Merge #672 (fix/linesweeper-closepath-first-panic) into integration/linesweeper

This commit is contained in:
dotCooCoo committed 2026-11-09 13:49:08 -08:00
commit 623a585f26
5 files changed
+68 -2

No files matched your search

+3
View File
@@ -265,6 +265,9 @@ vendor/linesweeper/README.craft.md and vendor/linesweeper/SOURCE.json for proven
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, the local
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, the local
change and the files left out.
Platform lifecycle source provenance
+4
View File
@@ -87,6 +87,9 @@ names, which is archived; its README says development moved off GitHub.
`824b0791a750f7b27b8edcbb6c6244d0e629875e`. That commit is not in the GitHub repository the manifest
names, which is archived; its README says development moved off GitHub.
`824b0791a750f7b27b8edcbb6c6244d0e629875e`. That commit is not in the GitHub repository the manifest
names, which is archived; its README says development moved off GitHub.
Every file here except this one, `SOURCE.json` and the files under Local changes is byte for byte the
file in the `.crate` archive. `SOURCE.json` records the hash of the `.crate` download
(`source_archive_sha256`) and, for every file kept, the hash in the package (`source_sha256`) and the
@@ -193,6 +196,7 @@ and, for every file kept, the hash in the package (`source_sha256`) and the hash
| `src/lib.rs`, `src/topology.rs` | `Topology::from_paths`, `from_paths_with_correctness`, `from_path` and `from_paths_binary` return `Error` instead of `NonClosedPath`, and return `Error::NaN`, `Error::Infinity` or the new `Error::TooLarge` when a path has a coordinate that is not finite or has a magnitude above `MAX_COORDINATE` (`f64::MAX / 16`). `binary_op` returns `Error::TooLarge` through `from_paths_binary`. Before, both panicked on a cubic with a coordinate above about `f64::MAX / 3`. A release build panicked in `f64::clamp` with "min > max, or either was NaN", and a debug build failed the `y.is_finite()` assertion in `Point::new`. The `coordinates_above_max_coordinate` test covers 6e307, 7e307 and 1.7e308. |
| `src/topology.rs` | `Contours::grouped` walks each containment tree with an explicit stack instead of one recursive call per nesting level, and returns the contours in the same order. Before, contours nested about 10,000 deep overflowed a 1 MiB stack, which aborts the process. The `grouped_*` tests cover the order and a 30,000-deep nesting on a 256 KiB stack. |
| `AlmostHorizontalDecomposition::from_monotone_cubic` keeps each piece's handles on the right side of its end points instead of clamping them into the piece's y-range, so the pieces the sweep compares follow the input curve | `Craft patch (monotone handles)` | `src/curve/mod.rs` | `curve::test::decomposition_keeps_handles_outside_the_y_range` |
| `Topology::from_path`, the other `Topology` constructors that take Bézier paths, `Segments::add_bez_path` and `binary_op` skip a `ClosePath` that comes before the first point of a path instead of panicking with "Can't start a segment on a ClosePath" | `Craft patch (leading ClosePath)` | `src/segments.rs`, `src/lib.rs` | `tests::leading_close_path` |
Every change here updates this table and `SOURCE.json` in the same commit.
+4
View File
@@ -41,6 +41,7 @@
"In `src/lib.rs` and `src/topology.rs`, the `Topology` constructors that take Bézier paths return `Error` instead of `NonClosedPath`, and return `Error::NaN`, `Error::Infinity` or the new `Error::TooLarge` for a coordinate that is not finite or has a magnitude above `MAX_COORDINATE` (`f64::MAX / 16`), so `Topology::from_path` and `binary_op` no longer panic on cubics with coordinates above about `f64::MAX / 3`."
"In `src/topology.rs`, `Contours::grouped` walks each containment tree with an explicit stack instead of one recursive call per nesting level, so deeply nested contours no longer overflow the stack. The order of the returned contours is unchanged."
"In `src/curve/mod.rs`, `AlmostHorizontalDecomposition::from_monotone_cubic` keeps `p1.y` at least `p0.y` and `p2.y` at most `p3.y` for each piece, instead of clamping both into the piece's y-range. A y-monotone cubic can have handles outside that range, and the clamp moved the curve the sweep compares: for `M0,5 C5,0 2,0 1,1 C0,2 4,0 5,5 Z` at eps 1e-6, `Topology::from_path(..).contours(|w| *w != 0)` gave an outline of area 11.0108 instead of 10.9122, with a horizontal cut at y = 1.97218 that lies 0.2588 from the input. `curve::test::decomposition_keeps_handles_outside_the_y_range` covers the shape and its mirror image in y."
"In `src/segments.rs` and `src/lib.rs`, a `ClosePath` that comes before the first point of a path is skipped. Without it, a `BezPath` deserialized from `[ClosePath]` or `[ClosePath, MoveTo, LineTo, LineTo, ClosePath]` makes `Topology::from_path` and `binary_op` panic in kurbo with \"Can't start a segment on a ClosePath\". With it, `[ClosePath]` gives no contours and the second path gives the same contours as the path without its leading `ClosePath`. The test `tests::leading_close_path` covers it."
],
"files": [
{ "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" },
@@ -90,6 +91,8 @@
{ "path": "src/lib.rs", "source_sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6", "source_git_blob": null, "sha256": "e690f4ac214403c97b37b8dafce322630c90622837cbe6172e878e1c0b15112c" },
{ "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": "83ecdd22cf9f01ffc1bfa3ee70866cbf34963e3de5e5cdd0fbe1877398c14dc9" },
{ "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": "c7b8f90ca37f5125ec56d1f3be827adcab2fe1cf8d0f8341add17903837df087" },
{ "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": "8d2393e43000543c4ac3d47c2615e16733106af78ac67708ebf6941a039b9cdc" },
{ "path": "src/order.rs", "source_sha256": "7e5b04eae8af134abb032e995f1d3c2ac473822923dfee8d463d9ade6ffeb596", "source_git_blob": null, "sha256": "2cce12b9110a5812ce0da81088122d4d64e8852d41bad9139bd29ff9d4363a0f" },
@@ -100,6 +103,7 @@
{ "path": "src/position.rs", "source_sha256": "dfa70840805ecccf5b7eb6122921e46ca60c24cb7b3c17f3b55ffc2549368ab0", "source_git_blob": null, "sha256": "37686f512c4f4ded9fcbd19e8a736f1462ad2e883a65d88d32a7c441d512dc30" },
{ "path": "src/segments.rs", "source_sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc", "source_git_blob": null, "sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc" },
{ "path": "src/segments.rs", "source_sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc", "source_git_blob": null, "sha256": "33997b8afe11f5b3d1846b69db4533af7242121176ba7dff3b7525799a4e17e1" },
{ "path": "src/segments.rs", "source_sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc", "source_git_blob": null, "sha256": "74478b647c0243a18bf0e34af28735544754b42445910cd4145aa1c31826d24d" },
{ "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" },
+47 -1
View File
@@ -145,7 +145,18 @@ pub fn binary_op(
op: BinaryOp,
) -> Result<topology::Contours, Error> {
// Find the extremal values, to figure out how much precision we can support.
let bbox = set_a.bounding_box().union(set_b.bounding_box());
// Craft patch (leading ClosePath): `BezPath::bounding_box` panics on a leading ClosePath.
let bounding_box = |path: &kurbo::BezPath| {
if matches!(path.elements().first(), Some(kurbo::PathEl::ClosePath)) {
kurbo::segments(segments::skip_leading_close_paths(path.iter()))
.map(|seg| kurbo::ParamCurveExtrema::bounding_box(&seg))
.reduce(|a, b| a.union(b))
.unwrap_or_default()
} else {
path.bounding_box()
}
};
let bbox = bounding_box(set_a).union(bounding_box(set_b));
let min = bbox.min_x().min(bbox.min_y());
let max = bbox.max_x().max(bbox.max_y());
if min.is_infinite() || max.is_infinite() {
@@ -243,6 +254,41 @@ mod tests {
insta::assert_ron_snapshot!(output);
}
// Craft patch (leading ClosePath).
#[test]
fn leading_close_path() {
// `BezPath`'s own constructors reject these, but deserializing does not.
let close_only: BezPath = serde_json::from_str(r#"["ClosePath"]"#).unwrap();
let triangle = r#"{"MoveTo":{"x":0.0,"y":0.0}},{"LineTo":{"x":10.0,"y":0.0}},{"LineTo":{"x":0.0,"y":10.0}},"ClosePath""#;
let plain: BezPath = serde_json::from_str(&format!("[{triangle}]")).unwrap();
let leading: BezPath =
serde_json::from_str(&format!(r#"["ClosePath",{triangle}]"#)).unwrap();
let empty = Topology::<i32>::from_path(&close_only, 1e-6).unwrap();
assert_eq!(empty.contours(|w| *w != 0).contours().count(), 0);
let expected = Topology::<i32>::from_path(&plain, 1e-6)
.unwrap()
.contours(|w| *w != 0);
let actual = Topology::<i32>::from_path(&leading, 1e-6)
.unwrap()
.contours(|w| *w != 0);
let paths =
|c: &topology::Contours| c.contours().map(|c| c.path.clone()).collect::<Vec<_>>();
assert_eq!(paths(&actual), paths(&expected));
assert_eq!(paths(&actual).len(), 1);
for (a, b) in [
(&close_only, &plain),
(&plain, &close_only),
(&leading, &plain),
(&plain, &leading),
] {
let output = binary_op(a, b, FillRule::NonZero, BinaryOp::Union).unwrap();
assert_eq!(output.contours().count(), 1);
}
}
// This example has a union of two not-quite-axis-aligned crosses. It
// suffers from some extra quadratic segments near the intersection points,
// but it used to be worse.
+10 -1
View File
@@ -131,6 +131,15 @@ fn pairs<T>(xs: &[T]) -> impl Iterator<Item = (&T, &T)> {
xs.windows(2).map(|pair| (&pair[0], &pair[1]))
}
// Craft patch (leading ClosePath): `kurbo::segments` panics on a ClosePath that comes before
// any point, so such ClosePaths are dropped first. They draw nothing.
pub(crate) fn skip_leading_close_paths(
path: impl IntoIterator<Item = kurbo::PathEl>,
) -> impl Iterator<Item = kurbo::PathEl> {
path.into_iter()
.skip_while(|el| matches!(el, kurbo::PathEl::ClosePath))
}
struct SubpathIter<'a, I: Iterator> {
inner: &'a mut Peekable<I>,
started: bool,
@@ -329,7 +338,7 @@ impl Segments {
};
while let Some(subpath) = subpaths.next() {
let old_len = self.segs.len();
for seg in kurbo::segments(subpath) {
for seg in kurbo::segments(skip_leading_close_paths(subpath)) {
let pieces = monotonic_pieces(seg);
for monotonic in pieces {
self.push_seg(monotonic.piece);