diff --git a/crates/engine/src/cmd/inquiry.rs b/crates/engine/src/cmd/inquiry.rs index f2738342..fce9ac5d 100644 --- a/crates/engine/src/cmd/inquiry.rs +++ b/crates/engine/src/cmd/inquiry.rs @@ -211,8 +211,10 @@ fn object_area(s: &Session, h: Handle) -> Result<(f64, f64)> { Ok(match &e.kind { EntityKind::Circle(c) => (c.radius * c.radius * cadcraft_geom::PI, c.radius * cadcraft_geom::TAU), EntityKind::LwPolyline(pl) => { + // An open polyline is measured as if closed for the area, but its perimeter is its own length (AutoCAD's AREA help). let g = Polyline { vertices: pl.vertices.clone(), closed: true }; - (g.area().abs(), g.len()) + let drawn = Polyline { vertices: pl.vertices.clone(), closed: pl.closed }; + (g.area().abs(), drawn.len()) } EntityKind::Ellipse(el) => { let arc = cadcraft_geom::Ellipse { center: el.center.xy(), major: el.major.xy(), ratio: el.ratio, start: el.start, end: el.end }; diff --git a/crates/engine/tests/inquiry_keywords.rs b/crates/engine/tests/inquiry_keywords.rs index db9330c3..b5abbbd4 100644 --- a/crates/engine/tests/inquiry_keywords.rs +++ b/crates/engine/tests/inquiry_keywords.rs @@ -33,6 +33,13 @@ fn area_object_add_and_subtract_keep_a_running_total() { assert!(s.running.is_none(), "{}", s.prompt_text()); } +#[test] +fn area_object_on_an_open_polyline_closes_the_area_but_not_the_perimeter() { + // Open, 160 long; the closing side back to 0,0 would add 116.619. + let (_, log) = run(&["pline", "0,0", "100,0", "100,60", "", "area", "o", "50,0"]); + assert!(has(&log, "Area = 3000.0000, Perimeter = 160.0000"), "{log:?}"); +} + #[test] fn area_unsupported_keywords_say_so_and_length_extends_the_last_segment() { let (s, log) = run(&["area", "0,0", "a"]);