Create Sketch: a face of a combined Mirror's copy keeps its own attachment (#5779) (#8278)

A mirror's or pattern's copy of a face carries its seed's construction certificate, and on a
combined body that certificate finds the seed's face. Capturing an attachment never checked
that the certificate finds the picked face, so a sketch on the mirrored half sat on the
original. The capture now falls back to the face's exact history name when the certificate
names another face, as docs/face-attachments.md describes.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
semmelrinde
2026-10-28 14:44:32 +00:00
committed by GitHub
parent cecb1d8b66
commit be2deb8c6f
2 changed files with 39 additions and 0 deletions
+5
View File
@@ -183,6 +183,11 @@ impl Document {
return Err(DocError::Invalid("this face has no supported construction certificate; choose a fixed plane instead".into()));
}
let indices = self.configuration_face_indices(body, &target)?;
// A copy a pattern or mirror made on the same body carries its seed's certificate,
// which finds the seed's face: the copy is attached by its own history name below.
if !indices.contains(&index) {
return Err(DocError::Invalid("this face has no supported construction certificate; choose a fixed plane instead".into()));
}
self.coplanar_pieces(body, &indices, |_| true)?;
Ok(target)
});
@@ -758,3 +758,37 @@ fn a_face_picked_by_point_on_a_block_with_a_modelled_thread_is_found() {
let plane = run(&mut s, "sketch.inspect", json!({}))["plane"].clone();
assert!((plane["origin"][2].as_f64().unwrap() - 20.0).abs() < 1e-6, "{plane}");
}
/// A Mirror that combines with its source makes each face's twin from the same source face: a
/// sketch on the mirrored half sits on that half, not on its original (#5779).
#[test]
fn a_sketch_on_the_mirrored_half_of_a_combined_body_sits_on_that_half() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length":30,"width":20,"height":10,"body_name":"Part","name":"Base"}));
run(&mut s, "solid.mirror", json!({"bodies":["Part"],"plane":"XY","combine":true,"name":"Mirror1"}));
assert_eq!(s.model.state().bodies.len(), 1, "the mirror combined");
let pick = |s: &Session, normal: Vec3, point: Vec3| {
let world = s.world_state();
let body = world.body("Part").unwrap();
let face = body
.body
.faces(0.01)
.unwrap()
.into_iter()
.find(|f| f.plane_normal.is_some_and(|n| n.dot(normal) > 0.999) && (f.centroid - point).dot(normal).abs() < 1e-6)
.unwrap_or_else(|| panic!("a face at {point:?}"));
json!({"body":"Part","index":face.index,"face":[point.x,point.y,point.z]})
};
for (name, normal, point) in [
("Bottom", -Vec3::Z, Vec3::new(15., 10., -10.)),
("Top", Vec3::Z, Vec3::new(15., 10., 10.)),
("Front low", -Vec3::Y, Vec3::new(15., 0., -5.)),
("Front high", -Vec3::Y, Vec3::new(15., 0., 5.)),
] {
let p = pick(&s, normal, point);
let id = run(&mut s, "sketch.create", json!({"name":name,"plane":p,"project_edges":false}))["sketch"].as_u64().unwrap();
run(&mut s, "sketch.finish", json!({}));
let plane = s.model.state().sketch(id).unwrap().plane;
assert!(plane.normal().dot(normal) > 0.999, "{name}: normal {:?}", plane.normal());
assert!((plane.origin - point).dot(normal).abs() < 1e-6, "{name}: origin {:?}", plane.origin);
}
}