mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-14 14:26:45 -04:00
This commit is contained in:
1 parent
483a9304ca
commit
5ce1ea3dfc
2 files changed
+17
No files matched your search
@@ -895,6 +895,9 @@ impl Interactive for PolygonM {
|
||||
let n = self.sides.unwrap_or(4);
|
||||
if self.edge {
|
||||
if let Input::Point(p) = i {
|
||||
if self.edge_pts.first().is_some_and(|a| a.near(p, 1e-12)) {
|
||||
return Err(crate::EngineError::Other("Edge endpoints must differ.".into()));
|
||||
}
|
||||
self.edge_pts.push(p);
|
||||
if self.edge_pts.len() == 2 {
|
||||
s.add_entity(lwpoly(polygon_from_edge(self.edge_pts[0], self.edge_pts[1], n), true))?;
|
||||
|
||||
@@ -65,6 +65,20 @@ fn polygon_typed_radius_has_a_horizontal_bottom_edge() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn polygon_edge_endpoints_must_differ() {
|
||||
let mut s = Session::new();
|
||||
s.cmdline("polygon 4 e 1,1 1,1").unwrap();
|
||||
assert_eq!(s.doc().unwrap().model.len(), 0, "no polygon");
|
||||
assert!(logged(&s, "Edge endpoints must differ."), "{:?}", s.log);
|
||||
assert!(s.running.is_some(), "still at the second endpoint prompt");
|
||||
s.cmdline("3,1").unwrap();
|
||||
assert!(s.running.is_none(), "a distinct endpoint finishes");
|
||||
let EntityKind::LwPolyline(p) = last(&s) else { panic!("no polygon") };
|
||||
assert!(p.closed && p.vertices.len() == 4);
|
||||
assert!(p.vertices.iter().any(|v| v.p.near(Vec2::new(3.0, 1.0), 1e-9)), "the edge runs from 1,1 to 3,1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn circle_center_prompt_rejects_garbage() {
|
||||
let mut s = Session::new();
|
||||
|
||||
Reference in new issue
Block a user