POLYGON: a typed radius of zero or less, or a radius point on the centre, is refused and asked again (fixes #720) (#735)

Co-authored-by: Brandon Thomas <echelon@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-10-13 05:05:37 -04:00
1 parent 724c18c6af
commit cc57dff527
2 files changed
+22

No files matched your search

+6
View File
@@ -937,11 +937,17 @@ impl Interactive for PolygonM {
s.last_used.polygon_circumscribed = !ins;
}
(Some(c), Some(ins), Input::Point(p)) => {
if c.near(p, 1e-12) {
return Err(crate::EngineError::Other("Value must be positive and nonzero.".into()));
}
s.add_entity(lwpoly(polygon_vertices(c, n, p, ins), true))?;
return Ok(Step::Done);
}
(Some(c), Some(ins), Input::Text(t)) => {
let r = number(&t).ok_or_else(|| crate::EngineError::Other("Requires numeric distance or point.".into()))?;
if !r.is_finite() || r <= 0.0 {
return Err(crate::EngineError::Other("Value must be positive and nonzero.".into()));
}
let rp = polygon_typed_radius_point(c, n, r, ins);
s.add_entity(lwpoly(polygon_vertices(c, n, rp, ins), true))?;
return Ok(Step::Done);
+16
View File
@@ -107,3 +107,19 @@ fn circle_center_prompt_rejects_garbage() {
s.cmdline("0,0 5").unwrap();
assert!(matches!(last(&s), EntityKind::Circle(c) if (c.radius - 5.0).abs() < 1e-9));
}
#[test]
fn polygon_radius_must_be_positive() {
for input in ["polygon 4 0,0 i 0", "polygon 4 0,0 c 0", "polygon 5 0,0 i -5", "polygon 5 0,0 c -5", "polygon 4 0,0 i 0,0", "polygon 4 0,0 c 0,0"]
{
let mut s = Session::new();
s.cmdline(input).unwrap();
assert_eq!(s.doc().unwrap().model.len(), 0, "{input}: no polygon");
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("2").unwrap();
assert!(s.running.is_none(), "{input}: a positive radius finishes");
assert_eq!(s.doc().unwrap().model.len(), 1, "{input}: one polygon");
assert!(matches!(last(&s), EntityKind::LwPolyline(p) if p.closed), "{input}");
}
}