Snap 3D bridge lines to points on other sketch planes (#229)
* Snap 3D bridge drawing to points on visible sketch planes * Keep cross-sketch point picks out of sketch tools `pick()` returned every visible sketch's points while 3D drawing was on, so `sketch_point_at` and the sketch tools could take another sketch's point as an active-sketch local point plus id (flattening it or making a bad coincident reference). `pick()` is local again; the bridge snap uses `pick_3d` explicitly and hover mirrors it for feedback. `sketch_point_at` also ignores foreign points defensively. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(sketch3d): check local point scope with a sketch tool active Main's Project preselection fix now offers other sketches' points to idle selection, so assert the local scope where it still applies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style: rustfmt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: bherbruck <brennen.herbruck@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
5 files changed
+163
-6
No files matched your search
@@ -3,6 +3,128 @@
|
||||
use serde_json::json;
|
||||
use solvecraft_engine::geom::Vec3;
|
||||
|
||||
#[test]
|
||||
fn bridge_line_snaps_to_points_on_two_visible_sketch_planes() {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
for (name, offset, point) in [("Lower", 10, [10, 20]), ("Upper", 40, [30, 35])] {
|
||||
h.app.run("sketch.create", json!({"plane":{"origin":[0,0,offset],"x_dir":[1,0,0],"y_dir":[0,1,0]},"name":name})).unwrap();
|
||||
h.app.run("sketch.point", json!({"point":point})).unwrap();
|
||||
h.app.run("sketch.finish", json!({})).unwrap();
|
||||
}
|
||||
let bridge = h.app.run("sketch.create", json!({"plane":"XY","name":"Bridge"})).unwrap()["sketch"].as_u64().unwrap();
|
||||
h.app.run("sketch.options", json!({"sketch_3d":true})).unwrap();
|
||||
h.app.ui.show_origin = false;
|
||||
h.call("ui.view", json!({"view":"home"}));
|
||||
h.call("ui.view", json!({"view":"fit"}));
|
||||
h.frames(3);
|
||||
h.app.start("sketch.line");
|
||||
h.frames(3);
|
||||
// Idle selection offers other sketches' points for Project preselection; a sketch tool's
|
||||
// ordinary pick stays local, and only the 3D bridge snap (`pick_3d`) reaches across.
|
||||
let [x, y] = h.at(&json!({"world":[10,20,10]})).unwrap();
|
||||
let proj = crate::viewport::projection(&h.app, h.app.viewport.rect.unwrap());
|
||||
assert!(
|
||||
crate::viewport::pick(&h.app, &proj, egui::pos2(x as f32, y as f32))
|
||||
.iter()
|
||||
.all(|hit| { !matches!(hit, crate::viewport::Hit::SketchPoint { sketch, .. } if *sketch != bridge) }),
|
||||
"a sketch tool's ordinary pick must keep its local sketch-point scope"
|
||||
);
|
||||
for p in [[10, 20, 10], [30, 35, 40]] {
|
||||
let [x, y] = h.at(&json!({"world":p})).unwrap();
|
||||
let proj = crate::viewport::projection(&h.app, h.app.viewport.rect.unwrap());
|
||||
let picked = crate::sketch3d::point_at(&h.app, &proj, egui::pos2(x as f32, y as f32)).unwrap().0;
|
||||
assert!(picked.dist(Vec3::new(p[0] as f64, p[1] as f64, p[2] as f64)) < 1e-6, "{picked:?}");
|
||||
h.step(&json!({"click":{"world":p}})).unwrap();
|
||||
}
|
||||
h.step(&json!({"key":"Escape"})).unwrap();
|
||||
h.step(&json!({"key":"Escape"})).unwrap();
|
||||
let state = h.app.session.world_state();
|
||||
let wire = state.sketch(bridge).unwrap().sketch.wires.first().unwrap();
|
||||
assert!(wire.fit[0].dist(Vec3::new(10.0, 20.0, 10.0)) < 1e-6);
|
||||
assert!(wire.fit[1].dist(Vec3::new(30.0, 35.0, 40.0)) < 1e-6);
|
||||
h.app.run("edit.undo", json!({})).unwrap();
|
||||
assert!(h.app.session.world_state().sketch(bridge).unwrap().sketch.wires.is_empty());
|
||||
h.app.run("edit.redo", json!({})).unwrap();
|
||||
assert_eq!(h.app.session.world_state().sketch(bridge).unwrap().sketch.wires[0].fit, wire.fit);
|
||||
}
|
||||
|
||||
/// Another sketch's point and an active sketch on the same XY plane, so both lie under one cursor.
|
||||
fn coplanar_foreign_point() -> (crate::scenario::Harness, u64, u64) {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
let other = h.app.run("sketch.create", json!({"plane":"XY","name":"Other"})).unwrap()["sketch"].as_u64().unwrap();
|
||||
h.app.run("sketch.point", json!({"point":[10,20]})).unwrap();
|
||||
h.app.run("sketch.finish", json!({})).unwrap();
|
||||
let active = h.app.run("sketch.create", json!({"plane":"XY","name":"Active"})).unwrap()["sketch"].as_u64().unwrap();
|
||||
h.app.ui.show_origin = false;
|
||||
h.call("ui.view", json!({"view":"home"}));
|
||||
h.call("ui.view", json!({"view":"fit"}));
|
||||
h.frames(3);
|
||||
(h, other, active)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sketch_tools_never_pick_another_sketchs_point() {
|
||||
// Both in plain 2D sketching and while 3D drawing is on (the bridge snap's mode), the
|
||||
// sketch-tool pick path must not return a foreign point as a local point plus id.
|
||||
for sketch_3d in [false, true] {
|
||||
let (mut h, other, active) = coplanar_foreign_point();
|
||||
h.app.run("sketch.options", json!({"sketch_3d":sketch_3d})).unwrap();
|
||||
h.app.start("sketch.line");
|
||||
h.frames(3);
|
||||
assert_eq!(crate::sketch3d::drawing(&h.app), sketch_3d);
|
||||
let [x, y] = h.at(&json!({"world":[10,20,0]})).unwrap();
|
||||
let pos = egui::pos2(x as f32, y as f32);
|
||||
let proj = crate::viewport::projection(&h.app, h.app.viewport.rect.unwrap());
|
||||
let hits = crate::viewport::pick(&h.app, &proj, pos);
|
||||
assert!(
|
||||
!hits.iter().any(|hit| matches!(hit, crate::viewport::Hit::SketchPoint { sketch, .. } if *sketch == other)),
|
||||
"sketch_3d={sketch_3d}: pick leaked a point of sketch {other}: {hits:?}"
|
||||
);
|
||||
let (at, id) = crate::viewport::sketch_point_at(&h.app, &proj, pos).unwrap();
|
||||
assert!(id.is_none(), "sketch_3d={sketch_3d}: snapped to foreign point id {id:?}");
|
||||
assert!(at.dist(solvecraft_engine::geom::Vec2::new(10.0, 20.0)) < 0.5, "{at:?}");
|
||||
if !sketch_3d {
|
||||
let before = h.app.session.world_state().sketch(other).unwrap().sketch.clone();
|
||||
// A real 2D line click there creates nothing tied to the other sketch's point.
|
||||
h.step(&json!({"click":{"world":[10,20,0]}})).unwrap();
|
||||
h.step(&json!({"click":{"world":[40,5,0]}})).unwrap();
|
||||
h.step(&json!({"key":"Escape"})).unwrap();
|
||||
let state = h.app.session.world_state();
|
||||
let own = &state.sketch(active).unwrap().sketch;
|
||||
assert!(!own.curves.is_empty(), "line was drawn");
|
||||
assert_eq!(state.sketch(other).unwrap().sketch, before, "other sketch untouched");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bridge_snap_still_sees_other_sketch_points() {
|
||||
let (mut h, other, _) = coplanar_foreign_point();
|
||||
h.app.run("sketch.options", json!({"sketch_3d":true})).unwrap();
|
||||
h.app.start("sketch.line");
|
||||
h.frames(3);
|
||||
let [x, y] = h.at(&json!({"world":[10,20,0]})).unwrap();
|
||||
let pos = egui::pos2(x as f32, y as f32);
|
||||
let proj = crate::viewport::projection(&h.app, h.app.viewport.rect.unwrap());
|
||||
assert!(
|
||||
crate::viewport::pick_3d(&h.app, &proj, pos)
|
||||
.iter()
|
||||
.any(|hit| matches!(hit, crate::viewport::Hit::SketchPoint { sketch, .. } if *sketch == other)),
|
||||
"the 3D bridge pick offers the other sketch's point"
|
||||
);
|
||||
let (snapped, kind) = crate::sketch3d::point_at(&h.app, &proj, pos).unwrap();
|
||||
assert_eq!(kind, "Pt");
|
||||
assert!(snapped.dist(Vec3::new(10.0, 20.0, 0.0)) < 1e-6, "{snapped:?}");
|
||||
// Hover highlights the snap target the click will use.
|
||||
h.step(&json!({"move":{"world":[10,20,0]}})).unwrap();
|
||||
h.frames(2);
|
||||
assert!(
|
||||
matches!(&h.app.viewport.hover, Some(crate::viewport::Hit::SketchPoint { sketch, .. }) if *sketch == other),
|
||||
"{:?}",
|
||||
h.app.viewport.hover
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn second_occurrence_drawn_wire_fit_picks_and_world_triad_drag_stay_aligned() {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
|
||||
Reference in new issue
Block a user