From 62f3c7b6cbaaf6add0a88867fc5e1fb1874cd0aa Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 7 Nov 2026 19:54:17 -0800 Subject: [PATCH] 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. --- NOTICE | 6 +- vendor/linesweeper/README.craft.md | 20 +++--- vendor/linesweeper/SOURCE.json | 6 +- vendor/linesweeper/src/curve/mod.rs | 96 +++++++++++++++++++++-------- 4 files changed, 91 insertions(+), 37 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..30eb6f1d6c 100644 --- a/vendor/linesweeper/README.craft.md +++ b/vendor/linesweeper/README.craft.md @@ -1,15 +1,21 @@ # 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` | `CurveOrder::next_touch_after(y)` walks the order once and compares each touch with `y`. Before, when `y` was inside a touch followed by a Left interval and another touch, it called itself with the end of the Left interval, which is where the next touch starts, so it skipped that touch too and returned `None`. Two curves that start at one point and touch again later gave no later touch at the start height. The `next_touch_after_a_touch_that_contains_y` and `next_touch_after_on_two_curves_that_start_together` tests cover a built order and two curves from `intersect_cubics`. | `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..8ba1fe1257 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`, `CurveOrder::next_touch_after(y)` walks the order once and compares each touch with `y`, so a touch that follows a touch containing `y` and a Left interval is no longer skipped, which made it return `None`." + ], "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": "7bbc99e120d3af0af93df9b6f2fde4da7b5075fef7588f8bf3c4807c007e9d76" }, { "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 f602308573..e0e7864424 100644 --- a/vendor/linesweeper/src/curve/mod.rs +++ b/vendor/linesweeper/src/curve/mod.rs @@ -202,33 +202,36 @@ impl CurveOrder { &self, y: f64, ) -> Option { - let mut iter = self - .iter() - .skip_while(|(_start, end, _order)| end <= &y) - .skip_while(|(_start, _end, order)| *order == Order::Left); + let mut iter = self.iter().skip_while(|(_start, end, _order)| end <= &y); + // The height that a crossing found right away is reported at. + let mut from = y; - let (y0, y1, order) = iter.next()?; - if order == Order::Right { - return Some(CurveInteraction::Cross(y, y)); - } - - let Some((_, next_y1, next_order)) = iter.next() else { - return Some(CurveInteraction::Touch(y0, y1)); - }; - - match next_order { - Order::Right => Some(CurveInteraction::Cross(y0, y1)), - Order::Left => { - if y < y0 { - Some(CurveInteraction::Touch(y0, y1)) - } else { - self.next_touch_after(next_y1) - } + loop { + let (y0, y1, order) = iter.find(|(_start, _end, order)| *order != Order::Left)?; + if order == Order::Right { + return Some(CurveInteraction::Cross(from, from)); } - Order::Ish => { - // The current order is Ish and adjacent orders get merged, - // so the next one isn't Ish. - unreachable!(); + + let Some((_, next_y1, next_order)) = iter.next() else { + return Some(CurveInteraction::Touch(y0, y1)); + }; + + match next_order { + Order::Right => return Some(CurveInteraction::Cross(y0, y1)), + Order::Left => { + if y < y0 { + return Some(CurveInteraction::Touch(y0, y1)); + } + // `y` is inside this Ish interval, so look for the next + // one. It starts after `y`, so it is compared with `y` + // and not with the end of the Left interval before it. + from = next_y1; + } + Order::Ish => { + // The current order is Ish and adjacent orders get merged, + // so the next one isn't Ish. + unreachable!(); + } } } } @@ -1747,6 +1750,49 @@ mod test { assert_eq!(cmp.iter().count(), 3); } + #[test] + fn next_touch_after_a_touch_that_contains_y() { + let mut cmp = CurveOrder::new(0.0); + for (end, order) in [ + (1.0, Order::Ish), + (2.0, Order::Left), + (3.0, Order::Ish), + (4.0, Order::Left), + ] { + cmp.push(end, order, MetricsStatus::default()); + } + + let touch = |y: f64| match cmp.next_touch_after(y) { + Some(CurveInteraction::Touch(y0, y1)) => (y0, y1), + other => panic!("expected a touch after {y}, got {other:?}"), + }; + // `y` inside the first touch or after it: the next one is the touch + // from 2 to 3. + assert_eq!(touch(0.0), (2.0, 3.0)); + assert_eq!(touch(0.5), (2.0, 3.0)); + assert_eq!(touch(1.5), (2.0, 3.0)); + // `y` inside the second touch, with no touch after it. + assert!(cmp.next_touch_after(2.5).is_none()); + assert!(cmp.next_touch_after(4.0).is_none()); + } + + #[test] + fn next_touch_after_on_two_curves_that_start_together() { + // The cubic starts on the line, moves left of it and comes back to + // touch it again near y = 2.4. + let a = CubicBez::new((0.0, 0.0), (-1.2, 4.0 / 3.0), (1.6, 8.0 / 3.0), (-1.6, 4.0)); + let b = CubicBez::new((0.0, 0.0), (0.0, 4.0 / 3.0), (0.0, 8.0 / 3.0), (0.0, 4.0)); + let cmp = intersect_cubics(a, b, 1e-3, 0.02); + let orders: Vec<_> = cmp.iter().map(|(_, _, order)| order).collect(); + assert_eq!(orders, [Order::Ish, Order::Left, Order::Ish, Order::Left]); + + let (touch_y0, touch_y1, _) = cmp.iter().nth(2).unwrap(); + match cmp.next_touch_after(0.0) { + Some(CurveInteraction::Touch(y0, y1)) => assert_eq!((y0, y1), (touch_y0, touch_y1)), + other => panic!("expected the second touch, got {other:?}"), + } + } + #[test] fn quad_approximation() { let c = CubicBez {