diff --git a/crates/doc/src/eval_cost_tests.rs b/crates/doc/src/eval_cost_tests.rs index 85d76b9fd..a851e33b9 100644 --- a/crates/doc/src/eval_cost_tests.rs +++ b/crates/doc/src/eval_cost_tests.rs @@ -174,6 +174,25 @@ fn joint_face_measurements_never_follow_a_replaced_body_or_stale_offset() { assert_eq!(work.joint_faces, 0, "offsets are applied after the shared face measurements"); } +/// Every solve of a drag resolves its edge origins again: they share the joint faces' one +/// measurement, as a face origin does, instead of tessellating the whole body each time. +#[test] +fn an_edge_origin_measures_its_faces_once() { + use crate::joints::{JointOrigin, Snap}; + let doc = Document::new("edge origin"); + let mut state = ModelState::default(); + state.bodies.push(ModelBody::new("Block".into(), kernel::box_solid(Vec3::ZERO, Vec3::new(10.0, 10.0, 10.0)).unwrap(), 0)); + let pick = Vec3::new(5.0, 0.0, 10.0); + let origin = JointOrigin { occurrence: 0, snap: Snap::Edge { pick, edge: None, face: None, corner: None, axis: None } }; + let work = counted(|| { + for _ in 0..8 { + let frame = joints::resolve_origin(&doc, &state.clone(), &origin).unwrap(); + assert!(apply_point(&frame, Vec3::ZERO).dist(pick) < 1e-9); + } + }); + assert_eq!(work.joint_faces, 1, "a solve must not measure the faces again: {work:?}"); +} + /// `parts` imported files of two boxes each, every one in its own component placed away from /// the origin (as inserted parts are). fn placed_imports(parts: usize) -> Document { diff --git a/crates/doc/src/joints_edge.rs b/crates/doc/src/joints_edge.rs index afa006976..e62b90c28 100644 --- a/crates/doc/src/joints_edge.rs +++ b/crates/doc/src/joints_edge.rs @@ -50,7 +50,7 @@ fn edge_index(b: &ModelBody, name: Option<&str>, pick: Vec3) -> Option { fn face_of(b: &ModelBody, i: usize, name: Option<&str>, pick: Vec3) -> Result<(usize, Vec3, Vec3)> { let m = b.mesh(); let beside: Vec = m.edge_faces.get(i).map(|fs| fs.iter().map(|f| *f as usize).collect()).unwrap_or_default(); - let infos = b.body.faces(tol(b))?; + let infos = b.joint_faces()?; let planar = |f: usize| infos.iter().find(|x| x.index == f).and_then(|x| x.plane_normal.map(|n| (x.index, n, x.centroid, x.area))); let chosen = match name { Some(n) => {