From cea84ccb64f6fdead6ac0981effe8778d129cf68 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Fri, 12 Jun 2026 01:00:34 +0300 Subject: [PATCH] fix(edit): correct entity-pick hover previews on offset drawings The trim/extend hover preview (on_hover_entity) gets the cursor in offset-relative space but compares it against WCS document entities and returns WCS preview wires. On a drawing with a non-zero world_offset the preview highlighted the wrong segment and the wires were shifted off the geometry by the offset. Pass the world-offset-corrected click to on_hover_entity and shift its returned wires back to the offset-relative frame the renderer uses. Point-creation previews keep the local cursor. Co-Authored-By: Claude Opus 4.8 --- src/app/update.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/app/update.rs b/src/app/update.rs index ca6c61a9d..b611235e6 100644 --- a/src/app/update.rs +++ b/src/app/update.rs @@ -2489,6 +2489,20 @@ impl OpenCADStudio { self.tabs[i].last_cursor_world = effective; self.tabs[i].last_cursor_screen = p_full; + // Entity-pick previews (TRIM/EXTEND/FILLET…) compare the + // cursor against WCS document entities and return WCS wires. + // `effective` is offset-relative, so build a WCS copy for + // the click and shift the returned wires back to the + // offset-relative frame the renderer expects (model space + // only; paper-space entities use sheet coordinates). + let wo_local = if self.tabs[i].scene.current_layout == "Model" { + self.tabs[i].scene.world_offset + } else { + [0.0; 3] + }; + let wo_f = glam::Vec3::new(wo_local[0] as f32, wo_local[1] as f32, wo_local[2] as f32); + let effective_wcs = effective + wo_f; + // C3D-style orange object snap (plugin commands implement resolve_object_pick). if needs_structure { use crate::snap::{SnapResult, SnapType}; @@ -2545,8 +2559,20 @@ impl OpenCADStudio { let mut p = self.tabs[i] .active_cmd .as_mut() - .map(|c| c.on_hover_entity(hover_handle, effective)) + .map(|c| c.on_hover_entity(hover_handle, effective_wcs)) .unwrap_or_default(); + // on_hover_entity returns WCS wires; shift to the + // offset-relative frame so the preview lands on the + // geometry on large-coordinate drawings. + if wo_f != glam::Vec3::ZERO { + for w in p.iter_mut() { + for pt in w.points.iter_mut() { + pt[0] -= wo_f.x; + pt[1] -= wo_f.y; + pt[2] -= wo_f.z; + } + } + } if !hover_handle.is_null() { if let Some(cmd) = self.tabs[i].active_cmd.as_ref() { p.extend(cmd.entity_pick_acquire_previews(