Joints: an edge origin shares the joint faces' measurement (#10866)
`face_of` called `Body::faces`, which tessellates the whole body, on every solve. Face origins went through the cached `ModelBody::joint_faces`, at the same tolerance, but edge origins never did, so one edge origin on a large body cost a drag or a Drive Joints step far more than the solve. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
58c64ca4d4
commit
cfc46448a8
2 files changed
+20
-1
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -50,7 +50,7 @@ fn edge_index(b: &ModelBody, name: Option<&str>, pick: Vec3) -> Option<usize> {
|
||||
fn face_of(b: &ModelBody, i: usize, name: Option<&str>, pick: Vec3) -> Result<(usize, Vec3, Vec3)> {
|
||||
let m = b.mesh();
|
||||
let beside: Vec<usize> = 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) => {
|
||||
|
||||
Reference in new issue
Block a user