Merge #676 (fix/linesweeper-decomposition-824-bytes) into integration/linesweeper

This commit is contained in:
dotCooCoo committed 2026-11-09 13:50:46 -08:00
commit 23a7cafebe
3 files changed
+54 -2

No files matched your search

+6
View File
@@ -90,6 +90,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
@@ -214,6 +217,9 @@ Every change here updates this table and `SOURCE.json` in the same commit.
| `src/topology.rs` | `Topology::merge_coincident` compares a segment with its nearest west neighbor that an earlier merge did not delete. Before, it used the west neighbor recorded when the segment was created, so a run of three or more coincident segments merged only in pairs: four copies of one square, two in each direction, left 4 segments and 2 zero-area contours instead of none. The `merge_coincident_runs_longer_than_two` test covers that input and three copies, which leave the square once. |
| `src/topology.rs` | `contours_for_positions` sorts the pieces it splits off a contour walk at a repeated point by the way they wind. A piece that winds like the walked contour becomes its sibling, and a piece that winds the other way becomes a child of the piece that contains it. Before, every piece split off became a child of the walk with the opposite `outer` flag, so of two holes touching at a point, the second came out with `outer = true` and the first hole as its parent, although it winds counter-clockwise. The `holes_touching_at_a_point_are_siblings` test covers it. |
| `src/sweep/sweep_line.rs` | The touch branch of `Sweeper::handle_intersection` runs its scan right from a segment, or left from a segment, at most once per sweep line until the sweep-line order changes. Exact copies of a shape queue a touch event for every pair of coincident segments, and each event used to scan the whole bundle in both directions, so sweeping `n` copies took time growing faster than `n^3`. The skipped scans would only push events already queued, so the output does not change. The `coincident_copies_scan_once_per_order` test counts the scans for 60 copies of two shapes, and `coincident_copies_keep_the_fill` compares the output fill with the input's nonzero fill for 200 inputs with exact, reversed and split copies. |
| `AlmostHorizontalDecomposition` stores up to two pieces inline in a `SmallVec` instead of six in an `ArrayVec`, which takes it from 824 to 288 bytes; `Segments` keeps one for every segment | `Craft patch (inline pieces)` | `src/curve/mod.rs` | `curve::test::horizontal_decomposition_stores_two_pieces_inline`, `curve::test::horizontal_decomposition_keeps_every_piece` |
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:
+2
View File
@@ -45,6 +45,7 @@
"In `src/topology.rs`, `Topology::merge_coincident` compares a segment with its nearest west neighbor that an earlier merge did not delete, so a run of three or more coincident segments merges fully instead of in pairs."
"In `src/topology.rs`, `contours_for_positions` makes a piece split off a contour walk at a repeated point a sibling of the walked contour when it winds the same way and a child of the piece that contains it otherwise, so a hole touching another hole at a point is no longer marked outer with that hole as its parent."
"In `src/sweep/sweep_line.rs`, the touch branch of `Sweeper::handle_intersection` runs each scan from a segment in a direction at most once per sweep line until the sweep-line order changes, so exact copies of a shape no longer rescan the whole coincident bundle for every touch event."
"In `src/curve/mod.rs`, `AlmostHorizontalDecomposition` stores its pieces in a `SmallVec<[CubicParams; 2]>` instead of an `ArrayVec<CubicParams, 6>`, so a decomposition takes 288 bytes instead of 824 and one with more than two pieces goes on the heap. `Segments` keeps one decomposition for every segment, horizontal ones included. For a closed polygon of 200,000 lines, the peak heap of `Topology::from_path` plus `contours` went from 500.9 MB to 360.4 MB with the same contours. `curve::test::horizontal_decomposition_stores_two_pieces_inline` covers the size and `curve::test::horizontal_decomposition_keeps_every_piece` covers decompositions of one, two and five pieces."
],
"files": [
{ "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" },
@@ -85,6 +86,7 @@
{ "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "00ac2cab19a570aefdd2121d621742f113842b9566e7b7718923b337d9c79005" },
{ "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "facf21dbb3a2bb8c2b4f33554f61571482de7f9c4653b6858f21392fcd789b38" },
{ "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "4aa43bcd77267dcd1ba77fa898d5e096b9d47b8ab9eb7bd25ace5a73adbb97ab" },
{ "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "02711a9662e1b5bea412a59cfe420ada1eca0bc685e0d6284c1b03875aa74165" },
{ "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" },
+46 -2
View File
@@ -1426,7 +1426,10 @@ fn intersect_cubics_rec(
/// A decomposition of a cubic Bezier into almost-horizontal and not-almost-horizontal pieces.
#[derive(Clone, Debug, Default)]
pub struct AlmostHorizontalDecomposition {
pieces: ArrayVec<CubicParams, 6>,
// Craft patch (inline pieces): up to two pieces are stored inline and more
// go on the heap. `Segments` stores one decomposition per segment, so this
// size is paid for every segment of the input.
pieces: SmallVec<[CubicParams; 2]>,
}
impl AlmostHorizontalDecomposition {
@@ -1483,7 +1486,7 @@ impl AlmostHorizontalDecomposition {
let mut last_y = c.p0.y;
let mut last_end = 0.0;
let orig_c = c;
let mut ret = ArrayVec::default();
let mut ret: SmallVec<[CubicParams; 2]> = SmallVec::new();
for (_, end, order) in subdivision.iter(0.0) {
let start = last_end;
// If there's no actual subdivision, skip the subsegment operation.
@@ -2005,6 +2008,47 @@ mod test {
);
}
// Craft patch (inline pieces) tests: a decomposition is no larger than two
// inline pieces, and one with more pieces than that keeps all of them.
#[test]
fn horizontal_decomposition_stores_two_pieces_inline() {
assert!(
std::mem::size_of::<AlmostHorizontalDecomposition>()
<= 2 * std::mem::size_of::<CubicParams>() + 2 * std::mem::size_of::<usize>()
);
}
#[test]
fn horizontal_decomposition_keeps_every_piece() {
let cases = [
(
CubicBez::new((0.0, 0.0), (10.0, 10.0), (20.0, 20.0), (30.0, 30.0)),
1,
),
(
CubicBez::new((0.0, 0.0), (10.0, 10.0), (20.0, 20.0), (500.0, 30.0)),
2,
),
(
CubicBez::new((0.0, 0.0), (2000.0, 10.0), (-1000.0, 20.0), (1000.0, 30.0)),
5,
),
(
CubicBez::new((0.0, 0.0), (2000.0, 0.0), (-1000.0, 30.0), (1000.0, 30.0)),
5,
),
];
for (c, count) in cases {
let decomp = AlmostHorizontalDecomposition::from_monotone_cubic(c);
assert_eq!(decomp.pieces.len(), count);
assert_eq!(decomp.pieces[0].c.p0, c.p0);
assert_eq!(decomp.pieces[count - 1].c.p3, c.p3);
for pair in decomp.pieces.windows(2) {
assert_eq!(pair[0].c.p3.y, pair[1].c.p0.y);
}
}
}
// This test recurses a bit too deeply. The two curves are quite close,
// and near the end they're just a bit more than eps apart.
#[test]