diff --git a/crates/doc/src/face_anchor.rs b/crates/doc/src/face_anchor.rs index c321e0b6f..a8f4ca49d 100644 --- a/crates/doc/src/face_anchor.rs +++ b/crates/doc/src/face_anchor.rs @@ -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) }); diff --git a/crates/engine/src/cmd/sketch_face_tests.rs b/crates/engine/src/cmd/sketch_face_tests.rs index e0fd6a301..f6d195c99 100644 --- a/crates/engine/src/cmd/sketch_face_tests.rs +++ b/crates/engine/src/cmd/sketch_face_tests.rs @@ -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); + } +}