Skip to content

Commit 8e5a58c

Browse files
sth-vclaude
andcommitted
perf: prune cells where Newton converges outside the cell range
When Newton converges to a point outside the current cell's parameter range, the nearest intersection is NOT in this cell — prune it instead of subdividing. This eliminates pointless subdivision near cutout boundaries where Newton always converges to the already-found boundary intersection. Reverted the pre-Newton dedup workaround and wider cutout margin — they're no longer needed. Example 4: 2.63s → 0.026s (100x speedup) All 7 examples under 0.3s. 65 tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4e332b6 commit 8e5a58c

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

mmcore/numeric/intersection/csx/_bez_csx4.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -572,13 +572,6 @@ def _phase2_isolated_search(
572572
t_mid = 0.5 * (t0 + t1)
573573
u_mid = 0.5 * (u0 + u1)
574574
v_mid = 0.5 * (v0 + v1)
575-
576-
# Skip Newton if the cell center is near a known intersection —
577-
# Newton would just reconverge to it, wasting iterations.
578-
pt_mid = eval_curve(C_orig, t_mid, rational=rational)
579-
if _is_duplicate(isolated, pt_mid, atol * 3):
580-
continue
581-
582575
t_sol, u_sol, v_sol, G, last_step = newton_csx(
583576
C_orig, S_orig, t_mid, u_mid, v_mid, rational=rational,
584577
)
@@ -608,6 +601,11 @@ def _phase2_isolated_search(
608601
# else: known intersection — cell is in its attraction basin
609602
continue
610603

604+
if converged:
605+
# Newton converged but OUTSIDE the cell range — the nearest
606+
# intersection is not in this cell. Prune.
607+
continue
608+
611609
if depth >= max_depth:
612610
continue
613611

@@ -748,7 +746,7 @@ def bez_csx(
748746
"t": float(t_bz), "u": float(u_bz), "v": float(v_bz),
749747
"point": pt_c,
750748
})
751-
t_exclude.append((t_bz - 3 * ptol_t, t_bz + 3 * ptol_t))
749+
t_exclude.append((t_bz - ptol_t, t_bz + ptol_t))
752750

753751
# Valley check for overlap
754752
if len(csx_boundary_zeros) >= 2:
@@ -765,7 +763,7 @@ def bez_csx(
765763
"u_range": (min(u_a, u_b), max(u_a, u_b)),
766764
"v_range": (min(v_a, v_b), max(v_a, v_b)),
767765
})
768-
t_exclude.append((t_lo_ovl - 3 * ptol_t, t_hi_ovl + 3 * ptol_t))
766+
t_exclude.append((t_lo_ovl - ptol_t, t_hi_ovl + ptol_t))
769767
# Remove isolated points inside the overlap
770768
isolated = [iso for iso in isolated
771769
if not (t_lo_ovl - atol <= iso["t"] <= t_hi_ovl + atol)]

0 commit comments

Comments
 (0)