From 0cbf8f472c2e5fc8d013380e950d139eb65dc230 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 7 Nov 2026 11:55:31 -0800 Subject: [PATCH 1/4] 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. --- NOTICE | 6 +- vendor/linesweeper/README.craft.md | 21 +++-- vendor/linesweeper/SOURCE.json | 8 +- vendor/linesweeper/src/curve/mod.rs | 115 +++++++++++++++++++++++++++- vendor/linesweeper/src/topology.rs | 13 ++++ 5 files changed, 148 insertions(+), 15 deletions(-) diff --git a/NOTICE b/NOTICE index bd88d43e7a..70c163182c 100644 --- a/NOTICE +++ b/NOTICE @@ -218,10 +218,10 @@ applications retain their own document-font selection and licensing policy. linesweeper linesweeper 0.5.0 (https://crates.io/crates/linesweeper/0.5.0), MIT OR Apache-2.0, is stored in -vendor/linesweeper with its upstream license files and no file changed. Its manifest names Joe Neeman +vendor/linesweeper with its upstream license files and one local patch. Its manifest names Joe Neeman as author, and its LICENSE-MIT reads "Copyright (c) 2018 Raph Levien". See -vendor/linesweeper/README.craft.md and vendor/linesweeper/SOURCE.json for provenance and the files -left out. +vendor/linesweeper/README.craft.md and vendor/linesweeper/SOURCE.json for provenance, the local +change and the files left out. Platform lifecycle source provenance diff --git a/vendor/linesweeper/README.craft.md b/vendor/linesweeper/README.craft.md index f683ca53de..d458a77b77 100644 --- a/vendor/linesweeper/README.craft.md +++ b/vendor/linesweeper/README.craft.md @@ -1,15 +1,22 @@ # Local linesweeper 0.5.0 copy -This is the crates.io linesweeper 0.5.0 package (MIT OR Apache-2.0) with some files left out and no -file changed. `.cargo_vcs_info.json` names the commit it was packaged from, +This is the crates.io linesweeper 0.5.0 package (MIT OR Apache-2.0) with some files left out and the +local patches listed below. `.cargo_vcs_info.json` names the commit it was packaged from, `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 and `SOURCE.json` 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 hash here (`sha256`). `upstream_repository` is -null because no public repository this copy can name holds `upstream_revision`. `local_patches` is -empty. +Every file here except this one, `SOURCE.json` and the patched files below 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 +hash here (`sha256`). `upstream_repository` is null because no public repository this copy can name +holds `upstream_revision`. `local_patches` describes each local patch. + +## Local patches + +| File | Change | +|---|---| +| `src/curve/mod.rs` | `intersect_cubics` compares a curve whose `p3.y` is below its `p0.y` as the same curve reversed, instead of panicking in `clamp`. `intersect_cubics_with_precomputed_decomp` returns close (`Ish`) over the common range when `sure_tolerance` is not positive, is larger than `ish_tolerance`, or `ish_tolerance` is not finite, instead of panicking, overflowing the stack or returning a wrong order; when the curves' vertical ranges do not overlap, it returns an empty order without a debug assertion failure. The docs of these functions, `from_monotone_cubic`, `solve_t_for_y` and `y_subsegment` state their input rules. The `curves_decreasing_in_y`, `invalid_tolerances` and `disjoint_vertical_ranges` tests cover the changes. | +| `src/topology.rs` | `Topology::bounding_box` returns `Rect::ZERO` for a topology with no segments, as kurbo does for an empty path, instead of a rectangle from infinity to negative infinity. The `empty_bounding_box` test covers it. | `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 9c71e51add..b9b5a1f04c 100644 --- a/vendor/linesweeper/SOURCE.json +++ b/vendor/linesweeper/SOURCE.json @@ -7,7 +7,9 @@ "upstream_repository": null, "upstream_revision": "824b0791a750f7b27b8edcbb6c6244d0e629875e", "upstream_directory": "", - "local_patches": [], + "local_patches": [ + "In `src/curve/mod.rs`, `intersect_cubics` reverses a curve whose `p3.y` is below its `p0.y` before comparing it, and `intersect_cubics_with_precomputed_decomp` returns `Ish` over the common range when `sure_tolerance` is not positive or is larger than `ish_tolerance`, or `ish_tolerance` is not finite, and an empty order for curves whose vertical ranges do not overlap; the docs of these functions, `from_monotone_cubic`, `solve_t_for_y` and `y_subsegment` state their input rules. In `src/topology.rs`, `Topology::bounding_box` returns `Rect::ZERO` when there are no segments." + ], "files": [ { "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" }, { "path": ".gitignore", "source_sha256": "88b59092499ae05234330eb7d0b01e953e969caf05261530e3765eef02536cf0", "source_git_blob": null, "sha256": "88b59092499ae05234330eb7d0b01e953e969caf05261530e3765eef02536cf0" }, @@ -32,7 +34,7 @@ { "path": "proptest-regressions/topology.txt", "source_sha256": "49ff0b5b370f082984276d5312f03b1fc96ef0dd218f9efd7b084b11abbb9d19", "source_git_blob": null, "sha256": "49ff0b5b370f082984276d5312f03b1fc96ef0dd218f9efd7b084b11abbb9d19" }, { "path": "src/arbitrary.rs", "source_sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750", "source_git_blob": null, "sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750" }, { "path": "src/curve/line.rs", "source_sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e", "source_git_blob": null, "sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e" }, - { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2" }, + { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "52cb0916966f786b2ea3c33d5d60981930014a18c202577cce8b8cebeb634afe" }, { "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" }, @@ -63,7 +65,7 @@ { "path": "src/sweep/snapshots/linesweeper__sweep__sweep_line__tests__square_and_diamond.snap", "source_sha256": "3f01a76fb7ff4aef0fd55fd869602d4a2b69fff1bd65632f406b275b5d6af600", "source_git_blob": null, "sha256": "3f01a76fb7ff4aef0fd55fd869602d4a2b69fff1bd65632f406b275b5d6af600" }, { "path": "src/sweep/snapshots/linesweeper__sweep__sweep_line__tests__two_squares.snap", "source_sha256": "79e3c95e563a66c0ce244125470a106a18dfe29f276b732defd305406c873c7e", "source_git_blob": null, "sha256": "79e3c95e563a66c0ce244125470a106a18dfe29f276b732defd305406c873c7e" }, { "path": "src/sweep/sweep_line.rs", "source_sha256": "822b261f682911ea0c0370eaf17d9201a1e639b315359dcb6a3b877a229816e3", "source_git_blob": null, "sha256": "822b261f682911ea0c0370eaf17d9201a1e639b315359dcb6a3b877a229816e3" }, - { "path": "src/topology.rs", "source_sha256": "9c9b48bc3853884425127e2d64e8ed957ba0d27e1696e2c457e95282e52d6a5b", "source_git_blob": null, "sha256": "9c9b48bc3853884425127e2d64e8ed957ba0d27e1696e2c457e95282e52d6a5b" }, + { "path": "src/topology.rs", "source_sha256": "9c9b48bc3853884425127e2d64e8ed957ba0d27e1696e2c457e95282e52d6a5b", "source_git_blob": null, "sha256": "d74f3ab448fba643daaac39c43a05c0578518053f68c74b218b1ba3ced7012e5" }, { "path": "src/treevec.rs", "source_sha256": "d88b9fbf02fa9f318560e1d483d465555f2b696ae12c00f8e4f5b71ea6779445", "source_git_blob": null, "sha256": "d88b9fbf02fa9f318560e1d483d465555f2b696ae12c00f8e4f5b71ea6779445" }, { "path": "src/typed_vec.rs", "source_sha256": "3e9a2675b8a40d8fc4df0575bd9d0d16b5604d18e9b78638dd5a612b28fc4c30", "source_git_blob": null, "sha256": "3e9a2675b8a40d8fc4df0575bd9d0d16b5604d18e9b78638dd5a612b28fc4c30" }, { "path": "tests/fonts.rs", "source_sha256": "081604ebf560a19ff0427efd9a17eaaa0a3b46ad0bf58323fd6e21b6c0764400", "source_git_blob": null, "sha256": "081604ebf560a19ff0427efd9a17eaaa0a3b46ad0bf58323fd6e21b6c0764400" }, diff --git a/vendor/linesweeper/src/curve/mod.rs b/vendor/linesweeper/src/curve/mod.rs index f602308573..d13c9dfb53 100644 --- a/vendor/linesweeper/src/curve/mod.rs +++ b/vendor/linesweeper/src/curve/mod.rs @@ -377,6 +377,14 @@ impl CurveOrder { } /// Find the parameter `t` at which `c` crosses height `y`. +/// +/// `c` must be y-monotone with `c.p0.y < c.p3.y`, and `y` must be in +/// `c.p0.y..=c.p3.y`. For other inputs, release builds return a parameter in +/// `0.0..=1.0` that need not be a crossing. +/// +/// # Panics +/// +/// Debug builds panic when `c` or `y` is outside these bounds. pub fn solve_t_for_y(c: CubicBez, y: f64) -> f64 { debug_assert!( c.p0.y <= y && y <= c.p3.y && c.p0.y < c.p3.y, @@ -426,6 +434,15 @@ pub fn solve_x_for_y(c: CubicBez, y: f64) -> f64 { /// /// The input curve should be monotonic in `y`, and its range should include /// `y0` and `y1` (which should be ordered). +/// +/// For other inputs, release builds return a curve that starts at height `y0` +/// and ends at height `y1`, but whose ends need not lie on `c`. With `y0 > y1` +/// it runs from `y0` down to `y1`. +/// +/// # Panics +/// +/// Debug builds panic when `y0` is not less than `y1` or when `c` does not +/// cover `y0..=y1`. pub fn y_subsegment(c: CubicBez, y0: f64, y1: f64) -> CubicBez { debug_assert!(y0 < y1); debug_assert!(c.p0.y <= y0 && y1 <= c.p3.y); @@ -1397,6 +1414,10 @@ impl AlmostHorizontalDecomposition { /// Decompose a cubic into almost-horizontal and not-almost-horizontal pieces. /// /// The cubic `c` must be (approximately) y-monotone and must not be completely horizontal. + /// + /// # Panics + /// + /// Panics if `c` is completely horizontal or if `c.p3.y` is smaller than `c.p0.y`. pub fn from_monotone_cubic(c: CubicBez) -> Self { const THRESHOLD: f64 = 16.0; let dx = cubic_from_bez_x(c).deriv(); @@ -1538,12 +1559,27 @@ impl AlmostHorizontalDecomposition { /// The `ish_tolerance` parameter tells us when we're allowed to say that /// the two curves are close: if they're definitely within `ish_tolerance` /// of one another, we can say that they're close. +/// +/// `sure_tolerance` must be positive and no larger than `ish_tolerance`, and +/// `ish_tolerance` must be finite. Otherwise the returned order says that the +/// curves are close over their whole common range. +/// +/// Each curve must be y-monotone. A curve whose `p3.y` is smaller than its +/// `p0.y` is compared as the same curve with its control points reversed. +/// When the vertical ranges of the curves do not overlap, the returned order +/// has no entries. +/// +/// # Panics +/// +/// Panics if either curve is completely horizontal. pub fn intersect_cubics( c0: CubicBez, c1: CubicBez, sure_tolerance: f64, ish_tolerance: f64, ) -> CurveOrder { + let c0 = increasing_in_y(c0); + let c1 = increasing_in_y(c1); intersect_cubics_with_precomputed_decomp( c0, &AlmostHorizontalDecomposition::from_monotone_cubic(c0), @@ -1554,11 +1590,26 @@ pub fn intersect_cubics( ) } +// Craft patch (input rules): `intersect_cubics` compares a curve that runs +// down in y as the same curve reversed. +/// Returns `c`, or `c` with its control points reversed if it decreases in y. +fn increasing_in_y(c: CubicBez) -> CubicBez { + if c.p3.y < c.p0.y { + CubicBez::new(c.p3, c.p2, c.p1, c.p0) + } else { + c + } +} + /// A version of [intersect_cubics] that uses a precomputed almost-horizontal /// decomposition. /// /// Pre-computing the almost-horizontal decomposition can be much faster, because /// then you can do it per-curve instead of per-comparison. +/// +/// `c0_div` and `c1_div` must be the decompositions of `c0` and `c1`, so each +/// curve must have `p0.y < p3.y`. The tolerances follow the same rule as in +/// [intersect_cubics]. pub fn intersect_cubics_with_precomputed_decomp( c0: CubicBez, c0_div: &AlmostHorizontalDecomposition, @@ -1571,7 +1622,15 @@ pub fn intersect_cubics_with_precomputed_decomp( let y1 = c0.p3.y.min(c1.p3.y); let mut ret = CurveOrder::new(y0); - if y0 < y1 { + let valid_tolerances = + sure_tolerance > 0.0 && sure_tolerance <= ish_tolerance && ish_tolerance.is_finite(); + if !valid_tolerances { + // Craft patch (input rules): with a negative `ish_tolerance`, + // `intersect_cubics_rec` can recurse without end. + if y0 <= y1 { + ret.push(y1, Order::Ish, MetricsStatus::default()); + } + } else if y0 < y1 { let c0_div = c0_div .pieces .iter() @@ -1620,7 +1679,7 @@ pub fn intersect_cubics_with_precomputed_decomp( ret.push(y1, order, MetricsStatus::default()); } //fix_up_endpoints(&mut ret, c0, c1, eps); - debug_assert_eq!(ret.cmps.last().unwrap().end, y1); + debug_assert!(y0 > y1 || ret.cmps.last().map(|e| e.end) == Some(y1)); ret } @@ -1790,6 +1849,58 @@ mod test { dbg!(intersect_cubics(c0, c1, 0.5e-6, 1.5e-6)); } + // Craft patch (input rules) tests: curves that run down in y, tolerances + // outside the documented rule, and curves with no common y-range. + fn vertical(x: f64, y0: f64, y1: f64) -> CubicBez { + PathSeg::Line(Line::new((x, y0), (x, y1))).to_cubic() + } + + #[test] + fn curves_decreasing_in_y() { + let up0 = vertical(0.0, 0.0, 1.0); + let up1 = vertical(1.0, 0.0, 1.0); + let down0 = vertical(0.0, 1.0, 0.0); + let down1 = vertical(1.0, 1.0, 0.0); + for (c0, c1) in [(down0, down1), (down0, up1), (up0, down1)] { + let cmp = intersect_cubics(c0, c1, 1e-6, 2e-6); + assert_eq!(cmp.iter().collect::>(), [(0.0, 1.0, Order::Left)]); + } + } + + #[test] + fn invalid_tolerances() { + let c0 = vertical(0.0, 0.0, 1.0); + let parallel = vertical(1.0, 0.0, 1.0); + let crossing = CubicBez::new( + (1.0, 0.0), + (2.0 / 3.0, 1.0 / 3.0), + (1.0 / 3.0, 2.0 / 3.0), + (0.0, 1.0), + ); + let tolerances = [ + (-1.0, -1.0), + (-1.0, 1e-6), + (1e-6, -1.0), + (-1e-9, -1e-9), + (0.0, 0.0), + (2e-6, 1e-6), + (1e-6, f64::INFINITY), + (f64::NAN, 1e-6), + ]; + for (sure, ish) in tolerances { + for c1 in [c0, parallel, crossing] { + let cmp = intersect_cubics(c0, c1, sure, ish); + assert_eq!(cmp.iter().collect::>(), [(0.0, 1.0, Order::Ish)]); + } + } + } + + #[test] + fn disjoint_vertical_ranges() { + let cmp = intersect_cubics(vertical(0.0, 0.0, 1.0), vertical(1.0, 2.0, 3.0), 1e-6, 2e-6); + assert_eq!(cmp.iter().count(), 0); + } + #[test] fn y_slop_single_seg() { let order = CurveOrder { diff --git a/vendor/linesweeper/src/topology.rs b/vendor/linesweeper/src/topology.rs index 8420d015a5..ca518a26a5 100644 --- a/vendor/linesweeper/src/topology.rs +++ b/vendor/linesweeper/src/topology.rs @@ -1453,7 +1453,13 @@ impl Topology { } /// Returns a rectangle bounding all of our segments. + /// + /// With no segments, it returns `Rect::ZERO`, as kurbo does for an empty path. pub fn bounding_box(&self) -> kurbo::Rect { + // Craft patch (input rules): an empty topology has a zero rectangle. + if self.segments.segments().next().is_none() { + return Rect::ZERO; + } let mut rect = Rect::new( f64::INFINITY, f64::INFINITY, @@ -2288,6 +2294,13 @@ mod tests { insta::assert_ron_snapshot!(top); } + // Craft patch (input rules) test. + #[test] + fn empty_bounding_box() { + let top = Topology::from_polylines_binary(EMPTY, EMPTY, 0.01); + assert_eq!(top.bounding_box(), kurbo::Rect::ZERO); + } + #[test] fn diamond() { let segs = [[p(0.0, 0.0), p(1.0, 1.0), p(0.0, 2.0), p(-1.0, 1.0)]]; From d637028aa767ecf2dae0de78ee0395ab514d7241 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 7 Nov 2026 12:28:31 -0800 Subject: [PATCH 2/4] linesweeper: record the committed bytes' digests for curve/mod.rs and topology.rs --- vendor/linesweeper/SOURCE.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/linesweeper/SOURCE.json b/vendor/linesweeper/SOURCE.json index b9b5a1f04c..d3c5b66492 100644 --- a/vendor/linesweeper/SOURCE.json +++ b/vendor/linesweeper/SOURCE.json @@ -34,7 +34,7 @@ { "path": "proptest-regressions/topology.txt", "source_sha256": "49ff0b5b370f082984276d5312f03b1fc96ef0dd218f9efd7b084b11abbb9d19", "source_git_blob": null, "sha256": "49ff0b5b370f082984276d5312f03b1fc96ef0dd218f9efd7b084b11abbb9d19" }, { "path": "src/arbitrary.rs", "source_sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750", "source_git_blob": null, "sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750" }, { "path": "src/curve/line.rs", "source_sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e", "source_git_blob": null, "sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e" }, - { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "52cb0916966f786b2ea3c33d5d60981930014a18c202577cce8b8cebeb634afe" }, + { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "2a23de09ddc09486f1f382c36f9e0f23d699f94779f1ba32194392948a608535" }, { "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" }, @@ -65,7 +65,7 @@ { "path": "src/sweep/snapshots/linesweeper__sweep__sweep_line__tests__square_and_diamond.snap", "source_sha256": "3f01a76fb7ff4aef0fd55fd869602d4a2b69fff1bd65632f406b275b5d6af600", "source_git_blob": null, "sha256": "3f01a76fb7ff4aef0fd55fd869602d4a2b69fff1bd65632f406b275b5d6af600" }, { "path": "src/sweep/snapshots/linesweeper__sweep__sweep_line__tests__two_squares.snap", "source_sha256": "79e3c95e563a66c0ce244125470a106a18dfe29f276b732defd305406c873c7e", "source_git_blob": null, "sha256": "79e3c95e563a66c0ce244125470a106a18dfe29f276b732defd305406c873c7e" }, { "path": "src/sweep/sweep_line.rs", "source_sha256": "822b261f682911ea0c0370eaf17d9201a1e639b315359dcb6a3b877a229816e3", "source_git_blob": null, "sha256": "822b261f682911ea0c0370eaf17d9201a1e639b315359dcb6a3b877a229816e3" }, - { "path": "src/topology.rs", "source_sha256": "9c9b48bc3853884425127e2d64e8ed957ba0d27e1696e2c457e95282e52d6a5b", "source_git_blob": null, "sha256": "d74f3ab448fba643daaac39c43a05c0578518053f68c74b218b1ba3ced7012e5" }, + { "path": "src/topology.rs", "source_sha256": "9c9b48bc3853884425127e2d64e8ed957ba0d27e1696e2c457e95282e52d6a5b", "source_git_blob": null, "sha256": "9ce5c474a4fa9a30fcffe21f0fa4878ee39d3149dfe48b57f7000e396844187e" }, { "path": "src/treevec.rs", "source_sha256": "d88b9fbf02fa9f318560e1d483d465555f2b696ae12c00f8e4f5b71ea6779445", "source_git_blob": null, "sha256": "d88b9fbf02fa9f318560e1d483d465555f2b696ae12c00f8e4f5b71ea6779445" }, { "path": "src/typed_vec.rs", "source_sha256": "3e9a2675b8a40d8fc4df0575bd9d0d16b5604d18e9b78638dd5a612b28fc4c30", "source_git_blob": null, "sha256": "3e9a2675b8a40d8fc4df0575bd9d0d16b5604d18e9b78638dd5a612b28fc4c30" }, { "path": "tests/fonts.rs", "source_sha256": "081604ebf560a19ff0427efd9a17eaaa0a3b46ad0bf58323fd6e21b6c0764400", "source_git_blob": null, "sha256": "081604ebf560a19ff0427efd9a17eaaa0a3b46ad0bf58323fd6e21b6c0764400" }, From 4ee9cd266d50883a79fba4fd3032750d085d28f8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 7 Nov 2026 13:02:47 -0800 Subject: [PATCH 3/4] linesweeper: with_y_slop and order_after accept an empty order intersect_cubics returns an empty order for curves whose vertical ranges do not overlap. CurveOrder::with_y_slop with a nonzero slop and CurveOrder::order_after panicked on an unwrap of that order's last entry. with_y_slop now returns the empty order unchanged, and order_after returns Ish. The docs of solve_t_for_y and y_subsegment state that debug builds do not check whether the curve is y-monotone. --- vendor/linesweeper/README.craft.md | 2 +- vendor/linesweeper/SOURCE.json | 4 ++-- vendor/linesweeper/src/curve/mod.rs | 25 +++++++++++++++++++------ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/vendor/linesweeper/README.craft.md b/vendor/linesweeper/README.craft.md index d458a77b77..82846eaaab 100644 --- a/vendor/linesweeper/README.craft.md +++ b/vendor/linesweeper/README.craft.md @@ -15,7 +15,7 @@ holds `upstream_revision`. `local_patches` describes each local patch. | File | Change | |---|---| -| `src/curve/mod.rs` | `intersect_cubics` compares a curve whose `p3.y` is below its `p0.y` as the same curve reversed, instead of panicking in `clamp`. `intersect_cubics_with_precomputed_decomp` returns close (`Ish`) over the common range when `sure_tolerance` is not positive, is larger than `ish_tolerance`, or `ish_tolerance` is not finite, instead of panicking, overflowing the stack or returning a wrong order; when the curves' vertical ranges do not overlap, it returns an empty order without a debug assertion failure. The docs of these functions, `from_monotone_cubic`, `solve_t_for_y` and `y_subsegment` state their input rules. The `curves_decreasing_in_y`, `invalid_tolerances` and `disjoint_vertical_ranges` tests cover the changes. | +| `src/curve/mod.rs` | `intersect_cubics` compares a curve whose `p3.y` is below its `p0.y` as the same curve reversed, instead of panicking in `clamp`. `intersect_cubics_with_precomputed_decomp` returns close (`Ish`) over the common range when `sure_tolerance` is not positive, is larger than `ish_tolerance`, or `ish_tolerance` is not finite, instead of panicking, overflowing the stack or returning a wrong order; when the curves' vertical ranges do not overlap, it returns an empty order without a debug assertion failure, and `CurveOrder::with_y_slop` and `CurveOrder::order_after` accept that empty order instead of panicking on an `unwrap`. The docs of these functions, `from_monotone_cubic`, `solve_t_for_y` and `y_subsegment` state their input rules. The `curves_decreasing_in_y`, `invalid_tolerances` and `disjoint_vertical_ranges` tests cover the changes. | | `src/topology.rs` | `Topology::bounding_box` returns `Rect::ZERO` for a topology with no segments, as kurbo does for an empty path, instead of a rectangle from infinity to negative infinity. The `empty_bounding_box` test covers it. | `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 d3c5b66492..85051831d3 100644 --- a/vendor/linesweeper/SOURCE.json +++ b/vendor/linesweeper/SOURCE.json @@ -8,7 +8,7 @@ "upstream_revision": "824b0791a750f7b27b8edcbb6c6244d0e629875e", "upstream_directory": "", "local_patches": [ - "In `src/curve/mod.rs`, `intersect_cubics` reverses a curve whose `p3.y` is below its `p0.y` before comparing it, and `intersect_cubics_with_precomputed_decomp` returns `Ish` over the common range when `sure_tolerance` is not positive or is larger than `ish_tolerance`, or `ish_tolerance` is not finite, and an empty order for curves whose vertical ranges do not overlap; the docs of these functions, `from_monotone_cubic`, `solve_t_for_y` and `y_subsegment` state their input rules. In `src/topology.rs`, `Topology::bounding_box` returns `Rect::ZERO` when there are no segments." + "In `src/curve/mod.rs`, `intersect_cubics` reverses a curve whose `p3.y` is below its `p0.y` before comparing it, and `intersect_cubics_with_precomputed_decomp` returns `Ish` over the common range when `sure_tolerance` is not positive or is larger than `ish_tolerance`, or `ish_tolerance` is not finite, and an empty order for curves whose vertical ranges do not overlap, which `CurveOrder::with_y_slop` and `CurveOrder::order_after` accept; the docs of these functions, `from_monotone_cubic`, `solve_t_for_y` and `y_subsegment` state their input rules. In `src/topology.rs`, `Topology::bounding_box` returns `Rect::ZERO` when there are no segments." ], "files": [ { "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" }, @@ -34,7 +34,7 @@ { "path": "proptest-regressions/topology.txt", "source_sha256": "49ff0b5b370f082984276d5312f03b1fc96ef0dd218f9efd7b084b11abbb9d19", "source_git_blob": null, "sha256": "49ff0b5b370f082984276d5312f03b1fc96ef0dd218f9efd7b084b11abbb9d19" }, { "path": "src/arbitrary.rs", "source_sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750", "source_git_blob": null, "sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750" }, { "path": "src/curve/line.rs", "source_sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e", "source_git_blob": null, "sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e" }, - { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "2a23de09ddc09486f1f382c36f9e0f23d699f94779f1ba32194392948a608535" }, + { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "ef0b50d4a922adf7c8b74cddb745986f14427d3a1dae28c544f174addd28bb28" }, { "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 d13c9dfb53..6a81d55159 100644 --- a/vendor/linesweeper/src/curve/mod.rs +++ b/vendor/linesweeper/src/curve/mod.rs @@ -263,8 +263,11 @@ impl CurveOrder { let mut ret = SmallVec::<[CurveOrderEntry; 3]>::new(); - // unwrap: cmps is always non-empty - let last_end = self.cmps.last().unwrap().end; + // Craft patch (input rules): curves with disjoint vertical ranges have + // an empty order. + let Some(last_end) = self.cmps.last().map(|e| e.end) else { + return self; + }; if self.start == last_end || self.cmps.len() <= 1 { return self; @@ -365,8 +368,13 @@ impl CurveOrder { /// As a corner case, if this comparison ends exactly at `y` then we return /// the ordering exactly at `y`. pub fn order_after(&self, y: f64) -> Order { - if y == self.cmps.last().unwrap().end { - self.cmps.last().unwrap().order + // Craft patch (input rules): curves with disjoint vertical ranges have + // an empty order. + let Some(last) = self.cmps.last() else { + return Order::Ish; + }; + if y == last.end { + last.order } else { self.iter() .skip_while(|(_start, end, _order)| end <= &y) @@ -384,7 +392,10 @@ impl CurveOrder { /// /// # Panics /// -/// Debug builds panic when `c` or `y` is outside these bounds. +/// Debug builds panic unless `c.p0.y <= y && y <= c.p3.y && c.p0.y < c.p3.y`. +/// They do not check whether `c` is y-monotone. For a curve that is not, they +/// return one of its crossings, or a parameter that is not a crossing, without +/// a panic. pub fn solve_t_for_y(c: CubicBez, y: f64) -> f64 { debug_assert!( c.p0.y <= y && y <= c.p3.y && c.p0.y < c.p3.y, @@ -442,7 +453,7 @@ pub fn solve_x_for_y(c: CubicBez, y: f64) -> f64 { /// # Panics /// /// Debug builds panic when `y0` is not less than `y1` or when `c` does not -/// cover `y0..=y1`. +/// cover `y0..=y1`. They do not check whether `c` is y-monotone. pub fn y_subsegment(c: CubicBez, y0: f64, y1: f64) -> CubicBez { debug_assert!(y0 < y1); debug_assert!(c.p0.y <= y0 && y1 <= c.p3.y); @@ -1899,6 +1910,8 @@ mod test { fn disjoint_vertical_ranges() { let cmp = intersect_cubics(vertical(0.0, 0.0, 1.0), vertical(1.0, 2.0, 3.0), 1e-6, 2e-6); assert_eq!(cmp.iter().count(), 0); + assert_eq!(cmp.order_after(0.5), Order::Ish); + assert_eq!(cmp.with_y_slop(0.5).iter().count(), 0); } #[test] From 9b0200729b50fd7b965101f98f32a61bf8dfcef0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 7 Nov 2026 13:31:39 -0800 Subject: [PATCH 4/4] linesweeper: check_invariants accepts an empty order A comparison of curves with disjoint vertical ranges has an empty order. CurveOrder::check_invariants returns for it instead of unwrapping the first entry, and disjoint_vertical_ranges checks it. --- vendor/linesweeper/README.craft.md | 2 +- vendor/linesweeper/SOURCE.json | 4 ++-- vendor/linesweeper/src/curve/mod.rs | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/vendor/linesweeper/README.craft.md b/vendor/linesweeper/README.craft.md index 82846eaaab..1c738880b5 100644 --- a/vendor/linesweeper/README.craft.md +++ b/vendor/linesweeper/README.craft.md @@ -15,7 +15,7 @@ holds `upstream_revision`. `local_patches` describes each local patch. | File | Change | |---|---| -| `src/curve/mod.rs` | `intersect_cubics` compares a curve whose `p3.y` is below its `p0.y` as the same curve reversed, instead of panicking in `clamp`. `intersect_cubics_with_precomputed_decomp` returns close (`Ish`) over the common range when `sure_tolerance` is not positive, is larger than `ish_tolerance`, or `ish_tolerance` is not finite, instead of panicking, overflowing the stack or returning a wrong order; when the curves' vertical ranges do not overlap, it returns an empty order without a debug assertion failure, and `CurveOrder::with_y_slop` and `CurveOrder::order_after` accept that empty order instead of panicking on an `unwrap`. The docs of these functions, `from_monotone_cubic`, `solve_t_for_y` and `y_subsegment` state their input rules. The `curves_decreasing_in_y`, `invalid_tolerances` and `disjoint_vertical_ranges` tests cover the changes. | +| `src/curve/mod.rs` | `intersect_cubics` compares a curve whose `p3.y` is below its `p0.y` as the same curve reversed, instead of panicking in `clamp`. `intersect_cubics_with_precomputed_decomp` returns close (`Ish`) over the common range when `sure_tolerance` is not positive, is larger than `ish_tolerance`, or `ish_tolerance` is not finite, instead of panicking, overflowing the stack or returning a wrong order; when the curves' vertical ranges do not overlap, it returns an empty order without a debug assertion failure, and `CurveOrder::with_y_slop`, `CurveOrder::order_after` and `CurveOrder::check_invariants` accept that empty order instead of panicking on an `unwrap`. The docs of these functions, `from_monotone_cubic`, `solve_t_for_y` and `y_subsegment` state their input rules. The `curves_decreasing_in_y`, `invalid_tolerances` and `disjoint_vertical_ranges` tests cover the changes. | | `src/topology.rs` | `Topology::bounding_box` returns `Rect::ZERO` for a topology with no segments, as kurbo does for an empty path, instead of a rectangle from infinity to negative infinity. The `empty_bounding_box` test covers it. | `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 85051831d3..24a481a138 100644 --- a/vendor/linesweeper/SOURCE.json +++ b/vendor/linesweeper/SOURCE.json @@ -8,7 +8,7 @@ "upstream_revision": "824b0791a750f7b27b8edcbb6c6244d0e629875e", "upstream_directory": "", "local_patches": [ - "In `src/curve/mod.rs`, `intersect_cubics` reverses a curve whose `p3.y` is below its `p0.y` before comparing it, and `intersect_cubics_with_precomputed_decomp` returns `Ish` over the common range when `sure_tolerance` is not positive or is larger than `ish_tolerance`, or `ish_tolerance` is not finite, and an empty order for curves whose vertical ranges do not overlap, which `CurveOrder::with_y_slop` and `CurveOrder::order_after` accept; the docs of these functions, `from_monotone_cubic`, `solve_t_for_y` and `y_subsegment` state their input rules. In `src/topology.rs`, `Topology::bounding_box` returns `Rect::ZERO` when there are no segments." + "In `src/curve/mod.rs`, `intersect_cubics` reverses a curve whose `p3.y` is below its `p0.y` before comparing it, and `intersect_cubics_with_precomputed_decomp` returns `Ish` over the common range when `sure_tolerance` is not positive or is larger than `ish_tolerance`, or `ish_tolerance` is not finite, and an empty order for curves whose vertical ranges do not overlap, which `CurveOrder::with_y_slop`, `CurveOrder::order_after` and `CurveOrder::check_invariants` accept; the docs of these functions, `from_monotone_cubic`, `solve_t_for_y` and `y_subsegment` state their input rules. In `src/topology.rs`, `Topology::bounding_box` returns `Rect::ZERO` when there are no segments." ], "files": [ { "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" }, @@ -34,7 +34,7 @@ { "path": "proptest-regressions/topology.txt", "source_sha256": "49ff0b5b370f082984276d5312f03b1fc96ef0dd218f9efd7b084b11abbb9d19", "source_git_blob": null, "sha256": "49ff0b5b370f082984276d5312f03b1fc96ef0dd218f9efd7b084b11abbb9d19" }, { "path": "src/arbitrary.rs", "source_sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750", "source_git_blob": null, "sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750" }, { "path": "src/curve/line.rs", "source_sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e", "source_git_blob": null, "sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e" }, - { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "ef0b50d4a922adf7c8b74cddb745986f14427d3a1dae28c544f174addd28bb28" }, + { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "ad8eee65561fdfd32892348a0710717bca54e736a364ddd3587f09694cb69c10" }, { "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 6a81d55159..001bb8c67d 100644 --- a/vendor/linesweeper/src/curve/mod.rs +++ b/vendor/linesweeper/src/curve/mod.rs @@ -324,7 +324,9 @@ impl CurveOrder { /// Asserts that we satisfy our internal invariants. For testing only. pub fn check_invariants(&self) { let mut cmps = self.cmps.iter(); - let mut last = cmps.next().unwrap(); + let Some(mut last) = cmps.next() else { + return; + }; for cmp in cmps { assert!(last.end <= cmp.end); assert!(last.order != cmp.order); @@ -1910,6 +1912,7 @@ mod test { fn disjoint_vertical_ranges() { let cmp = intersect_cubics(vertical(0.0, 0.0, 1.0), vertical(1.0, 2.0, 3.0), 1e-6, 2e-6); assert_eq!(cmp.iter().count(), 0); + cmp.check_invariants(); assert_eq!(cmp.order_after(0.5), Order::Ish); assert_eq!(cmp.with_y_slop(0.5).iter().count(), 0); }