From 128ba86be3c147e28d9dcc98d3e62d6f2a826b94 Mon Sep 17 00:00:00 2001 From: Don Omondi <282319807+mockydevs@users.noreply.github.com> Date: Fri, 13 Nov 2026 03:25:35 -0500 Subject: [PATCH] Twist (#7069): the derivative's step grows with the coordinates so it doesn't round away --- crates/doc/src/live.rs | 24 ++++++++++++++++++++++++ crates/doc/src/live/warp.rs | 8 ++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/crates/doc/src/live.rs b/crates/doc/src/live.rs index 5768d26cac..946f1534c7 100644 --- a/crates/doc/src/live.rs +++ b/crates/doc/src/live.rs @@ -90,6 +90,30 @@ mod tests { } } + /// The smooth map takes each handle along the map's derivative, also far from the origin, + /// where a fixed sampling step would round away (#7069): the identity map keeps a curve's + /// handles there. + #[test] + fn map_smooth_within_keeps_handles_far_from_the_origin() { + for at in [0.0, 1e13] { + let o = Point::new(at, at); + let curve = PathData::single(vectorcraft_geom::SubPath::new( + vec![ + vectorcraft_geom::Anchor::with_handles(o, o, o + vectorcraft_geom::Vec2::new(0.2, 0.0)), + vectorcraft_geom::Anchor::with_handles( + o + vectorcraft_geom::Vec2::new(1.0, 0.5), + o + vectorcraft_geom::Vec2::new(0.8, 0.5), + o + vectorcraft_geom::Vec2::new(1.0, 0.5), + ), + ], + false, + )); + let out = map_smooth_within(&curve, 10.0, usize::MAX, |p| p); + let (a, b) = (&curve.subpaths[0].anchors, &out.subpaths[0].anchors); + assert!(a[0].h_out.distance(b[0].h_out) < 0.01 && a[1].h_in.distance(b[1].h_in) < 0.01, "at {at}: {:?} {:?}", b[0].h_out, b[1].h_in); + } + } + /// #3578: a non-linear map within an anchor budget splits its segments into longer pieces, /// down to one a segment, and matches the plain map where the budget leaves room. #[test] diff --git a/crates/doc/src/live/warp.rs b/crates/doc/src/live/warp.rs index 2f33e670a5..dd48e8ef65 100644 --- a/crates/doc/src/live/warp.rs +++ b/crates/doc/src/live/warp.rs @@ -517,8 +517,12 @@ fn mapped_handle(f: &impl Fn(Point) -> Point, p: Point, h: Point) -> Point { if len.is_nan() || len <= 0.0 || len.is_infinite() { return f(p); } - const STEP: f64 = 1e-3; - let d = (f(p + v * STEP) - f(p - v * STEP)) / (2.0 * STEP); + // A thousandth of the handle, or more where the coordinates are so large that so short a + // step would round away (#7069): the samples stay a billionth of the coordinates apart, and + // at most at the handle's own end. + let size = p.x.abs().max(p.y.abs()).max(1.0); + let step = (1e-3f64).max(size * 1e-9 / len).min(1.0); + let d = (f(p + v * step) - f(p - v * step)) / (2.0 * step); f(p) + d }