Commit Graph
109 Commits
Author SHA1 Message Date
dotCooCoo eba2cf9de4 Merge #720 (fix/linesweeper-comparison-cache-unbounded) into integration/linesweeper 2026-11-09 14:08:12 -08:00
dotCooCoo 92f57d1479 Merge #719 (fix/linesweeper-near-parallel-leaf-count) into integration/linesweeper 2026-11-09 14:07:24 -08:00
dotCooCoo e2efaffeba Merge #718 (fix/linesweeper-eps-unvalidated) into integration/linesweeper 2026-11-09 14:05:26 -08:00
dotCooCoo 6c866041c2 Merge #717 (fix/linesweeper-huge-coord-wrong-output) into integration/linesweeper 2026-11-09 14:03:41 -08:00
dotCooCoo 331dcf7e04 Merge #695 (fix/linesweeper-next-touch-after-skip) into integration/linesweeper 2026-11-09 14:00:21 -08:00
dotCooCoo 1892b0f562 Merge #694 (fix/linesweeper-near-parallel-t-tolerance) into integration/linesweeper 2026-11-09 13:59:54 -08:00
dotCooCoo d78c5df2a2 Merge #693 (fix/linesweeper-contour-start-scan-west) into integration/linesweeper 2026-11-09 13:59:23 -08:00
dotCooCoo 0085e4538b Merge #692 (fix/linesweeper-add-bez-path-error-state) into integration/linesweeper 2026-11-09 13:58:48 -08:00
dotCooCoo 14cd3ca5af Merge #691 (fix/linesweeper-contours-recompute-positions) into integration/linesweeper 2026-11-09 13:58:23 -08:00
dotCooCoo f0293d6275 Merge #690 (fix/linesweeper-can-merge-cross-input) into integration/linesweeper 2026-11-09 13:57:20 -08:00
dotCooCoo b855610244 Merge #689 (fix/linesweeper-sweep-no-work-limit) into integration/linesweeper 2026-11-09 13:56:43 -08:00
dotCooCoo 4c771f038b Merge #688 (fix/linesweeper-huge-coord-stack-overflow) into integration/linesweeper 2026-11-09 13:54:48 -08:00
dotCooCoo 85a2ae63cd Merge #686 (fix/linesweeper-public-fn-preconditions) into integration/linesweeper 2026-11-09 13:54:09 -08:00
dotCooCoo cd75b69951 Merge #685 (fix/linesweeper-treevec-small-costs) into integration/linesweeper 2026-11-09 13:53:47 -08:00
dotCooCoo bf324b1946 Merge #684 (fix/linesweeper-is-disjoint-dbg) into integration/linesweeper 2026-11-09 13:53:21 -08:00
dotCooCoo 2018952858 Merge #679 (fix/linesweeper-scan-continue-before-break) into integration/linesweeper 2026-11-09 13:51:37 -08:00
dotCooCoo 52fe711c73 Merge #678 (fix/linesweeper-horizontals-per-x) into integration/linesweeper 2026-11-09 13:51:15 -08:00
dotCooCoo 39b029d968 Merge #675 (fix/linesweeper-coincident-touch-rescan) into integration/linesweeper 2026-11-09 13:50:25 -08:00
dotCooCoo 399cf69367 Merge #674 (fix/linesweeper-contour-tree-outer-parent) into integration/linesweeper 2026-11-09 13:50:03 -08:00
dotCooCoo d95d4dd11d Merge #673 (fix/linesweeper-merge-coincident-twins) into integration/linesweeper 2026-11-09 13:49:37 -08:00
dotCooCoo 623a585f26 Merge #672 (fix/linesweeper-closepath-first-panic) into integration/linesweeper 2026-11-09 13:49:08 -08:00
dotCooCoo b6c4282cb7 Merge #670 (fix/linesweeper-grouped-recursion-abort) into integration/linesweeper 2026-11-09 13:48:20 -08:00
dotCooCoo d5f5282202 Merge #669 (fix/linesweeper-huge-coord-clamp-panic) into integration/linesweeper 2026-11-09 13:47:53 -08:00
dotCooCoo 488b36d0bf Merge #668 (fix/linesweeper-entry-at-delayed-event-panic) into integration/linesweeper 2026-11-09 13:47:18 -08:00
dotCooCoo 51f14c4d23 Merge #667 (fix/linesweeper-contour-walk-spin) into integration/linesweeper 2026-11-09 13:46:52 -08:00
dotCooCoo 8a5c55246b Merge #666 (fix/linesweeper-sweep-same-y-cycle) into integration/linesweeper 2026-11-09 13:46:21 -08:00
dotCooCoo 7d81c44277 Merge #659 (fix/linesweeper-paperjs-fixtures) into integration/linesweeper 2026-11-09 13:45:44 -08:00
dotCooCoo ff2afe01d8 Merge #658 (fix/linesweeper-sweep-doc-crossing-t) into integration/linesweeper 2026-11-09 13:45:01 -08:00
dotCooCoo 89d6a1bfca Merge #657 (fix/linesweeper-paperjs-alpha) into integration/linesweeper 2026-11-09 13:44:41 -08:00
dotCooCoo df6b43e9b2 Merge #655 (fix/linesweeper-treevec-range-bounds) into integration/linesweeper 2026-11-09 13:44:19 -08:00
dotCooCoo 663684da23 Merge #654 (fix/linesweeper-cross-height-midpoint) into integration/linesweeper 2026-11-09 13:43:57 -08:00
dotCooCoo 666de547c4 Merge #650 (fix/linesweeper-curve-order-ish-span) into integration/linesweeper 2026-11-09 13:42:31 -08:00
dotCooCoo 1df8b229ef Merge #648 (fix/linesweeper-add-points-duplicate) into integration/linesweeper 2026-11-09 13:41:49 -08:00
dotCooCoo b83d51acd3 Merge #646 (fix/linesweeper-example-fill-rule) into integration/linesweeper 2026-11-09 13:40:40 -08:00
dotCooCoo 67f79dd30d Merge #642 (fix/linesweeper-unbuildable-targets) into integration/linesweeper 2026-11-09 13:39:13 -08:00
dotCooCoo 659f6413af Merge #638 (fix/linesweeper-line-recip-overflow) into integration/linesweeper 2026-11-09 13:37:15 -08:00
dotCooCoo 7fc724ced7 linesweeper: comparison caches keep one order per pair and drop ended pairs
ComparisonCache stored a CurveOrder for each direction of every compared
pair and kept every pair until the sweep ended. A sweep of a 2,001-point
star polygon held 4,001,998 cached orders (1,463 MiB).

The cache now stores one order per pair and flips it for a lookup in the
other direction. evict_ended drops the pairs in which a segment ends
above the current height, once the cache has doubled since its last
scan. Sweeper::advance calls it on both of its caches, and
compute_positions calls it as it takes each height from its queue.
2026-11-08 08:07:20 -08:00
dotCooCoo ed977f5bcc linesweeper: near-parallel cubics are ordered from their control points without recursing
intersect_cubics_rec split the shared y-range of two nearly parallel
cubics into a number of pieces that grows as about
(height / ish_tolerance)^(1/3), even when the curves stay more than
ish_tolerance apart. A 1e8-tall S-shaped cubic and a copy moved 1e-5
sideways took 16,384 recursion leaves.

order_from_control_points now bounds the gap between the two cut
pieces by their control point x gaps, widened by the largest control
point y gap times a bound on |dx/dy| from the control polygon. When
the range stays more than ish_tolerance on one side of zero, the
whole range gets Left or Right without recursing.
2026-11-08 08:00:13 -08:00
dotCooCoo a7b1dc28fb linesweeper: an eps that is not usable returns an error or is raised instead of overflowing the stack
binary_op_with_eps did not check eps. A NaN or negative eps returned a
wrong region without an error, -inf made the sweep hang, and an eps
below the float spacing of the coordinates (0, or 1e-10 with
coordinates near 1.5e8) recursed in intersect_cubics_rec until the
stack overflowed and the process aborted.

binary_op_with_eps now returns the new Error::InvalidEps for an eps that
is NaN, infinite, zero or negative. The Topology constructors and
Sweeper::new_with_correctness raise an eps that is NaN, not positive, or
below 64 * f64::EPSILON times the largest coordinate magnitude (and at
least 64 times the spacing of subnormal floats) to that value, the
scale binary_op uses.

intersect_cubics and intersect_cubics_with_precomputed_decomp raise a
positive ish_tolerance below 4 * f64::EPSILON times the two curves'
largest x coordinate magnitude (and at least four times the spacing of
subnormal floats) to that value, and a positive sure_tolerance below
half of it to half of it. Lines 1.0 apart at x = 1e15 or at y = 2e15,
and lines at x = 1e-310 and 2e-310, still compare as Left.

intersect_cubics_rec returns Ish for an interval whose midpoint rounds
to one of its ends instead of recursing on the same interval again. In
position.rs, approximate stops halving such an interval, so the loop in
compute_positions_correct always advances.

README.craft.md, SOURCE.json and NOTICE record the local patch.
2026-11-08 07:48:54 -08:00
dotCooCoo f7aa4e96f9 linesweeper: curves taller than 1e154 are ordered correctly
fit_quadratic multiplied two heights together. For a curve taller than
about 1.3e154 the product overflowed to infinity, inf * 0 gave a NaN
coefficient, and the quadratic sign checks read the NaN as a definite
order. binary_op then returned a wrong result without an error: the
union of a circle and a rectangle 1e155 across gave 4 contours instead
of 1. fit_quadratic now fits in the heights times a power of two that
brings the largest to between 2 and 4 when one is above 2^500, and
scales the coefficients back. QuadraticApprox::from_cubic multiplies by
the y^2 coefficient first when a product of two y coefficients is not
finite, so its error bounds keep the curve's extremes. The quadratic
sign checks report an unknown or close order for a quadratic with a NaN
or infinite coefficient.

intersect_lines compares x coordinates above 2^1019 at 1/16 scale and
works with half of each height for lines more than f64::MAX tall.
Segment::at_y and Segment::to_kurbo_cubic do the same on an axis where a
straight segment is more than f64::MAX long.
2026-11-08 07:20:33 -08:00
dotCooCoo 62f3c7b6cb linesweeper: next_touch_after finds the touch after one that contains y
CurveOrder::next_touch_after(y) skipped a touch when y was inside an
earlier touch followed by a Left interval. It called itself with the end
of the Left interval, which is where the next touch starts, so the
y < y0 test failed for that touch too and it returned None. For the
cubic (0,0) (-1.2,4/3) (1.6,8/3) (-1.6,4) and the vertical line x = 0
from y = 0 to 4, intersect_cubics(c0, c1, 1e-3, 0.02) gives Ish, Left,
Ish, Left, and next_touch_after(0.0) returned None instead of the touch
from y = 2.3454 to 2.5048. The sweep then queued no event for that touch.

next_touch_after now walks the order once in a loop and compares each
touch with the original y. A crossing found after a skipped touch is
still reported at the end of the Left interval, as before.
README.craft.md, SOURCE.json and NOTICE record the change as a local
patch.
2026-11-07 19:54:17 -08:00
dotCooCoo 3a5a3d465d linesweeper: tall near-parallel curves no longer split into millions of entries
solve_t_for_y asked polycool for t to within 1e-12. A t that is off by
1e-12 moves x by |dx/dt| * 1e-12, which grows with the coordinates while
the comparison tolerance does not: on a curve 1e9 tall x was off by up
to 166 times 64 * f64::EPSILON * 1e9. intersect_cubics cuts both curves
with y_subsegment, so near 3e7 the cut pieces moved by tens of
tolerances, the quadratic fits never got under the tolerance, and the
comparison recursed into y intervals shorter than the tolerance. Two
copies of one S-shaped curve 1.2 tolerances apart took 950,130 entries
and 9 s at 3e7 tall and ran for minutes at 1e8.

solve_t_for_y now passes an x_error of 0, so the root finder stops when
its step is zero or its bracket reaches adjacent floats. The new tests
solve_x_for_y_on_tall_curve and near_parallel_tall_curves fail without
the change.
2026-11-07 19:51:46 -08:00
dotCooCoo b7ba824ded linesweeper: contours follows each scan-west chain once instead of once per contour
Topology::contours_for_positions walked the scan-west chain of every new
contour until it found a boundary segment, calling inside twice per link,
and kept nothing between contours. With n bars of one set west of m
small squares of the other and the test "first set and not second", no
bar edge is on the boundary, so each square walked all 2n bar edges:
1,024,240,000 calls to inside for n = m = 16,000.

The boundary test now runs once per segment, and Topology::west_boundary
remembers the nearest boundary segment for every segment it passes, so
each link is followed once per call. The contours do not change.
README.craft.md, SOURCE.json and NOTICE record the change as a local
patch.
2026-11-07 18:51:32 -08:00
dotCooCoo 1886e30101 linesweeper: add_bez_path leaves the arena unchanged when a subpath is open
Segments::add_bez_path pushed every segment of a subpath before checking
that it was closed, and returned NonClosedPath without removing them.
For M0,0 L10,0 L5,10 Z M20,0 L30,5 L25,10 the arena kept five segments
with no entrances, the last linked to index 5 of a 5-segment arena, so
check_invariants panicked with an index out of bounds. Adding a closed
square afterwards linked the open piece into the square, and the sweep
visited only the square's 4 of 9 segments.

add_bez_path now truncates the arena back to its length before the call
when it returns the error. README.craft.md, SOURCE.json and NOTICE
record the local patch.
2026-11-07 18:44:53 -08:00
dotCooCoo 8f89ee88e0 linesweeper: merge output segments only within one input curve
Topology::can_merge accepted a merge at a simple point without checking
that the neighbor there is the adjacent piece of the same input segment.
After coincident segments are deleted, pieces of two different input
curves can meet at a simple point, and segs_to_path then rebuilt a
sub-curve of one curve from the other curve's parameters. Two arches
whose right legs agree to within about 1e-6 (area about 0.00096) gave a
contour of area 900 at eps 1e-6, and a path followed by its own reverse
panicked on the unwrap in segs_to_path.

can_merge now also requires the neighbor to be the input segment's
contour predecessor or successor, and segs_to_path starts at the first
segment when every segment looks mergeable.
2026-11-07 18:42:19 -08:00
dotCooCoo 4df639a818 linesweeper: contours builds paths only for boundary segments
Topology::contours called compute_positions, which with
Correctness::GoodEnough builds a BezPath for every output segment. The
contour walk only reads the paths of segments on the boundary of the
result, so on a union of many overlapping shapes almost all of that work
and memory went unused. The source carried a TODO for this.

With GoodEnough, contours now builds paths only for the non-deleted
segments whose two sides differ under `inside`. ReallyCorrect still
positions every segment, since its perturbations depend on neighbors. The
contours returned are unchanged.

The topology tests contour_positions_cover_only_boundary_segments and
contours_match_contours_from_all_positions check which segments get a
path and compare contours with contours built from every position for
four fill predicates.

README.craft.md, SOURCE.json and NOTICE record the change as a local
patch.
2026-11-07 18:41:53 -08:00
dotCooCoo db5a9291e4 linesweeper: sweeps can stop at a comparison limit instead of running for minutes
The sweep had no limit on its work. The union of 400 identical circles
made 1.36 billion segment comparisons in 19 sweep lines and took 66 to
83 s and 1.3 GB in a release build, with no way to stop it.

Sweeper counts its segment comparisons, and Sweeper::set_work_limit
stops it once it passes the limit, also between the events of one sweep
line. Topology::from_paths_with_work_limit returns the new
Error::WorkLimitExceeded. Topology::from_paths and the other
constructors set no limit.

prepress sweeps with a limit of 100 million comparisons and treats a
sweep past it as degenerate input, which the flattener rasterizes.
2026-11-07 18:32:43 -08:00
dotCooCoo 099bbef23a linesweeper: heights near f64::MAX no longer overflow the stack in solve_t_for_y
solve_t_for_y built the cubic's coefficients straight from the heights.
For a segment with heights above about f64::MAX / 3, `3.0 * p` overflowed
to infinity, and polycool's critical point search rescaled and retried
until the process aborted with a stack overflow. Topology::from_path
reached it on two overlapping rectangles near y = 1e308.

When a height or the target has a magnitude above f64::MAX / 32,
solve_t_for_y now divides every height by 32 before building the
coefficients. The division is exact and does not move the root.

README.craft.md, SOURCE.json and NOTICE record the local patch.
2026-11-07 17:53:09 -08:00
dotCooCoo 0cbf8f472c linesweeper: intersect_cubics no longer panics on reversed curves or bad tolerances
intersect_cubics panicked in clamp ("min > max") when either curve ran
from a larger y to a smaller one. It now compares such a curve as the
same curve with its control points reversed.

A negative or zero sure_tolerance, or a negative ish_tolerance, could
panic on an unwrap, overflow the stack on identical curves, or report
two parallel lines one unit apart as Right. With a sure_tolerance that
is not positive or is larger than ish_tolerance, or an ish_tolerance
that is not finite, the comparison now returns Ish over the common
range. Curves whose vertical ranges do not overlap give an empty order
instead of failing a debug assertion.

Topology::bounding_box returns Rect::ZERO when there are no segments,
as kurbo does for an empty path, instead of a rectangle from infinity
to negative infinity.

The docs of solve_t_for_y, y_subsegment and from_monotone_cubic state
their input rules and what happens outside them. README.craft.md,
SOURCE.json and NOTICE record the local patch.
2026-11-07 12:00:47 -08:00
dotCooCoo 000d50b4a3 linesweeper: tree iterators no longer allocate for trees of up to 8 levels
TreeVec's iter, iter_mut, range and range_mut kept the iterator's stack of
child iterators in a Vec, so each call on a tree with more than one level
allocated once. The sweep line calls range_mut on a TreeVec<_, 128> while
it holds more than 128 segments.

The stack is now a Stack that holds 8 levels in place and puts any deeper
level in a Vec. A TreeVec<_, 128> needs at least 2 * 64^9 elements to have
more than 8 levels. The iterators visit the same elements in the same
order. The treevec test iterators_on_short_and_tall_trees compares the
four iterators with a Vec on a tree of at most 8 levels and on one with
more.

README.craft.md, SOURCE.json and NOTICE record the change as a local patch.
2026-11-07 11:49:48 -08:00