diff --git a/vendor/linesweeper/README.craft.md b/vendor/linesweeper/README.craft.md index f5dd1029a1..317a7b2a7e 100644 --- a/vendor/linesweeper/README.craft.md +++ b/vendor/linesweeper/README.craft.md @@ -84,6 +84,9 @@ names, which is archived; its README says development moved off GitHub. `824b0791a750f7b27b8edcbb6c6244d0e629875e`. That commit is not in the GitHub repository the manifest names, which is archived; its README says development moved off GitHub. +`824b0791a750f7b27b8edcbb6c6244d0e629875e`. That commit is not in the GitHub repository the manifest +names, which is archived; its README says development moved off GitHub. + Every file here except this one, `SOURCE.json` and the files under Local changes is byte for byte the file in the `.crate` archive. `SOURCE.json` records the hash of the `.crate` download (`source_archive_sha256`) and, for every file kept, the hash in the package (`source_sha256`) and the @@ -189,6 +192,9 @@ and, for every file kept, the hash in the package (`source_sha256`) and the hash | `src/sweep/sweep_line.rs` | `Sweeper::handle_intersection` queues a delayed intersection only when its `y` is before the ends of both segments, as the intersection scans do. A delayed intersection at a segment's end used to panic in `CurveOrder::entry_at`. The `delayed_intersection_at_a_segment_end` test sweeps three wide, flat contours whose sweep delayed an intersection to a segment's end. | | `src/lib.rs`, `src/topology.rs` | `Topology::from_paths`, `from_paths_with_correctness`, `from_path` and `from_paths_binary` return `Error` instead of `NonClosedPath`, and return `Error::NaN`, `Error::Infinity` or the new `Error::TooLarge` when a path has a coordinate that is not finite or has a magnitude above `MAX_COORDINATE` (`f64::MAX / 16`). `binary_op` returns `Error::TooLarge` through `from_paths_binary`. Before, both panicked on a cubic with a coordinate above about `f64::MAX / 3`. A release build panicked in `f64::clamp` with "min > max, or either was NaN", and a debug build failed the `y.is_finite()` assertion in `Point::new`. The `coordinates_above_max_coordinate` test covers 6e307, 7e307 and 1.7e308. | | `src/topology.rs` | `Contours::grouped` walks each containment tree with an explicit stack instead of one recursive call per nesting level, and returns the contours in the same order. Before, contours nested about 10,000 deep overflowed a 1 MiB stack, which aborts the process. The `grouped_*` tests cover the order and a 30,000-deep nesting on a 256 KiB stack. | +| `AlmostHorizontalDecomposition::from_monotone_cubic` keeps each piece's handles on the right side of its end points instead of clamping them into the piece's y-range, so the pieces the sweep compares follow the input curve | `Craft patch (monotone handles)` | `src/curve/mod.rs` | `curve::test::decomposition_keeps_handles_outside_the_y_range` | + +Every change here updates this table and `SOURCE.json` in the same commit. `omitted_files` lists the 43 files of the package left out here, with their hashes: diff --git a/vendor/linesweeper/SOURCE.json b/vendor/linesweeper/SOURCE.json index a82cbac0ae..3c5297b6b2 100644 --- a/vendor/linesweeper/SOURCE.json +++ b/vendor/linesweeper/SOURCE.json @@ -40,6 +40,7 @@ "In `src/sweep/sweep_line.rs`, `Sweeper::handle_intersection` queues a delayed intersection only when its y is before the ends of both segments, so a delayed intersection at a segment's end no longer panics in `CurveOrder::entry_at`." "In `src/lib.rs` and `src/topology.rs`, the `Topology` constructors that take Bézier paths return `Error` instead of `NonClosedPath`, and return `Error::NaN`, `Error::Infinity` or the new `Error::TooLarge` for a coordinate that is not finite or has a magnitude above `MAX_COORDINATE` (`f64::MAX / 16`), so `Topology::from_path` and `binary_op` no longer panic on cubics with coordinates above about `f64::MAX / 3`." "In `src/topology.rs`, `Contours::grouped` walks each containment tree with an explicit stack instead of one recursive call per nesting level, so deeply nested contours no longer overflow the stack. The order of the returned contours is unchanged." + "In `src/curve/mod.rs`, `AlmostHorizontalDecomposition::from_monotone_cubic` keeps `p1.y` at least `p0.y` and `p2.y` at most `p3.y` for each piece, instead of clamping both into the piece's y-range. A y-monotone cubic can have handles outside that range, and the clamp moved the curve the sweep compares: for `M0,5 C5,0 2,0 1,1 C0,2 4,0 5,5 Z` at eps 1e-6, `Topology::from_path(..).contours(|w| *w != 0)` gave an outline of area 11.0108 instead of 10.9122, with a horizontal cut at y = 1.97218 that lies 0.2588 from the input. `curve::test::decomposition_keeps_handles_outside_the_y_range` covers the shape and its mirror image in y." ], "files": [ { "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" }, @@ -79,6 +80,7 @@ { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "0b1be70901b2bbf0244fccb0a599f0e9615eb30c21758a4d0efda97254bfb059" }, { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "00ac2cab19a570aefdd2121d621742f113842b9566e7b7718923b337d9c79005" }, { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "facf21dbb3a2bb8c2b4f33554f61571482de7f9c4653b6858f21392fcd789b38" }, + { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "4aa43bcd77267dcd1ba77fa898d5e096b9d47b8ab9eb7bd25ace5a73adbb97ab" }, { "path": "src/curve/split_quad.rs", "source_sha256": "b8aae4ce7c16fa623724f667e1058130a9c7eed693b5b01e8b9e16632b8ec45f", "source_git_blob": null, "sha256": "b8aae4ce7c16fa623724f667e1058130a9c7eed693b5b01e8b9e16632b8ec45f" }, { "path": "src/curve/transverse.rs", "source_sha256": "be9c695531f4cb0fe73af13e78040b51b9476c193d84562e701aadd07b3fd06e", "source_git_blob": null, "sha256": "be9c695531f4cb0fe73af13e78040b51b9476c193d84562e701aadd07b3fd06e" }, { "path": "src/generators.rs", "source_sha256": "cc9f2441546db9204219294c354449809dda77dffad06fec8a30f45df01e6fef", "source_git_blob": null, "sha256": "cc9f2441546db9204219294c354449809dda77dffad06fec8a30f45df01e6fef" }, diff --git a/vendor/linesweeper/src/curve/mod.rs b/vendor/linesweeper/src/curve/mod.rs index 29e0d14d8c..2c6c72c8fd 100644 --- a/vendor/linesweeper/src/curve/mod.rs +++ b/vendor/linesweeper/src/curve/mod.rs @@ -1497,10 +1497,15 @@ impl AlmostHorizontalDecomposition { // Enforce y-monotonicity, from the previous curve to this one, and // also for the initial and final tangents of this subsegment. + // + // Craft patch (monotone handles): the tangents only need to point + // the right way, so p1.y is kept at least p0.y and p2.y at most + // p3.y. A monotone cubic can have handles outside its own y-range, + // and clamping them into that range moves the curve. c.p0.y = c.p0.y.clamp(last_y, orig_c.p3.y); - c.p1.y = c.p1.y.clamp(c.p0.y, orig_c.p3.y); + c.p1.y = c.p1.y.max(c.p0.y); c.p3.y = c.p3.y.clamp(last_y, orig_c.p3.y); - c.p2.y = c.p2.y.clamp(last_y, c.p3.y); + c.p2.y = c.p2.y.min(c.p3.y); last_y = c.p3.y; let approx_horiz = match order { Right => { @@ -2022,6 +2027,44 @@ mod test { dbg!(intersect_cubics(c0, c1, sure_tol, ish_tol)); } + // Craft patch (monotone handles) test: after the shape is split into + // y-monotone pieces, some pieces have a handle outside their own y-range. + // The outline must still follow the input curves, for the shape and for + // its mirror image in y. + #[test] + fn decomposition_keeps_handles_outside_the_y_range() { + use kurbo::{BezPath, ParamCurve as _, ParamCurveNearest as _, Shape as _}; + + for svg in [ + "M0,5 C5,0 2,0 1,1 C0,2 4,0 5,5 Z", + "M0,0 C5,5 2,5 1,4 C0,3 4,5 5,0 Z", + ] { + let input = BezPath::from_svg(svg).unwrap(); + let topology = crate::topology::Topology::::from_path(&input, 1e-6).unwrap(); + let contours = topology.contours(|w| *w != 0); + let mut output = BezPath::new(); + for contour in contours.contours() { + output.extend(contour.path.iter()); + } + + let area = output.area().abs(); + assert!((area - 10.9122).abs() < 1e-3, "{svg}: area {area}"); + + let input_segs: Vec<_> = input.segments().collect(); + for seg in output.segments() { + for i in 0..=16 { + let p = seg.eval(i as f64 / 16.0); + let dist = input_segs + .iter() + .map(|s| s.nearest(p, 1e-9).distance_sq) + .fold(f64::INFINITY, f64::min) + .sqrt(); + assert!(dist < 1e-6, "{svg}: {p:?} is {dist} from the input"); + } + } + } + } + #[test] fn quadratic_comparison() { let c0 = CubicBez::new((0.0, 0.0), (10.0, 10.0), (20.0, 20.0), (30.0, 30.0));