CIRCLE: a radius point on the centre is refused and asked again (follow-up to #735) (#761)

This commit is contained in:
Marco Arnulfo
2026-10-13 04:34:25 -04:00
committed by GitHub
parent 5ce1ea3dfc
commit f5d58913cc
2 changed files with 22 additions and 0 deletions
+3
View File
@@ -780,6 +780,9 @@ impl Interactive for CircleM {
Ok(Step::Continue)
}
Input::Point(p) => {
if self.mode == 0 && self.pts.first().is_some_and(|c| c.near(p, 1e-12)) {
return Err(crate::EngineError::Other("Value must be positive and nonzero.".into()));
}
self.pts.push(p);
let done = match self.mode {
0 if self.pts.len() == 2 => {
+19
View File
@@ -44,6 +44,25 @@ fn spline_rejects_text_and_switches_method() {
assert!(sp.fit.is_empty() && sp.control.len() == 4);
}
#[test]
fn circle_radius_point_on_the_centre_is_refused() {
for input in ["circle 2,3 2,3", "circle 2,3 d 2,3"] {
let mut s = Session::new();
s.cmdline(input).unwrap();
assert_eq!(s.doc().unwrap().model.len(), 0, "{input}: no circle");
assert!(logged(&s, "Value must be positive and nonzero."), "{input}: {:?}", s.log);
assert!(s.running.is_some(), "{input}: still at the radius prompt");
s.cmdline("4").unwrap();
assert!(s.running.is_none(), "{input}: a positive value finishes");
assert_eq!(s.doc().unwrap().model.len(), 1, "{input}: one circle");
let want = if input.contains(" d ") { 2.0 } else { 4.0 };
assert!(
matches!(last(&s), EntityKind::Circle(c) if c.center.xy().near(Vec2::new(2.0, 3.0), 1e-9) && (c.radius - want).abs() < 1e-9),
"{input}: the centre is kept"
);
}
}
/// The two lowest vertices of a closed polyline share their y (the bottom edge is horizontal).
fn bottom_y(k: &EntityKind) -> Option<f64> {
let EntityKind::LwPolyline(p) = k else { return None };