fix(edit): add world_offset to entity-pick clicks

The pick point handed to commands is in offset-relative (local) space,
matching the camera and point-creation commands. Entity-pick, tangent
and structure-pick handlers (TRIM / EXTEND / FILLET / OFFSET, …) instead
compare the click against WCS document entities, so on a drawing with a
non-zero world_offset (UTM-scale coordinates) the click landed ~1e6
units off the geometry — TRIM cut the wrong side or reported the click
as off the segment. Add world_offset back to the pick (model space only)
before passing it to those handlers, matching what the grip path already
does. Point-creation commands keep the local point unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-06-12 00:53:20 +03:00
commit 14d047ce9a

View file

@ -3032,6 +3032,22 @@ impl OpenCADStudio {
pt
};
// `world_pt` is in offset-relative (local) space, matching
// the camera and the point-creation commands. Entity-pick /
// tangent / structure-pick commands instead compare the
// click against WCS document entities, so they need the
// world_offset added back (model space only — paper-space
// entities are already in sheet coordinates). Without this,
// TRIM/EXTEND/FILLET pick the wrong side on UTM-scale files.
let pick_wcs = {
let wo = if self.tabs[i].scene.current_layout == "Model" {
self.tabs[i].scene.world_offset
} else {
[0.0; 3]
};
world_pt + glam::Vec3::new(wo[0] as f32, wo[1] as f32, wo[2] as f32)
};
let result = if self.tabs[i]
.active_cmd
.as_ref()
@ -3041,12 +3057,12 @@ impl OpenCADStudio {
let pick = self.tabs[i].active_cmd.as_ref().and_then(|c| {
c.resolve_object_pick(
&self.tabs[i].scene,
world_pt.x as f64,
world_pt.y as f64,
pick_wcs.x as f64,
pick_wcs.y as f64,
)
});
if let Some(pick) = pick {
let center = glam::Vec3::new(pick.x as f32, pick.y as f32, world_pt.z);
let center = glam::Vec3::new(pick.x as f32, pick.y as f32, pick_wcs.z);
let result = self.tabs[i]
.active_cmd
.as_mut()
@ -3094,7 +3110,7 @@ impl OpenCADStudio {
let result = self.tabs[i]
.active_cmd
.as_mut()
.map(|c| c.on_entity_pick(handle, world_pt));
.map(|c| c.on_entity_pick(handle, pick_wcs));
// HATCHEDIT: after pick, inject hatch model data into the command.
if self.tabs[i]
.active_cmd
@ -3161,7 +3177,7 @@ impl OpenCADStudio {
self.tabs[i]
.active_cmd
.as_mut()
.map(|c| c.on_tangent_point(obj, world_pt))
.map(|c| c.on_tangent_point(obj, pick_wcs))
} else {
self.command_line.push_info("Select a tangent object.");
None