Canvas: a plane seen edge-on doesn't take the image (#4717) (#4876)

* claim: #4717

* Canvas: a plane seen edge-on doesn't take the image (#4717)

Placed with a click at a sketch's origin, the canvas went onto the origin's XZ square, which
is under the cursor there too and was the first plane hit. From the Top view that plane is
edge-on, so the image was out of sight and Canvas seemed to do nothing. A plane hit counts only
when the view shows it (its normal more than ~11.5 degrees off the view's edge-on direction); the
sketch plane, or another plane, takes the image instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dudedagger42
2026-10-24 21:06:41 +00:00
committed by GitHub
parent 2c9d0a2847
commit fcc3753a4c
3 changed files with 29 additions and 2 deletions
+1 -1
View File
@@ -3055,7 +3055,7 @@ fn shown_origin_plane(app: &SolveApp, name: &str) -> Option<Value> {
}
/// The world plane of an origin plane or a construction plane by name, where it is shown.
fn plane_by_name(s: &Session, name: &str) -> Option<solidcraft_engine::geom::Plane> {
pub(crate) fn plane_by_name(s: &Session, name: &str) -> Option<solidcraft_engine::geom::Plane> {
if let Some(p) = solidcraft_engine::geom::Plane::named(name) {
return Some(p);
}
+23
View File
@@ -388,4 +388,27 @@ mod tests {
h.frames(2);
assert_eq!(*asked.borrow(), [vec!["csv", "json"], vec!["png", "jpg", "jpeg"]]);
}
/// #4717: a canvas placed with a click on the origin of a sketch on XY, seen from the top,
/// lies on XY. The origin's XZ square is under the cursor there too, edge-on, and the image
/// went onto it, out of sight.
#[test]
fn a_canvas_clicked_at_the_sketch_origin_lies_where_it_can_be_seen() {
let mut h = crate::scenario::Harness::new();
h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();
for step in [
json!({"make_image": "pic.png"}),
json!({"choose_file": "pic.png"}),
json!({"call": "ui.view", "params": {"view": "top"}}),
json!({"start": "canvas.insert"}),
json!({"click": {"world": [0, 0, 0]}}),
] {
h.step(&step).unwrap();
}
let doc = &h.app.session.doc;
let canvas = doc.canvases.first().expect("the canvas is placed");
let (vals, _) = doc.param_values();
let n = doc.canvas_plane(&vals, canvas).unwrap().normal();
assert!(n.z.abs() > 0.99, "the canvas lies on {n:?}, not on XY");
}
}
+5 -1
View File
@@ -851,9 +851,13 @@ pub fn on_click(app: &mut SolveApp, tool: &mut Tool, proj: &Proj, pos: Pos2) {
Mode::ModelRef if matches!(cmd, "canvas.insert" | "canvas.decal") => {
let Some(path) = IMAGE.with(|i| i.borrow().clone()) else { return };
let decal = cmd == "canvas.decal";
// A plane the view shows edge-on can't show the image: at the origin its square is
// under the cursor too, and the image went onto it out of sight (#4717).
let (_, ray) = proj.ray(pos);
let seen = |name: &str| crate::dialogs::plane_by_name(&app.session, name).is_some_and(|pl| pl.normal().dot(ray).abs() > 0.2 * ray.len());
let target = hits.iter().find_map(|h| match h {
Hit::Face { point, .. } => Some((json!({"face": [point.x, point.y, point.z]}), *point)),
Hit::Plane { name, point } if !decal => Some((json!(name), *point)),
Hit::Plane { name, point } if !decal && seen(name) => Some((json!(name), *point)),
_ => None,
});
// Empty space while sketching: the sketch plane.