Merge #692 (fix/linesweeper-add-bez-path-error-state) into integration/linesweeper

This commit is contained in:
dotCooCoo committed 2026-11-09 13:58:48 -08:00
commit 0085e4538b
5 files changed
+53 -1

No files matched your search

+3
View File
@@ -304,6 +304,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
+6
View File
@@ -105,6 +105,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
@@ -279,6 +282,9 @@ Every change here updates this table and `SOURCE.json` in the same commit.
| `src/lib.rs`, `src/order.rs`, `src/sweep/sweep_line.rs`, `src/topology.rs` | `ComparisonCache` counts its calls, so `Sweeper` counts its segment comparisons, and `Sweeper` also counts the segment positions it checks against horizontal segments and contour endpoints while finding a sweep line's changed intervals, and one unit for every 16 segments that linear searches of the sweep line step over. `Sweeper::set_work_limit` sets the most work it may do; past it, `Sweeper::next_line` returns `None`, also between the enter, exit and intersection events of one sweep line and between the comparisons and position checks that find its changed intervals, never returns a sweep line past the limit, and keeps returning `None` if the limit is raised; `Sweeper::work_limit_exceeded` returns `true`. `Topology::from_paths_with_work_limit` returns the new `Error::WorkLimitExceeded` when its sweep passes the limit. The sweep had no limit: the union of 400 identical circles made 1.36 billion comparisons in 19 sweep lines and took 66 to 83 s and 1.3 GB in a release build. `Topology::from_paths` and the other constructors set no limit. The `work_limit` and `work_limit_stops_within_a_sweep_line` tests sweep 20 stacked circles with a limit of 1,000 comparisons, and `work_limit_returns_no_line_past_the_limit` sweeps 3 stacked circles with every limit below the sweep's total. `work_limit_counts_the_horizontal_scans` sweeps 150 bars crossed by the top and bottom edges of 30 wide rectangles, where the sweep makes 1,462 comparisons but checks at least 18,000 positions, and stops it at half its total work. `work_limit_counts_linear_searches` sweeps 2,000 disjoint rectangles sharing their top and bottom heights, where each exit searches the whole sweep line, and stops it at half its total work. |
| `src/topology.rs` | `Topology::can_merge` merges two output segments only when the neighbor at the shared point is the adjacent piece of the same input segment. Before, after coincident segments were deleted, a piece of one input curve could be merged with a piece of another, and the output rebuilt a sub-curve from the wrong curve's parameters: two arches whose right legs agree to within about 1e-6 (area about 0.00096) gave a contour of area 900 at eps 1e-6, and a path followed by its own reverse panicked in `segs_to_path`. `segs_to_path` also starts at the first segment instead of panicking when every segment looks mergeable. The `merge_only_pieces_of_one_input_curve` and `path_followed_by_its_reverse` tests cover both inputs. |
| `src/topology.rs` | With `Correctness::GoodEnough`, `Topology::contours` builds paths only for the output segments on the boundary of the result instead of for every output segment, which it then did not read. The contours it returns are unchanged. The `contour_positions_cover_only_boundary_segments` and `contours_match_contours_from_all_positions` tests cover the change. |
| `Segments::add_bez_path` leaves the arena unchanged when a subpath is not closed, instead of keeping the segments it pushed before the open subpath, the last of them linked to an index past the end of the arena | `Craft patch (add_bez_path error)` | `src/segments.rs`, `src/lib.rs` | `tests::add_bez_path_error_leaves_segments_unchanged` |
Every change here updates this table and `SOURCE.json` in the same commit.
`omitted_files` lists the 43 files of the package left out here, with their hashes:
+4
View File
@@ -58,6 +58,7 @@
"In `src/sweep/sweep_line.rs`, `src/order.rs`, `src/topology.rs` and `src/lib.rs`, `Sweeper` counts its segment comparisons and the segment positions it checks against horizontal segments and contour endpoints, and one unit per 16 segments that linear searches of the sweep line step over, and `Sweeper::set_work_limit` stops the sweep, between the events of one sweep line and between the comparisons and position checks that find its changed intervals too, once it passes the limit, so no sweep line comes back past the limit; `Topology::from_paths_with_work_limit` then returns the new `Error::WorkLimitExceeded`, so stacked or nearly coincident shapes no longer sweep for minutes with no way to stop them."
"In `src/topology.rs`, `Topology::can_merge` merges two output segments only when the neighbor at the shared point is the adjacent piece of the same input segment, so pieces of different input curves are no longer merged, and `segs_to_path` starts at the first segment instead of panicking when every segment looks mergeable."
"In `src/topology.rs`, `Topology::contours` with `Correctness::GoodEnough` builds paths only for the output segments on the boundary of the result, not for every output segment."
"In `src/segments.rs`, `Segments::add_bez_path` removes the segments it pushed when a subpath is not closed. Without it, adding `M0,0 L10,0 L5,10 Z M20,0 L30,5 L25,10` returns `NonClosedPath` but keeps five segments with no entrances, the last linked to index 5 of a 5-segment arena: `check_invariants` panics with an index out of bounds, and after a closed square is added the open piece is linked into the square and the sweep visits only the square's 4 of 9 segments. With it, the arena is unchanged after the error and the square's 4 segments are all entered. The test `tests::add_bez_path_error_leaves_segments_unchanged` in `src/lib.rs` covers it."
],
"files": [
{ "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" },
@@ -116,6 +117,8 @@
{ "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/geom.rs", "source_sha256": "9878ffa6d4a13fa2c9149741c137205ca01acb626a5b9f86a3db75cf91b63a08", "source_git_blob": null, "sha256": "9878ffa6d4a13fa2c9149741c137205ca01acb626a5b9f86a3db75cf91b63a08" },
{ "path": "src/lib.rs", "source_sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6", "source_git_blob": null, "sha256": "e71cce5fb386773e9e08372a76001511de4080b999e78525a0f768cd6e543fa1" },
{ "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" },
@@ -131,6 +134,7 @@
{ "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/segments.rs", "source_sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc", "source_git_blob": null, "sha256": "5b3ca2c01ac51b55d950372cad15a5ccb2dfb50a6e568ac94b855f611ae25eea" },
{ "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" },
+18
View File
@@ -357,6 +357,24 @@ mod tests {
Topology::from_path(&path, 0.001).unwrap();
}
// Craft patch (add_bez_path error).
#[test]
fn add_bez_path_error_leaves_segments_unchanged() {
let mut segments = Segments::default();
let open = BezPath::from_svg("M0,0 L10,0 L5,10 Z M20,0 L30,5 L25,10").unwrap();
assert!(segments.add_bez_path(&open).is_err());
assert_eq!(segments.len(), 0);
segments.check_invariants();
let square = BezPath::from_svg("M40,0 L50,0 L50,10 L40,10 Z").unwrap();
segments.add_bez_path(&square).unwrap();
segments.check_invariants();
assert_eq!(segments.len(), 4);
let mut entered: Vec<_> = segments.entrances().iter().map(|(_, idx)| *idx).collect();
entered.sort();
assert_eq!(entered, segments.indices().collect::<Vec<_>>());
}
#[test]
fn empty_paths() {
let contours = binary_op(
+22 -1
View File
@@ -311,9 +311,17 @@ impl Segments {
/// Add a Bézier path to this arena.
///
/// The path can contain multiple subpaths, and each of them must be closed.
/// If one of them is not closed, this returns an error and leaves the arena
/// unchanged.
pub fn add_bez_path(&mut self, p: &BezPath) -> Result<(), NonClosedPath> {
let old_len = self.segs.len();
self.add_path_without_updating_enter_exit(p, true)?;
// Craft patch (add_bez_path error): segments pushed before the open
// subpath was found are removed, so no segment is left with a link
// past the end of the arena or without an entrance.
if let Err(e) = self.add_path_without_updating_enter_exit(p, true) {
self.truncate(old_len);
return Err(e);
}
self.update_enter_exit(old_len);
Ok(())
}
@@ -420,6 +428,19 @@ impl Segments {
self.segs.push(seg);
}
// Craft patch (add_bez_path error): drops every segment at index `len` or
// above. `enter` and `exit` are left alone, so this is only for segments
// that `update_enter_exit` has not seen yet.
fn truncate(&mut self, len: usize) {
self.segs.inner.truncate(len);
self.horizontal_decomps.inner.truncate(len);
self.contour_prev.inner.truncate(len);
self.contour_next.inner.truncate(len);
self.orientation.inner.truncate(len);
self.split_from_predecessor.inner.truncate(len);
self.input_segs.inner.truncate(len);
}
/// Construct a segment arena from a single closed polyline.
pub fn from_closed_polyline<P: Into<Point>>(ps: impl IntoIterator<Item = P>) -> Self {
let mut ret = Self::default();