From a7b1dc28fbeb1ea1cacdb08ef921c797a143c2f6 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 7 Nov 2026 19:58:12 -0800 Subject: [PATCH 1/2] 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. --- NOTICE | 6 +- vendor/linesweeper/README.craft.md | 23 +++-- vendor/linesweeper/SOURCE.json | 16 +-- vendor/linesweeper/src/curve/mod.rs | 115 +++++++++++++++++++++ vendor/linesweeper/src/lib.rs | 92 +++++++++++++++++ vendor/linesweeper/src/position.rs | 27 ++++- vendor/linesweeper/src/segments.rs | 23 +++++ vendor/linesweeper/src/sweep/sweep_line.rs | 4 + vendor/linesweeper/src/topology.rs | 5 + 9 files changed, 293 insertions(+), 18 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..43be429020 100644 --- a/vendor/linesweeper/README.craft.md +++ b/vendor/linesweeper/README.craft.md @@ -1,15 +1,24 @@ # 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/lib.rs` | `binary_op_with_eps` returns the new `Error::InvalidEps` when `eps` is NaN, infinite, zero or negative, instead of returning a wrong region (NaN or negative `eps`) or hanging (`-inf`). The `binary_op_with_eps_rejects_invalid_eps`, `topology_raises_unusable_eps` and `binary_op_with_eps_raises_eps_below_coordinate_resolution` tests cover the changes in this file, `src/segments.rs`, `src/sweep/sweep_line.rs` and `src/topology.rs`. | +| `src/segments.rs`, `src/sweep/sweep_line.rs`, `src/topology.rs` | 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. Before, an `eps` below one ulp of the coordinates (0 included, or 1e-10 at 1.5e8) overflowed the stack and aborted the process. | +| `src/curve/mod.rs` | `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 (two to four ulps of it, 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. Below that, rounding made the comparison report the wrong order. `intersect_cubics_rec` returns close (`Ish`) for an interval whose midpoint rounds to one of its ends instead of splitting it again, which repeated the same call until the stack overflowed. The `ish_tolerance_below_float_spacing` test covers both. `raised_tolerance_keeps_far_curves_apart`, `raised_tolerance_ignores_large_y` and `raised_tolerance_keeps_subnormal_curves_apart` check that lines 1.0 apart at x = 1e15, lines 1.0 apart at y = 2e15, and lines at x = 1e-310 and 2e-310 stay ordered. | +| `src/position.rs` | `approximate` stops halving an interval whose midpoint rounds to one of its ends. Before, it could return the interval's start, and the loop in `compute_positions_correct` then made no progress. The `approx_stops_at_one_float` 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..798dff0e41 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/lib.rs`, `src/segments.rs`, `src/sweep/sweep_line.rs` and `src/topology.rs`, `binary_op_with_eps` returns the new `Error::InvalidEps` for an `eps` that is NaN, infinite, zero or negative, and 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, so a bad `eps` no longer gives a wrong region, a hang or a stack overflow. In `src/curve/mod.rs`, `intersect_cubics` and `intersect_cubics_with_precomputed_decomp` raise a positive `ish_tolerance` below `4 * f64::EPSILON` times the 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, and `intersect_cubics_rec` returns `Ish` for an interval whose midpoint rounds to one of its ends instead of recursing on it again. In `src/position.rs`, `approximate` stops halving such an interval, so `compute_positions_correct` always advances." + ], "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,17 +34,17 @@ { "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": "cbc6f444153525e7da85473466434b07826c75d0500773a0aa3cf068c5225d09" }, { "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" }, { "path": "src/geom.rs", "source_sha256": "9878ffa6d4a13fa2c9149741c137205ca01acb626a5b9f86a3db75cf91b63a08", "source_git_blob": null, "sha256": "9878ffa6d4a13fa2c9149741c137205ca01acb626a5b9f86a3db75cf91b63a08" }, - { "path": "src/lib.rs", "source_sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6", "source_git_blob": null, "sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6" }, + { "path": "src/lib.rs", "source_sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6", "source_git_blob": null, "sha256": "e4835e7e1027174deadd7d38a65f6d6932cda831c59da7283207c1b604261d27" }, { "path": "src/num.rs", "source_sha256": "39ff85da50c500ce91cf6dea81aedc0dcca1db5e7d0506696dde2da118e93a2a", "source_git_blob": null, "sha256": "39ff85da50c500ce91cf6dea81aedc0dcca1db5e7d0506696dde2da118e93a2a" }, { "path": "src/order.rs", "source_sha256": "7e5b04eae8af134abb032e995f1d3c2ac473822923dfee8d463d9ade6ffeb596", "source_git_blob": null, "sha256": "7e5b04eae8af134abb032e995f1d3c2ac473822923dfee8d463d9ade6ffeb596" }, { "path": "src/perturbation.rs", "source_sha256": "fa274a822bbdf65f8e53e403eef78034dd87964b3f1d3134a064df4ec8cef9c5", "source_git_blob": null, "sha256": "fa274a822bbdf65f8e53e403eef78034dd87964b3f1d3134a064df4ec8cef9c5" }, - { "path": "src/position.rs", "source_sha256": "dfa70840805ecccf5b7eb6122921e46ca60c24cb7b3c17f3b55ffc2549368ab0", "source_git_blob": null, "sha256": "dfa70840805ecccf5b7eb6122921e46ca60c24cb7b3c17f3b55ffc2549368ab0" }, - { "path": "src/segments.rs", "source_sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc", "source_git_blob": null, "sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc" }, + { "path": "src/position.rs", "source_sha256": "dfa70840805ecccf5b7eb6122921e46ca60c24cb7b3c17f3b55ffc2549368ab0", "source_git_blob": null, "sha256": "0934efacd54a7bbd55705bbbbea6bd7820df3c4d3f4e97673eb68fdfc9007bf0" }, + { "path": "src/segments.rs", "source_sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc", "source_git_blob": null, "sha256": "d108c56a905e7d3ffb47188ebaf43f0a1cdbb94aa7083807ed1becbb3b927f3e" }, { "path": "src/snapshots/linesweeper__tests__empty_horizontals.snap", "source_sha256": "e319881853e889badf6524f19af4cd6f112e8dd71bdc516826f4463134a82244", "source_git_blob": null, "sha256": "e319881853e889badf6524f19af4cd6f112e8dd71bdc516826f4463134a82244" }, { "path": "src/snapshots/linesweeper__tests__two_squares.snap", "source_sha256": "01961e0311a5af3b8f13eb52a2a7112560c47cf86771c04e40475dc6f15a0846", "source_git_blob": null, "sha256": "01961e0311a5af3b8f13eb52a2a7112560c47cf86771c04e40475dc6f15a0846" }, { "path": "src/snapshots/linesweeper__topology__tests__diamond.snap", "source_sha256": "cfaefd620a0a3d1376861bca09cd7c658ef00a32635b88f1b259a9b39cd15502", "source_git_blob": null, "sha256": "cfaefd620a0a3d1376861bca09cd7c658ef00a32635b88f1b259a9b39cd15502" }, @@ -62,8 +64,8 @@ { "path": "src/sweep/snapshots/linesweeper__sweep__sweep_line__tests__square.snap", "source_sha256": "b35c3e6a38d5ecdd8acf315ba0b0bd6485cd8b40193fdd76bd446bdfdb6eda77", "source_git_blob": null, "sha256": "b35c3e6a38d5ecdd8acf315ba0b0bd6485cd8b40193fdd76bd446bdfdb6eda77" }, { "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/sweep/sweep_line.rs", "source_sha256": "822b261f682911ea0c0370eaf17d9201a1e639b315359dcb6a3b877a229816e3", "source_git_blob": null, "sha256": "c0401befb020a407347273fe7fa40dfd884fa4e51f73ea169bd9e9edb75e80af" }, + { "path": "src/topology.rs", "source_sha256": "9c9b48bc3853884425127e2d64e8ed957ba0d27e1696e2c457e95282e52d6a5b", "source_git_blob": null, "sha256": "d84ea63494f4583c0cb28c540650ccc524b5b74b7e7fcb1fd43254171fd16d6e" }, { "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..75303f587d 100644 --- a/vendor/linesweeper/src/curve/mod.rs +++ b/vendor/linesweeper/src/curve/mod.rs @@ -1196,6 +1196,30 @@ fn max_distance(c0: CubicBez, c1: CubicBez) -> f64 { .max(l_infty_distance(c0.p3, c1.p3)) } +/// The largest absolute value of any control point's x coordinate. +fn max_abs_x(c: CubicBez) -> f64 { + [c.p0, c.p1, c.p2, c.p3] + .iter() + .fold(0.0, |m: f64, p| m.max(p.x.abs())) +} + +/// The spacing of the smallest floats, which is also the spacing of all +/// subnormal floats. +const MIN_SPACING: f64 = f64::from_bits(1); + +/// The smallest tolerance that tells apart coordinates of magnitude up to +/// `max_coord`: `64 * f64::EPSILON * max_coord`, the scale [`crate::binary_op`] +/// uses, and never below 64 times the spacing of subnormal floats. +pub(crate) fn resolution_floor(max_coord: f64) -> f64 { + (max_coord * (f64::EPSILON * 64.0)).max(MIN_SPACING * 64.0) +} + +/// `f64::EPSILON * max_coord`, between one and two ulps of `max_coord`, and +/// never below the spacing of subnormal floats. +fn float_spacing(max_coord: f64) -> f64 { + (max_coord * f64::EPSILON).max(MIN_SPACING) +} + #[derive(Clone, Debug)] struct CubicParams { c: CubicBez, @@ -1337,7 +1361,14 @@ fn intersect_cubics_rec( // "ish" interval that's just an artifact. In this case, new_y0 and new_y1 // will be very close, but we'll recurse one more time to get a better // quadratic approximation. + // + // When `mid` rounds to one of the ends, the interval is one float + // wide and cannot be split, so splitting it would repeat the same + // call until the stack overflows. That happens when `ish_tolerance` + // is below the spacing of floats at this height. if y1 - y0 <= ish_tolerance + || mid <= new_y0 + || mid >= new_y1 || (ep0.dmax + ep1.dmax <= 2.0 * ish_tolerance && ep0.dmin + ep1.dmin >= -2.0 * ish_tolerance) { @@ -1538,6 +1569,12 @@ 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. +/// +/// A positive `ish_tolerance` below `4 * f64::EPSILON` times the largest +/// x coordinate magnitude of the two curves (two to four ulps of it, and at +/// least four times the spacing of subnormal floats) is raised to that value, +/// and a positive `sure_tolerance` below half of it is raised to half of it. +/// Below that, rounding in the comparison can report the wrong order. pub fn intersect_cubics( c0: CubicBez, c1: CubicBez, @@ -1559,6 +1596,8 @@ pub fn intersect_cubics( /// /// Pre-computing the almost-horizontal decomposition can be much faster, because /// then you can do it per-curve instead of per-comparison. +/// +/// The tolerances are raised as in [intersect_cubics]. pub fn intersect_cubics_with_precomputed_decomp( c0: CubicBez, c0_div: &AlmostHorizontalDecomposition, @@ -1567,6 +1606,18 @@ pub fn intersect_cubics_with_precomputed_decomp( sure_tolerance: f64, ish_tolerance: f64, ) -> CurveOrder { + let floor = 4.0 * float_spacing(max_abs_x(c0).max(max_abs_x(c1))); + let ish_tolerance = if ish_tolerance > 0.0 && ish_tolerance < floor { + floor + } else { + ish_tolerance + }; + let sure_tolerance = if sure_tolerance > 0.0 && sure_tolerance < floor / 2.0 { + floor / 2.0 + } else { + sure_tolerance + }; + let y0 = c0.p0.y.max(c1.p0.y); let y1 = c0.p3.y.min(c1.p3.y); @@ -1974,6 +2025,70 @@ mod test { dbg!(intersect_cubics(c0, c1, sure_tol, ish_tol)); } + // At a height of 1.5e8 one ulp is about 3e-8, more than `ish_tolerance`. + // Splitting the close interval around a crossing used to repeat the same + // one-ulp interval until the stack overflowed. + #[test] + fn ish_tolerance_below_float_spacing() { + let offset = 1.5e8; + let mut segs = crate::Segments::default(); + segs.add_bez_path(&kurbo::Circle::new((offset, offset), 1.0).to_path(1e-9)) + .unwrap(); + segs.add_bez_path(&kurbo::Circle::new((offset + 1.0, offset), 1.0).to_path(1e-9)) + .unwrap(); + let cubics: Vec<_> = segs.segments().map(|s| s.to_kurbo_cubic()).collect(); + let mut compared = 0; + for c0 in &cubics { + for c1 in &cubics { + let y1 = c0.p3.y.min(c1.p3.y); + if c0.p0.y.max(c1.p0.y) >= y1 { + continue; + } + let order = intersect_cubics(*c0, *c1, 5e-11, 1e-10); + order.check_invariants(); + assert_eq!(order.iter().last().map(|(_, end, _)| end), Some(y1)); + compared += 1; + } + } + assert!(compared > 0); + } + + // Raising tiny tolerances must not merge curves that are a few ulps + // apart: at 1e15 one ulp is 0.125, and these lines are 1.0 apart. + #[test] + fn raised_tolerance_keeps_far_curves_apart() { + let x = 1e15; + let c0 = PathSeg::Line(Line::new((x, 0.0), (x, 1.0))).to_cubic(); + let c1 = PathSeg::Line(Line::new((x + 1.0, 0.0), (x + 1.0, 1.0))).to_cubic(); + let order = intersect_cubics(c0, c1, 1e-12, 1e-11); + let entries: Vec<_> = order.iter().collect(); + assert_eq!(entries, vec![(0.0, 1.0, Order::Left)]); + } + + // The floor depends on the x coordinates only: large y coordinates do + // not make lines 1.0 apart close. + #[test] + fn raised_tolerance_ignores_large_y() { + let y = 2e15; + let c0 = PathSeg::Line(Line::new((0.0, y), (0.0, y + 1.0))).to_cubic(); + let c1 = PathSeg::Line(Line::new((1.0, y), (1.0, y + 1.0))).to_cubic(); + let order = intersect_cubics(c0, c1, 1e-12, 1e-11); + let entries: Vec<_> = order.iter().collect(); + assert_eq!(entries, vec![(y, y + 1.0, Order::Left)]); + } + + // Subnormal coordinates keep their order: the floor goes down to the + // spacing of subnormal floats, not to `f64::MIN_POSITIVE`. + #[test] + fn raised_tolerance_keeps_subnormal_curves_apart() { + let x = 1e-310; + let c0 = PathSeg::Line(Line::new((x, 0.0), (x, 1.0))).to_cubic(); + let c1 = PathSeg::Line(Line::new((2.0 * x, 0.0), (2.0 * x, 1.0))).to_cubic(); + let order = intersect_cubics(c0, c1, 1e-320, 2e-320); + let entries: Vec<_> = order.iter().collect(); + assert_eq!(entries, vec![(0.0, 1.0, Order::Left)]); + } + #[test] fn quadratic_comparison() { let c0 = CubicBez::new((0.0, 0.0), (10.0, 10.0), (20.0, 20.0), (30.0, 30.0)); diff --git a/vendor/linesweeper/src/lib.rs b/vendor/linesweeper/src/lib.rs index 7d2500d095..768f91aad6 100644 --- a/vendor/linesweeper/src/lib.rs +++ b/vendor/linesweeper/src/lib.rs @@ -74,6 +74,8 @@ pub enum Error { NaN, /// One of the inputs had a non-closed path. NonClosedPath(NonClosedPath), + /// The accuracy parameter was NaN, infinite, zero or negative. + InvalidEps, } impl From for Error { @@ -88,6 +90,9 @@ impl std::fmt::Display for Error { Error::Infinity => write!(f, "one of the inputs was infinite"), Error::NaN => write!(f, "one of the inputs had a NaN"), Error::NonClosedPath(_) => write!(f, "one of the inputs had a non-closed path"), + Error::InvalidEps => { + write!(f, "the accuracy parameter was not a positive finite number") + } } } } @@ -133,6 +138,10 @@ pub fn binary_op( /// /// The output paths will not exactly agree with the input paths in general. /// The accuracy parameter `eps` bounds how much they can differ. +/// +/// Returns [`Error::InvalidEps`] when `eps` is NaN, infinite, zero or +/// negative. An `eps` below `64 * f64::EPSILON` times the largest coordinate +/// magnitude is raised to that value. pub fn binary_op_with_eps( set_a: &kurbo::BezPath, set_b: &kurbo::BezPath, @@ -140,6 +149,9 @@ pub fn binary_op_with_eps( op: BinaryOp, eps: f64, ) -> Result { + if !(eps.is_finite() && eps > 0.0) { + return Err(Error::InvalidEps); + } let top = Topology::from_paths_binary(set_a, set_b, eps)?; #[cfg(feature = "debug-svg")] { @@ -333,4 +345,84 @@ mod tests { 4 ); } + + /// Two unit circles whose centers are one unit apart, at `(offset, offset)` + /// and `(offset + 1, offset)`. + fn crossing_circles(offset: f64) -> (BezPath, BezPath) { + ( + kurbo::Circle::new((offset, offset), 1.0).to_path(1e-9), + kurbo::Circle::new((offset + 1.0, offset), 1.0).to_path(1e-9), + ) + } + + /// The single contour's area, measured after moving it back to the origin. + fn single_contour_area(contours: &topology::Contours, offset: f64) -> f64 { + let contours: Vec<_> = contours.contours().collect(); + assert_eq!(contours.len(), 1); + (kurbo::Affine::translate((-offset, -offset)) * contours[0].path.clone()) + .area() + .abs() + } + + const UNION_AREA: f64 = 5.054816; + + #[test] + fn binary_op_with_eps_rejects_invalid_eps() { + let (a, b) = crossing_circles(0.0); + // -inf goes last: before the check it made the sweep loop forever. + for eps in [ + f64::NAN, + -1.0, + -1e-6, + 0.0, + -0.0, + f64::INFINITY, + f64::NEG_INFINITY, + ] { + let result = binary_op_with_eps(&a, &b, FillRule::NonZero, BinaryOp::Union, eps); + assert_eq!(result.err(), Some(Error::InvalidEps), "eps = {eps}"); + } + } + + #[test] + fn topology_raises_unusable_eps() { + let inside = |w: &BinaryWindingNumber| w.shape_a != 0 || w.shape_b != 0; + // At 1.5e8 one ulp is about 3e-8, so 1e-10 used to recurse in + // intersect_cubics_rec until the stack overflowed. + for (offset, eps) in [ + (0.0, f64::NAN), + (0.0, -1.0), + (0.0, 0.0), + (1.5e8, 1e-10), + (1.5e8, 0.0), + (0.0, f64::NEG_INFINITY), + ] { + let (a, b) = crossing_circles(offset); + for correctness in [ + sweep::Correctness::GoodEnough, + sweep::Correctness::ReallyCorrect, + ] { + let top = Topology::from_paths_with_correctness( + [(&a, topology::OneOfTwo::A), (&b, topology::OneOfTwo::B)], + eps, + correctness, + ) + .unwrap(); + let area = single_contour_area(&top.contours(inside), offset); + assert!( + (area - UNION_AREA).abs() < 1e-3, + "offset {offset}, eps {eps}, {correctness:?}: area {area}" + ); + } + } + } + + #[test] + fn binary_op_with_eps_raises_eps_below_coordinate_resolution() { + let (a, b) = crossing_circles(1.5e8); + let contours = + binary_op_with_eps(&a, &b, FillRule::NonZero, BinaryOp::Union, 1e-10).unwrap(); + let area = single_contour_area(&contours, 1.5e8); + assert!((area - UNION_AREA).abs() < 1e-3, "area {area}"); + } } diff --git a/vendor/linesweeper/src/position.rs b/vendor/linesweeper/src/position.rs index f4cbd773d5..d893f67c6d 100644 --- a/vendor/linesweeper/src/position.rs +++ b/vendor/linesweeper/src/position.rs @@ -168,7 +168,10 @@ fn approximate( let factor = horizontal_error_weight(cubic); - let too_short = y1 <= y0 + accuracy; + // An interval whose midpoint rounds to one of its ends cannot be + // halved. Halving it anyway would leave `y1` where it is, or return + // `y0` and stop the caller's loop from advancing. + let too_short = y1 <= y0 + accuracy || y_mid <= y0 || y_mid >= y1; let accurate = approx.dmax.max(-approx.dmin) * factor < accuracy; if !too_short && !accurate { // TODO: can we be smarter about this? @@ -558,4 +561,26 @@ mod tests { let next_y0 = super::approximate(90.03645987646233, y1, &[s0, s1], &segs, 2.5e-7, &mut out); assert_eq!(next_y0, y1); } + + // With an accuracy that no approximation meets, the interval is halved + // until it is one float wide. At 1.5e8 the midpoint of such an interval + // rounds to its start, and `approximate` used to return the start, which + // left the loop in `compute_positions_correct` without progress. + #[test] + fn approx_stops_at_one_float() { + let y0 = 1.5e8; + let mut p = BezPath::new(); + p.move_to((y0, y0)); + p.curve_to((y0 + 1.0, y0 + 0.3), (y0 - 1.0, y0 + 0.7), (y0, y0 + 1.0)); + p.close_path(); + + let mut segs = Segments::default(); + segs.add_bez_path(&p).unwrap(); + let s0 = segs.indices().next().unwrap(); + + let mut out = Vec::new(); + let next_y0 = super::approximate(y0, y0 + 1.0, &[s0], &segs, 0.0, &mut out); + assert!(next_y0 > y0, "next_y0 = {next_y0}"); + assert_eq!(out.len(), 1); + } } diff --git a/vendor/linesweeper/src/segments.rs b/vendor/linesweeper/src/segments.rs index 909eb01d2e..b35c136a2b 100644 --- a/vendor/linesweeper/src/segments.rs +++ b/vendor/linesweeper/src/segments.rs @@ -471,6 +471,29 @@ impl Segments { debug_assert!(!self.segs[idx].is_horizontal()); &self.horizontal_decomps[idx] } + + /// The sweep tolerance to use for these segments when the caller asks for `eps`. + /// + /// Returns `eps` when it is at least `64 * f64::EPSILON` times the largest + /// coordinate magnitude (the scale [`crate::binary_op`] uses), and that + /// floor otherwise. The floor replaces an `eps` that is NaN, negative, + /// zero, or too small to tell coordinates of this size apart. It is never + /// below 64 times the spacing of subnormal floats. + pub(crate) fn usable_eps(&self, eps: f64) -> f64 { + let max_coord = self + .segs + .iter() + .map(|(_, seg)| { + seg.min_x() + .abs() + .max(seg.max_x().abs()) + .max(seg.start().y.abs()) + .max(seg.end().y.abs()) + }) + .fold(0.0, f64::max); + let floor = crate::curve::resolution_floor(max_coord); + if eps >= floor { eps } else { floor } + } } impl std::ops::Index for Segments { diff --git a/vendor/linesweeper/src/sweep/sweep_line.rs b/vendor/linesweeper/src/sweep/sweep_line.rs index b4b1883e29..c4dbab9715 100644 --- a/vendor/linesweeper/src/sweep/sweep_line.rs +++ b/vendor/linesweeper/src/sweep/sweep_line.rs @@ -359,11 +359,15 @@ impl<'segs> Sweeper<'segs> { /// The really correct mode doesn't actually change any of the /// output orders, but it does emit extra events whenever lines /// touch without crossing. + /// + /// An `eps` that is NaN, not positive, or below `64 * f64::EPSILON` times + /// the segments' largest coordinate magnitude is raised to that value. pub fn new_with_correctness( segments: &'segs Segments, eps: f64, correctness: Correctness, ) -> Self { + let eps = segments.usable_eps(eps); let events = EventQueue::default(); Sweeper { eps, diff --git a/vendor/linesweeper/src/topology.rs b/vendor/linesweeper/src/topology.rs index 8420d015a5..f717bee1b4 100644 --- a/vendor/linesweeper/src/topology.rs +++ b/vendor/linesweeper/src/topology.rs @@ -512,6 +512,10 @@ impl Topology { /// Construct a new topology from a collection of paths and tags. /// /// See [`WindingNumber`] about the tags are for. + /// + /// An `eps` that is NaN, not positive, or below `64 * f64::EPSILON` times + /// the paths' largest coordinate magnitude is raised to that value. The + /// other constructors pass `eps` through here, or follow the same rule. pub fn from_paths_with_correctness<'a, Iter>(paths: Iter, eps: f64, correctness: Correctness) -> Result where Iter: IntoIterator, @@ -538,6 +542,7 @@ impl Topology { eps: f64, correctness: Correctness, ) -> Self { + let eps = segments.usable_eps(eps); let mut ret = Self { eps, correctness, From e8299ed92d9305aed6a28008ae57a65f4c3743b8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 9 Nov 2026 06:11:49 -0800 Subject: [PATCH 2/2] linesweeper: an infinite eps is replaced like a NaN or zero eps The Topology constructors and Sweeper::new_with_correctness passed a positive infinite eps through unchanged, and a lens of two arcs lost its arcs as coincident. It now takes the same coordinate-based floor as other unusable values. --- vendor/linesweeper/README.craft.md | 2 +- vendor/linesweeper/SOURCE.json | 10 +++++----- vendor/linesweeper/src/lib.rs | 1 + vendor/linesweeper/src/segments.rs | 12 ++++++++---- vendor/linesweeper/src/sweep/sweep_line.rs | 4 ++-- vendor/linesweeper/src/topology.rs | 4 ++-- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/vendor/linesweeper/README.craft.md b/vendor/linesweeper/README.craft.md index 43be429020..faeec19a58 100644 --- a/vendor/linesweeper/README.craft.md +++ b/vendor/linesweeper/README.craft.md @@ -16,7 +16,7 @@ holds `upstream_revision`. `local_patches` describes each local patch. | File | Change | |---|---| | `src/lib.rs` | `binary_op_with_eps` returns the new `Error::InvalidEps` when `eps` is NaN, infinite, zero or negative, instead of returning a wrong region (NaN or negative `eps`) or hanging (`-inf`). The `binary_op_with_eps_rejects_invalid_eps`, `topology_raises_unusable_eps` and `binary_op_with_eps_raises_eps_below_coordinate_resolution` tests cover the changes in this file, `src/segments.rs`, `src/sweep/sweep_line.rs` and `src/topology.rs`. | -| `src/segments.rs`, `src/sweep/sweep_line.rs`, `src/topology.rs` | 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. Before, an `eps` below one ulp of the coordinates (0 included, or 1e-10 at 1.5e8) overflowed the stack and aborted the process. | +| `src/segments.rs`, `src/sweep/sweep_line.rs`, `src/topology.rs` | The `Topology` constructors and `Sweeper::new_with_correctness` replace an `eps` that is NaN, infinite, not positive, or below `64 * f64::EPSILON` times the largest coordinate magnitude (and at least 64 times the spacing of subnormal floats) with that value, the scale `binary_op` uses. Before, an infinite `eps` made a lens of two arcs vanish, and an `eps` below one ulp of the coordinates (0 included, or 1e-10 at 1.5e8) overflowed the stack and aborted the process. | | `src/curve/mod.rs` | `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 (two to four ulps of it, 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. Below that, rounding made the comparison report the wrong order. `intersect_cubics_rec` returns close (`Ish`) for an interval whose midpoint rounds to one of its ends instead of splitting it again, which repeated the same call until the stack overflowed. The `ish_tolerance_below_float_spacing` test covers both. `raised_tolerance_keeps_far_curves_apart`, `raised_tolerance_ignores_large_y` and `raised_tolerance_keeps_subnormal_curves_apart` check that lines 1.0 apart at x = 1e15, lines 1.0 apart at y = 2e15, and lines at x = 1e-310 and 2e-310 stay ordered. | | `src/position.rs` | `approximate` stops halving an interval whose midpoint rounds to one of its ends. Before, it could return the interval's start, and the loop in `compute_positions_correct` then made no progress. The `approx_stops_at_one_float` test covers it. | diff --git a/vendor/linesweeper/SOURCE.json b/vendor/linesweeper/SOURCE.json index 798dff0e41..1542e9e3d9 100644 --- a/vendor/linesweeper/SOURCE.json +++ b/vendor/linesweeper/SOURCE.json @@ -8,7 +8,7 @@ "upstream_revision": "824b0791a750f7b27b8edcbb6c6244d0e629875e", "upstream_directory": "", "local_patches": [ - "In `src/lib.rs`, `src/segments.rs`, `src/sweep/sweep_line.rs` and `src/topology.rs`, `binary_op_with_eps` returns the new `Error::InvalidEps` for an `eps` that is NaN, infinite, zero or negative, and 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, so a bad `eps` no longer gives a wrong region, a hang or a stack overflow. In `src/curve/mod.rs`, `intersect_cubics` and `intersect_cubics_with_precomputed_decomp` raise a positive `ish_tolerance` below `4 * f64::EPSILON` times the 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, and `intersect_cubics_rec` returns `Ish` for an interval whose midpoint rounds to one of its ends instead of recursing on it again. In `src/position.rs`, `approximate` stops halving such an interval, so `compute_positions_correct` always advances." + "In `src/lib.rs`, `src/segments.rs`, `src/sweep/sweep_line.rs` and `src/topology.rs`, `binary_op_with_eps` returns the new `Error::InvalidEps` for an `eps` that is NaN, infinite, zero or negative, and the `Topology` constructors and `Sweeper::new_with_correctness` replace an `eps` that is NaN, infinite, not positive, or below `64 * f64::EPSILON` times the largest coordinate magnitude (and at least 64 times the spacing of subnormal floats) with that value, so a bad `eps` no longer gives a wrong region, a hang or a stack overflow. In `src/curve/mod.rs`, `intersect_cubics` and `intersect_cubics_with_precomputed_decomp` raise a positive `ish_tolerance` below `4 * f64::EPSILON` times the 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, and `intersect_cubics_rec` returns `Ish` for an interval whose midpoint rounds to one of its ends instead of recursing on it again. In `src/position.rs`, `approximate` stops halving such an interval, so `compute_positions_correct` always advances." ], "files": [ { "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" }, @@ -39,12 +39,12 @@ { "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" }, { "path": "src/geom.rs", "source_sha256": "9878ffa6d4a13fa2c9149741c137205ca01acb626a5b9f86a3db75cf91b63a08", "source_git_blob": null, "sha256": "9878ffa6d4a13fa2c9149741c137205ca01acb626a5b9f86a3db75cf91b63a08" }, - { "path": "src/lib.rs", "source_sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6", "source_git_blob": null, "sha256": "e4835e7e1027174deadd7d38a65f6d6932cda831c59da7283207c1b604261d27" }, + { "path": "src/lib.rs", "source_sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6", "source_git_blob": null, "sha256": "5eab08a7e620f1eca3744826ceb2c575abc6b9154315feba35db486380e2edc5" }, { "path": "src/num.rs", "source_sha256": "39ff85da50c500ce91cf6dea81aedc0dcca1db5e7d0506696dde2da118e93a2a", "source_git_blob": null, "sha256": "39ff85da50c500ce91cf6dea81aedc0dcca1db5e7d0506696dde2da118e93a2a" }, { "path": "src/order.rs", "source_sha256": "7e5b04eae8af134abb032e995f1d3c2ac473822923dfee8d463d9ade6ffeb596", "source_git_blob": null, "sha256": "7e5b04eae8af134abb032e995f1d3c2ac473822923dfee8d463d9ade6ffeb596" }, { "path": "src/perturbation.rs", "source_sha256": "fa274a822bbdf65f8e53e403eef78034dd87964b3f1d3134a064df4ec8cef9c5", "source_git_blob": null, "sha256": "fa274a822bbdf65f8e53e403eef78034dd87964b3f1d3134a064df4ec8cef9c5" }, { "path": "src/position.rs", "source_sha256": "dfa70840805ecccf5b7eb6122921e46ca60c24cb7b3c17f3b55ffc2549368ab0", "source_git_blob": null, "sha256": "0934efacd54a7bbd55705bbbbea6bd7820df3c4d3f4e97673eb68fdfc9007bf0" }, - { "path": "src/segments.rs", "source_sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc", "source_git_blob": null, "sha256": "d108c56a905e7d3ffb47188ebaf43f0a1cdbb94aa7083807ed1becbb3b927f3e" }, + { "path": "src/segments.rs", "source_sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc", "source_git_blob": null, "sha256": "16976779627959735493eb16177220148048cbb9fed0efb85112b50b0f78c2f4" }, { "path": "src/snapshots/linesweeper__tests__empty_horizontals.snap", "source_sha256": "e319881853e889badf6524f19af4cd6f112e8dd71bdc516826f4463134a82244", "source_git_blob": null, "sha256": "e319881853e889badf6524f19af4cd6f112e8dd71bdc516826f4463134a82244" }, { "path": "src/snapshots/linesweeper__tests__two_squares.snap", "source_sha256": "01961e0311a5af3b8f13eb52a2a7112560c47cf86771c04e40475dc6f15a0846", "source_git_blob": null, "sha256": "01961e0311a5af3b8f13eb52a2a7112560c47cf86771c04e40475dc6f15a0846" }, { "path": "src/snapshots/linesweeper__topology__tests__diamond.snap", "source_sha256": "cfaefd620a0a3d1376861bca09cd7c658ef00a32635b88f1b259a9b39cd15502", "source_git_blob": null, "sha256": "cfaefd620a0a3d1376861bca09cd7c658ef00a32635b88f1b259a9b39cd15502" }, @@ -64,8 +64,8 @@ { "path": "src/sweep/snapshots/linesweeper__sweep__sweep_line__tests__square.snap", "source_sha256": "b35c3e6a38d5ecdd8acf315ba0b0bd6485cd8b40193fdd76bd446bdfdb6eda77", "source_git_blob": null, "sha256": "b35c3e6a38d5ecdd8acf315ba0b0bd6485cd8b40193fdd76bd446bdfdb6eda77" }, { "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": "c0401befb020a407347273fe7fa40dfd884fa4e51f73ea169bd9e9edb75e80af" }, - { "path": "src/topology.rs", "source_sha256": "9c9b48bc3853884425127e2d64e8ed957ba0d27e1696e2c457e95282e52d6a5b", "source_git_blob": null, "sha256": "d84ea63494f4583c0cb28c540650ccc524b5b74b7e7fcb1fd43254171fd16d6e" }, + { "path": "src/sweep/sweep_line.rs", "source_sha256": "822b261f682911ea0c0370eaf17d9201a1e639b315359dcb6a3b877a229816e3", "source_git_blob": null, "sha256": "8e901d5cb80f2b920db1c5be85fdd31d6a31ca4b71191aea930a17a90ede1a35" }, + { "path": "src/topology.rs", "source_sha256": "9c9b48bc3853884425127e2d64e8ed957ba0d27e1696e2c457e95282e52d6a5b", "source_git_blob": null, "sha256": "701a53d627f3ef2ccde552fb1d35fb445ef51dba356fcce0e9f9f091bf71f66f" }, { "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/lib.rs b/vendor/linesweeper/src/lib.rs index 768f91aad6..ecdfede7dd 100644 --- a/vendor/linesweeper/src/lib.rs +++ b/vendor/linesweeper/src/lib.rs @@ -396,6 +396,7 @@ mod tests { (1.5e8, 1e-10), (1.5e8, 0.0), (0.0, f64::NEG_INFINITY), + (0.0, f64::INFINITY), ] { let (a, b) = crossing_circles(offset); for correctness in [ diff --git a/vendor/linesweeper/src/segments.rs b/vendor/linesweeper/src/segments.rs index b35c136a2b..aeb7a8509c 100644 --- a/vendor/linesweeper/src/segments.rs +++ b/vendor/linesweeper/src/segments.rs @@ -476,9 +476,9 @@ impl Segments { /// /// Returns `eps` when it is at least `64 * f64::EPSILON` times the largest /// coordinate magnitude (the scale [`crate::binary_op`] uses), and that - /// floor otherwise. The floor replaces an `eps` that is NaN, negative, - /// zero, or too small to tell coordinates of this size apart. It is never - /// below 64 times the spacing of subnormal floats. + /// floor otherwise. The floor replaces an `eps` that is NaN, infinite, + /// negative, zero, or too small to tell coordinates of this size apart. It + /// is never below 64 times the spacing of subnormal floats. pub(crate) fn usable_eps(&self, eps: f64) -> f64 { let max_coord = self .segs @@ -492,7 +492,11 @@ impl Segments { }) .fold(0.0, f64::max); let floor = crate::curve::resolution_floor(max_coord); - if eps >= floor { eps } else { floor } + if eps.is_finite() && eps >= floor { + eps + } else { + floor + } } } diff --git a/vendor/linesweeper/src/sweep/sweep_line.rs b/vendor/linesweeper/src/sweep/sweep_line.rs index c4dbab9715..c2a4667fd5 100644 --- a/vendor/linesweeper/src/sweep/sweep_line.rs +++ b/vendor/linesweeper/src/sweep/sweep_line.rs @@ -360,8 +360,8 @@ impl<'segs> Sweeper<'segs> { /// output orders, but it does emit extra events whenever lines /// touch without crossing. /// - /// An `eps` that is NaN, not positive, or below `64 * f64::EPSILON` times - /// the segments' largest coordinate magnitude is raised to that value. + /// An `eps` that is NaN, infinite, not positive, or below `64 * f64::EPSILON` + /// times the segments' largest coordinate magnitude is replaced by that value. pub fn new_with_correctness( segments: &'segs Segments, eps: f64, diff --git a/vendor/linesweeper/src/topology.rs b/vendor/linesweeper/src/topology.rs index f717bee1b4..164a229d99 100644 --- a/vendor/linesweeper/src/topology.rs +++ b/vendor/linesweeper/src/topology.rs @@ -513,8 +513,8 @@ impl Topology { /// /// See [`WindingNumber`] about the tags are for. /// - /// An `eps` that is NaN, not positive, or below `64 * f64::EPSILON` times - /// the paths' largest coordinate magnitude is raised to that value. The + /// An `eps` that is NaN, infinite, not positive, or below `64 * f64::EPSILON` + /// times the paths' largest coordinate magnitude is replaced by that value. The /// other constructors pass `eps` through here, or follow the same rule. pub fn from_paths_with_correctness<'a, Iter>(paths: Iter, eps: f64, correctness: Correctness) -> Result where