Merge pull request #9356 from dotCooCoo/fix/ellipse-three-point-preview-bound

Shape tools: a huge circle through Shift-clicked points is previewed solid
This commit is contained in:
BFlat authored and GitHub committed 2026-11-26 16:48:08 +07:00
commit d8d3abfcbc
3 files changed
+40 -6

No files matched your search

+7 -4
View File
@@ -224,6 +224,12 @@ fn round_diameter(cx: &ToolContext, first: Point, p: Point, mods: Mods, centered
if mods.alt && d > 0.0 && rounded > 0.0 && rounded.is_finite() { first + (p - first) * (rounded / d) } else { p }
}
/// Whether a circle preview of radius `r` is drawn dashed. The canvas draws a dashed outline dash by
/// dash along its whole length, so a circle longer than [`DASHED_PX`] on screen is drawn solid.
pub(crate) fn preview_dashed(cx: &ToolContext, r: f64) -> bool {
std::f64::consts::TAU * r <= cx.tol(DASHED_PX)
}
/// Are the points two or more different points through which no circle is drawn: three on one
/// line, or a circle that would reach past the canvas?
fn too_large(points: &[Point], centered: bool, standard_anchors: bool) -> bool {
@@ -573,10 +579,7 @@ impl Tool for CircleTool {
let on_outline = if self.centered { points.get(1..).unwrap_or(&[]) } else { &points[..] };
shapes::circle_with_anchors_at(c, r, on_outline).to_bezpath()
};
// The canvas draws a dashed outline dash by dash along its whole length: a circle longer
// than DASHED_PX on screen is drawn solid instead.
let dashed = std::f64::consts::TAU * r <= cx.tol(DASHED_PX);
o.push(Overlay::Path { path, color, width: 1.0, dashed });
o.push(Overlay::Path { path, color, width: 1.0, dashed: preview_dashed(cx, r) });
let opts = self.options;
let lines = COLORS.get(opts.color).map_or(color, |(_, rgb)| *rgb);
if opts.radii {
+2 -2
View File
@@ -999,7 +999,7 @@ impl Tool for ShapeTool {
let mut o = if tangent.is_some() { self.tangent_line.guides(cx) } else { self.snap.guides().to_vec() };
o.extend(self.guides.iter().cloned());
// The points Shift-clicks placed, and after two of them the circle through them and the
// pointer, dashed.
// pointer, dashed (solid when it is too long on screen, as the Circle tool draws it).
for p in &self.through {
o.push(Overlay::Anchor { p: *p, color: crate::draw2::FEEDBACK, filled: true, size: 6.0 });
}
@@ -1007,7 +1007,7 @@ impl Tool for ShapeTool {
&& let Some((c, r)) = vectorcraft_geom::shapes::circle_through(*a, *b, h)
{
let path = vectorcraft_geom::shapes::ellipse(Rect::new(c.x - r, c.y - r, c.x + r, c.y + r)).to_bezpath();
o.push(Overlay::Path { path, color: crate::draw2::FEEDBACK, width: 1.0, dashed: true });
o.push(Overlay::Path { path, color: crate::draw2::FEEDBACK, width: 1.0, dashed: crate::circle::preview_dashed(cx, r) });
}
if let Some((p, text)) = &self.measure {
o.push(Overlay::Measure { p: *p, text: text.clone() });
+31
View File
@@ -667,6 +667,37 @@ fn the_circle_preview_passes_through_the_snapped_pointer() {
assert!(matches!(&a[..], [Action::Exec(_, v)] if v["points"][2] == json!([100.0, 100.0])), "{a:?}");
}
/// A circle through the Shift-clicked points more than 50,000 screen points around is previewed
/// solid, as the Circle tool previews it: points nearly on one line give a radius of about
/// 1,250,000 pt.
#[test]
fn a_huge_circle_through_shift_clicked_points_is_previewed_solid() {
let (d, _) = doc_with_rect();
let s = Selection::default();
let p = paint();
let cx = ToolContext { smart_guides: false, ..cx(&d, &s, &p) };
let shift = Mods { shift: true, ..Default::default() };
let mut t = ShapeTool::new("ellipse");
for (x, y) in [(0.0, 0.0), (1000.0, 0.0)] {
t.pointer(&cx, &PointerEvent::new(PointerKind::Down, x, y).with_mods(shift));
t.pointer(&cx, &PointerEvent::new(PointerKind::Up, x, y).with_mods(shift));
}
let paths = |t: &ShapeTool| {
t.overlays(&cx)
.into_iter()
.filter_map(|o| match o {
Overlay::Path { dashed, .. } => Some(dashed),
_ => None,
})
.collect::<Vec<_>>()
};
t.pointer(&cx, &PointerEvent::new(PointerKind::Move, 500.0, 0.1));
assert_eq!(paths(&t), vec![false]);
// At 100% a circle 100 pt across is dashed.
t.pointer(&cx, &PointerEvent::new(PointerKind::Move, 500.0, 300.0));
assert_eq!(paths(&t), vec![true]);
}
/// Escape, a plain click and a drag drop the points Shift-clicks placed, so the next Shift-click
/// starts a new circle.
#[test]