mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-09 03:51:42 +00:00
Geom: the bounded-sizes test also covers the cap itself, NaN, infinities and negative sizes
Review follow-up on #1774. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
8e6a04baf6
commit
33f32c1166
1 file changed
+15
-1
@@ -59,7 +59,8 @@ fn absurd_sizes_build_bounded_paths() {
|
||||
// kurbo subdivides an arc in proportion to the sixth root of its radius, so without a cap the
|
||||
// segment count grows without bound with the input: a 1e36 ellipse was about a million
|
||||
// elements and 1e60 never returned. Sizes are untrusted (files, commands), so they are capped.
|
||||
for mag in [1e36, 1e300, f64::MAX] {
|
||||
// At the cap itself (1e9) an arc is still a few dozen segments.
|
||||
for mag in [MAX_COORD, 1e36, 1e300, f64::MAX] {
|
||||
let paths = [
|
||||
("ellipse", ellipse(mag, mag, 0.0, PI, 0.0)),
|
||||
("ring", ellipse(mag, mag, 0.0, TAU, 0.5)),
|
||||
@@ -76,6 +77,19 @@ fn absurd_sizes_build_bounded_paths() {
|
||||
let p = smoothed_polygon(&[Point::new(0.0, 0.0), Point::new(mag, 0.0), Point::new(mag, mag)], mag, 0.6);
|
||||
assert!(p.elements().len() < 1_000, "huge points at {mag:e}: {} elements", p.elements().len());
|
||||
}
|
||||
// NaN, infinities and negative sizes build nothing or a bounded path with a finite box.
|
||||
for v in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, -1e36, -1.0] {
|
||||
let paths = [
|
||||
("ellipse", ellipse(v, v, v, v, v)),
|
||||
("rounded_rect", rounded_rect(v, v, [v; 4], v)),
|
||||
("smoothed_polygon", smoothed_polygon(&polygon_points(100.0, 100.0, 5), v, v)),
|
||||
];
|
||||
for (name, p) in paths {
|
||||
assert!(p.elements().len() < 1_000, "{name} at {v}: {} elements", p.elements().len());
|
||||
let b = p.bounding_box();
|
||||
assert!([b.x0, b.y0, b.x1, b.y1].iter().all(|x| x.is_finite()), "{name} at {v}: {b:?}");
|
||||
}
|
||||
}
|
||||
// Sizes a document can hold are untouched.
|
||||
let p = rounded_rect(1e6, 1e6, [1e5; 4], 0.6);
|
||||
let b = p.bounding_box();
|
||||
|
||||
Reference in new issue
Block a user