mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 02:36:54 +01:00
Merge #695 (fix/linesweeper-next-touch-after-skip) into integration/linesweeper
This commit is contained in:
commit
331dcf7e04
4 files changed
+81
-25
No files matched your search
@@ -313,6 +313,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
|
||||
|
||||
Vendored
+5
@@ -232,6 +232,10 @@ local patches listed below. `.cargo_vcs_info.json` names the commit it was packa
|
||||
`824b0791a750f7b27b8edcbb6c6244d0e629875e`. That commit is not in the GitHub repository the manifest
|
||||
names, which is archived; its README says development moved off GitHub.
|
||||
|
||||
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, `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
|
||||
@@ -295,6 +299,7 @@ Every change here updates this table and `SOURCE.json` in the same commit.
|
||||
Every change here updates this table and `SOURCE.json` in the same commit.
|
||||
| `src/topology.rs` | `contours_for_positions` finds the nearest boundary segment west of each new contour through `Topology::west_boundary`, which remembers the answer for every segment it passes, so each link of a scan-west chain is followed once per call. A segment's boundary test runs the first time the walk asks for it, and its result is kept. Before, every contour walked its whole chain again, and `n` bars of one set west of `m` squares of the other with the test "first set and not second" called `inside` about `4nm` times: 1,024,240,000 calls for `n = m = 16,000`. The contours do not change. The `contour_starts_follow_each_west_chain_once` test counts the calls to `inside` for 200 bars and 200 squares, and `contour_starts_find_the_boundary_past_non_boundary_segments` checks the parents of squares whose chains pass non-boundary segments. `contours_of_one_polygon_test_the_boundary_only_where_needed` counts the calls to `inside` for one polygon with 1,000 edges. |
|
||||
| `src/curve/mod.rs` | `solve_t_for_y` asks the root finder for `t` to the precision of f64 (`x_error` 0) instead of to within 1e-12. The x error of a `t` that is off by 1e-12 grows with the coordinates: on a curve 1e9 tall it reached 166 times `64 * f64::EPSILON * 1e9`, and pieces that `y_subsegment` cut from curves near 3e7 tall moved by tens of tolerances. Comparing two near-parallel curves of that size recursed down to y intervals shorter than the tolerance: 950,130 entries and 9 s for a pair 3e7 tall, minutes for a pair 1e8 tall. The `solve_x_for_y_on_tall_curve` test checks x on a curve 1e9 tall against a bisection, and the `near_parallel_tall_curves` test compares two curves 2e7 tall, 1.2 tolerances apart, and allows at most 64 entries. |
|
||||
| `src/curve/mod.rs` | `CurveOrder::next_touch_after(y)` walks the order once and compares each touch with `y`. Before, when `y` was inside a touch followed by a Left interval and another touch, it called itself with the end of the Left interval, which is where the next touch starts, so it skipped that touch too and returned `None`. Two curves that start at one point and touch again later gave no later touch at the start height. The `next_touch_after_a_touch_that_contains_y` and `next_touch_after_on_two_curves_that_start_together` tests cover a built order and two curves from `intersect_cubics`. |
|
||||
|
||||
`omitted_files` lists the 43 files of the package left out here, with their hashes:
|
||||
|
||||
|
||||
Vendored
+2
@@ -61,6 +61,7 @@
|
||||
"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."
|
||||
"In `src/topology.rs`, `contours_for_positions` finds the nearest boundary segment west of each new contour through `Topology::west_boundary`, which remembers the answer for every segment it passes, so each link of a scan-west chain is followed once per call instead of once per contour. Each segment's boundary test runs at most once, when the walk first asks for it."
|
||||
"In `src/curve/mod.rs`, `solve_t_for_y` asks for `t` to the precision of f64 instead of to within 1e-12, so comparing near-parallel curves with coordinates near 3e7 or larger no longer recurses into millions of entries."
|
||||
"In `src/curve/mod.rs`, `CurveOrder::next_touch_after(y)` walks the order once and compares each touch with `y`, so a touch that follows a touch containing `y` and a Left interval is no longer skipped, which made it return `None`."
|
||||
],
|
||||
"files": [
|
||||
{ "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" },
|
||||
@@ -109,6 +110,7 @@
|
||||
{ "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "ad8eee65561fdfd32892348a0710717bca54e736a364ddd3587f09694cb69c10" },
|
||||
{ "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "36ace9cc769ed06e6aaaf2060828e09394a15adc77fcec25378ff793be4135d8" },
|
||||
{ "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "f992312ad44b74336a18c992cbabff0bb8a42bd759bc4bee778586b44f2dfe1d" },
|
||||
{ "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "7bbc99e120d3af0af93df9b6f2fde4da7b5075fef7588f8bf3c4807c007e9d76" },
|
||||
{ "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" },
|
||||
|
||||
Vendored
+71
-25
@@ -221,33 +221,36 @@ impl CurveOrder {
|
||||
&self,
|
||||
y: f64,
|
||||
) -> Option<CurveInteraction> {
|
||||
let mut iter = self
|
||||
.iter()
|
||||
.skip_while(|(_start, end, _order)| end <= &y)
|
||||
.skip_while(|(_start, _end, order)| *order == Order::Left);
|
||||
let mut iter = self.iter().skip_while(|(_start, end, _order)| end <= &y);
|
||||
// The height that a crossing found right away is reported at.
|
||||
let mut from = y;
|
||||
|
||||
let (y0, y1, order) = iter.next()?;
|
||||
if order == Order::Right {
|
||||
return Some(CurveInteraction::Cross(y, y));
|
||||
}
|
||||
|
||||
let Some((_, next_y1, next_order)) = iter.next() else {
|
||||
return Some(CurveInteraction::Touch(y0, y1));
|
||||
};
|
||||
|
||||
match next_order {
|
||||
Order::Right => Some(CurveInteraction::Cross(y0, y1)),
|
||||
Order::Left => {
|
||||
if y < y0 {
|
||||
Some(CurveInteraction::Touch(y0, y1))
|
||||
} else {
|
||||
self.next_touch_after(next_y1)
|
||||
}
|
||||
loop {
|
||||
let (y0, y1, order) = iter.find(|(_start, _end, order)| *order != Order::Left)?;
|
||||
if order == Order::Right {
|
||||
return Some(CurveInteraction::Cross(from, from));
|
||||
}
|
||||
Order::Ish => {
|
||||
// The current order is Ish and adjacent orders get merged,
|
||||
// so the next one isn't Ish.
|
||||
unreachable!();
|
||||
|
||||
let Some((_, next_y1, next_order)) = iter.next() else {
|
||||
return Some(CurveInteraction::Touch(y0, y1));
|
||||
};
|
||||
|
||||
match next_order {
|
||||
Order::Right => return Some(CurveInteraction::Cross(y0, y1)),
|
||||
Order::Left => {
|
||||
if y < y0 {
|
||||
return Some(CurveInteraction::Touch(y0, y1));
|
||||
}
|
||||
// `y` is inside this Ish interval, so look for the next
|
||||
// one. It starts after `y`, so it is compared with `y`
|
||||
// and not with the end of the Left interval before it.
|
||||
from = next_y1;
|
||||
}
|
||||
Order::Ish => {
|
||||
// The current order is Ish and adjacent orders get merged,
|
||||
// so the next one isn't Ish.
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2104,6 +2107,49 @@ mod test {
|
||||
assert!(compared > 3000, "{compared} generated comparisons");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_touch_after_a_touch_that_contains_y() {
|
||||
let mut cmp = CurveOrder::new(0.0);
|
||||
for (end, order) in [
|
||||
(1.0, Order::Ish),
|
||||
(2.0, Order::Left),
|
||||
(3.0, Order::Ish),
|
||||
(4.0, Order::Left),
|
||||
] {
|
||||
cmp.push(end, order, MetricsStatus::default());
|
||||
}
|
||||
|
||||
let touch = |y: f64| match cmp.next_touch_after(y) {
|
||||
Some(CurveInteraction::Touch(y0, y1)) => (y0, y1),
|
||||
other => panic!("expected a touch after {y}, got {other:?}"),
|
||||
};
|
||||
// `y` inside the first touch or after it: the next one is the touch
|
||||
// from 2 to 3.
|
||||
assert_eq!(touch(0.0), (2.0, 3.0));
|
||||
assert_eq!(touch(0.5), (2.0, 3.0));
|
||||
assert_eq!(touch(1.5), (2.0, 3.0));
|
||||
// `y` inside the second touch, with no touch after it.
|
||||
assert!(cmp.next_touch_after(2.5).is_none());
|
||||
assert!(cmp.next_touch_after(4.0).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_touch_after_on_two_curves_that_start_together() {
|
||||
// The cubic starts on the line, moves left of it and comes back to
|
||||
// touch it again near y = 2.4.
|
||||
let a = CubicBez::new((0.0, 0.0), (-1.2, 4.0 / 3.0), (1.6, 8.0 / 3.0), (-1.6, 4.0));
|
||||
let b = CubicBez::new((0.0, 0.0), (0.0, 4.0 / 3.0), (0.0, 8.0 / 3.0), (0.0, 4.0));
|
||||
let cmp = intersect_cubics(a, b, 1e-3, 0.02);
|
||||
let orders: Vec<_> = cmp.iter().map(|(_, _, order)| order).collect();
|
||||
assert_eq!(orders, [Order::Ish, Order::Left, Order::Ish, Order::Left]);
|
||||
|
||||
let (touch_y0, touch_y1, _) = cmp.iter().nth(2).unwrap();
|
||||
match cmp.next_touch_after(0.0) {
|
||||
Some(CurveInteraction::Touch(y0, y1)) => assert_eq!((y0, y1), (touch_y0, touch_y1)),
|
||||
other => panic!("expected the second touch, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quad_approximation() {
|
||||
let c = CubicBez {
|
||||
|
||||
Reference in new issue
Block a user