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..dd287c30f1 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` | `solve_t_for_y` divides every height by 32 before it builds the cubic's coefficients when the largest height or the target has a magnitude above `f64::MAX / 32`. Before, a segment with heights above about `f64::MAX / 3` gave an infinite coefficient, and polycool's critical point search recursed until the process aborted with a stack overflow. `Topology::from_path` reached it on two overlapping rectangles near y = 1e308. The `solve_for_t_near_the_float_limit` test solves straight segments with heights from 5.5e307 up to `f64::MAX`. | `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..eaa177d53c 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`, `solve_t_for_y` divides every height by 32 before it builds the cubic's coefficients when a height or the target has a magnitude above `f64::MAX / 32`, so a segment with heights above about `f64::MAX / 3` no longer gives an infinite coefficient that makes polycool recurse until the stack overflows." + ], "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": "fc5f9ae6a55aa6a94f6bf8cf6b4e6627ef7c502d2ff39440fcd77c78b69280db" }, { "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..9768eadebc 100644 --- a/vendor/linesweeper/src/curve/mod.rs +++ b/vendor/linesweeper/src/curve/mod.rs @@ -390,10 +390,23 @@ pub fn solve_t_for_y(c: CubicBez, y: f64) -> f64 { return 1.0; } - let c3 = c.p3.y - 3.0 * c.p2.y + 3.0 * c.p1.y - c.p0.y; - let c2 = 3.0 * (c.p2.y - 2.0 * c.p1.y + c.p0.y); - let c1 = 3.0 * (c.p1.y - c.p0.y); - let c0 = c.p0.y - y; + // The coefficients below, and the derivative and sums that polycool forms from them, reach + // about 28 times the largest height. Above `f64::MAX / 32` they can overflow to infinity, + // and polycool's critical point search then recurses until the stack overflows. Dividing + // every height by 32 is exact and does not move the root. + let heights = [c.p0.y, c.p1.y, c.p2.y, c.p3.y, y]; + let max_height = heights.iter().fold(0.0f64, |m, h| m.max(h.abs())); + let scale = if max_height > f64::MAX / 32.0 { + 1.0 / 32.0 + } else { + 1.0 + }; + let [p0, p1, p2, p3, target] = heights.map(|h| h * scale); + + let c3 = p3 - 3.0 * p2 + 3.0 * p1 - p0; + let c2 = 3.0 * (p2 - 2.0 * p1 + p0); + let c1 = 3.0 * (p1 - p0); + let c0 = p0 - target; let cubic = Cubic::new([c0, c1, c2, c3]); let eps = 1e-12; @@ -1719,6 +1732,27 @@ mod test { assert!(dbg!(c.eval(t).y - y).abs() < 1e-8); } + #[test] + fn solve_for_t_near_the_float_limit() { + let line = |y0: f64, y1: f64| { + let a = Point::new(0.0, y0); + let b = Point::new(10.0, y1); + CubicBez::new(a, a.lerp(b, 1.0 / 3.0), a.lerp(b, 2.0 / 3.0), b) + }; + + // Without scaling, `3.0 * p1` or `3.0 * p2` overflows to infinity for every line here + // except the one from -8e307 to 8e307, whose coefficients stay finite. + for (y0, y1) in [ + (5.5e307, 6.5e307), + (-6.5e307, -5.5e307), + (-8e307, 8e307), + (f64::MAX / 2.0, f64::MAX), + ] { + let t = solve_t_for_y(line(y0, y1), y0 / 2.0 + y1 / 2.0); + assert!((t - 0.5).abs() < 1e-9, "t = {t} from {y0} to {y1}"); + } + } + #[test] fn solve_for_t_arbtest() { arbtest::arbtest(arbtests::solve_for_t);