From bd54c2a63bcafd15c03fa4c0d4dbb13d5250fe64 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 16:37:07 -0800 Subject: [PATCH] Three-Point Arc: measure the arc's curve, not its handles, against the canvas An arc near the canvas edge whose handles reach past it while the curve stays inside showed "Arc too large", though shape.threePointArc draws it. The tool now measures the curve's bounds, as the document's range check does for such a path. --- crates/tools/src/three_point_arc.rs | 5 ++++- crates/tools/src/three_point_arc/tests.rs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/tools/src/three_point_arc.rs b/crates/tools/src/three_point_arc.rs index 2732836dc1..4145c549e7 100644 --- a/crates/tools/src/three_point_arc.rs +++ b/crates/tools/src/three_point_arc.rs @@ -73,7 +73,10 @@ pub fn arc_of(start: Point, end: Point, third: Point, direction: bool, at_end: b (true, false) => CircularArc::leaving(start, third - start, end).map(|arc| (arc, arc.to_path())), (true, true) => CircularArc::arriving(start, end, end - third).map(|arc| (arc, arc.to_path())), }?; - let on_canvas = path.anchors().all(|(_, _, a)| [a.p, a.h_in, a.h_out].iter().all(|q| q.x.abs() <= MAX_COORD && q.y.abs() <= MAX_COORD)); + // The curve is measured, not its handles, which can reach past the canvas while the curve stays + // inside, as the document's own range check measures a path. + let inside = |x: f64, y: f64| x.abs() <= MAX_COORD && y.abs() <= MAX_COORD; + let on_canvas = path.bounds().is_some_and(|r| inside(r.x0, r.y0) && inside(r.x1, r.y1)); on_canvas.then_some((arc, path)) } diff --git a/crates/tools/src/three_point_arc/tests.rs b/crates/tools/src/three_point_arc/tests.rs index 2481de1bff..70f1f51e69 100644 --- a/crates/tools/src/three_point_arc/tests.rs +++ b/crates/tools/src/three_point_arc/tests.rs @@ -115,6 +115,25 @@ fn a_third_point_in_line_with_the_ends_draws_nothing() { assert_eq!(click(&mut t, &cx, (340.0, 340.0)), through((300.0, 300.0), (380.0, 300.0), (340.0, 340.0))); } +/// An arc near the canvas edge fits while its curve stays inside, even where a handle reaches past +/// the edge, and gives no arc once the curve reaches past it. +#[test] +fn an_arc_near_the_canvas_edge_is_measured_by_its_curve() { + // A 60° arc of radius 1000 whose rightmost point is `edge`: the handles at its ends reach about + // 45 pt further right. + let arc = |edge: f64| { + let (r, c) = (1000.0, edge - 1000.0); + let (dx, dy) = (r * 30f64.to_radians().cos(), r * 30f64.to_radians().sin()); + let start = Point::new(c + dx, -dy); + let end = Point::new(c + dx, dy); + arc_of(start, end, start + Vec2::new(0.5, 3f64.sqrt() / 2.0) * 100.0, true, false) + }; + let Some((_, path)) = arc(MAX_COORD - 1.0) else { panic!("an arc inside the canvas fits") }; + assert!(path.control_bounds().is_some_and(|r| r.x1 > MAX_COORD), "a handle reaches past the edge"); + assert!(path.bounds().is_some_and(|r| r.x1 <= MAX_COORD && (r.x1 - (MAX_COORD - 1.0)).abs() < 1e-6)); + assert!(arc(MAX_COORD + 1.0).is_none(), "an arc reaching past the canvas does not fit"); +} + /// In direction mode, Shift keeps the direction line at 45° steps from the end it starts at. #[test] fn shift_keeps_the_direction_at_45_degree_steps() {