Save a dimangular made from two lines as a 2-line angular dimension (#1652) (#1681)

This commit is contained in:
MarekSpodBiedry
2026-10-24 01:48:35 -04:00
committed by GitHub
parent 20b0c9c11a
commit 60265a1eee
2 changed files with 14 additions and 7 deletions
+10 -5
View File
@@ -182,7 +182,7 @@ fn with_assoc(k: EntityKind, assoc: Vec<DimAssoc>) -> EntityKind {
}
}
/// Angular dimension between two lines, attached to them (vertex = their intersection).
/// Two-line angular dimension (type 2) between two lines, attached to them.
fn angular_from_lines(s: &Session, h1: Handle, h2: Handle, at: Vec2) -> Option<EntityKind> {
let d = s.doc().ok()?;
let line = |h: Handle| match &d.entity(h)?.kind {
@@ -200,13 +200,18 @@ fn angular_from_lines(s: &Session, h1: Handle, h2: Handle, at: Vec2) -> Option<E
};
let (p1, s1) = pick(a1, a2, AssocSnap::Start, AssocSnap::End);
let (p2, s2) = pick(b1, b2, AssocSnap::Start, AssocSnap::End);
let k = dim(s, DimKind::Angular3P, at, p1, p2, v, Vec2::ZERO, "");
// A two-line angular dimension (type 2): line 1 is p13 -> p14, line 2 is defpt -> p15, p16 is on the arc.
// The picked leg end goes last in each pair, so the renderer measures between p14 and p15.
let (o1, t1) = if s1 == AssocSnap::Start { (a2, AssocSnap::End) } else { (a1, AssocSnap::Start) };
let (o2, t2) = if s2 == AssocSnap::Start { (b2, AssocSnap::End) } else { (b1, AssocSnap::Start) };
let k = dim(s, DimKind::Angular, o2, o1, p1, p2, at, "");
let mut assoc = Vec::new();
if assoc_enabled(s) {
assoc = vec![
DimAssoc { point: "p13".into(), handle: h1, snap: s1 },
DimAssoc { point: "p14".into(), handle: h2, snap: s2 },
DimAssoc { point: "p15".into(), handle: h1, snap: AssocSnap::Intersection { other: h2 } },
DimAssoc { point: "p13".into(), handle: h1, snap: t1 },
DimAssoc { point: "p14".into(), handle: h1, snap: s1 },
DimAssoc { point: "defpt".into(), handle: h2, snap: t2 },
DimAssoc { point: "p15".into(), handle: h2, snap: s2 },
];
}
Some(with_assoc(k, assoc))
+4 -2
View File
@@ -1,4 +1,4 @@
use cadcraft_doc::{AssocSnap, DimKind, Dimension, EntityKind, Handle};
use cadcraft_doc::{DimKind, Dimension, EntityKind, Handle};
use cadcraft_geom::Vec2;
use serde_json::{Value, json};
@@ -136,7 +136,9 @@ fn angular_between_lines_follows_rotation() {
let b = line(&mut s, [0.0, 0.0], [0.0, 10.0]);
let d = h(&s.execute("dimangular", &json!({ "lines": [a.hex(), b.hex()], "at": [3, 3] })).unwrap());
let dm = dim(&s, d);
assert!(dm.assoc.iter().any(|x| matches!(x.snap, AssocSnap::Intersection { .. })));
// Two picked lines make a two-line angular dimension (type 2), tied to both lines at all four points.
assert_eq!(dm.kind, DimKind::Angular);
assert_eq!(dm.assoc.len(), 4);
assert_eq!(cadcraft_render::dimension_in(s.doc().unwrap(), &dm).value, "90°");
// Swing the second line to 45°.
s.execute("properties.set", &json!({ "handles": [b.hex()], "end": [10, 10] })).unwrap();