mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-24 02:46:51 -06:00
AREA, Object: an open polyline's perimeter is its length, without the closing side (fixes #1168) (#1188)
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -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"]);
|
||||
|
||||
Reference in New Issue
Block a user