From b346eb4d6ebd91db3d31777049181a07c7e1705a Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Sat, 2 May 2026 14:55:12 +0300 Subject: [PATCH] fix: remove dead code warning and fix sheet viewport double-click in DWG files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove unused `screen_delta_to_world` camera method (superseded by the corrected pan_active_viewport formula). Fix `is_content_viewport`: the old geometry fallback required the viewport center to be near the origin, but DWG files never write the viewport id field (stays 0) and the sheet viewport center is the paper centre (e.g. 105, 148.5 mm for A4) — not the origin. This caused the sheet viewport to be classified as a content viewport in DWG files, making it both tessellated (border visible) and enterable via double-click. The new heuristic uses only the scale: a sheet viewport has scale ≈ 1:1 (view_height ≈ paper height); true content viewports have deliberate drawing scales (1:50, 1:100, …) that are far from 1.0. Co-Authored-By: Claude Sonnet 4.6 --- src/scene/camera.rs | 10 ---------- src/scene/mod.rs | 14 ++++++++++---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/scene/camera.rs b/src/scene/camera.rs index acff7b942..8d1d9af3c 100644 --- a/src/scene/camera.rs +++ b/src/scene/camera.rs @@ -242,16 +242,6 @@ impl Camera { self.target += cam_up * delta_y * speed; } - /// Returns the world-space translation that `pan(delta_x, delta_y)` would - /// apply to the camera target — without actually moving the camera. - /// Used by MSPACE to pan the viewport's model-space view independently. - pub fn screen_delta_to_world(&self, delta_x: f32, delta_y: f32, _bounds: Rectangle) -> Vec3 { - let speed = self.distance * 0.001; - let cam_right = self.rotation * Vec3::X; - let cam_up = self.rotation * Vec3::Y; - -(cam_right * delta_x * speed) + (cam_up * delta_y * speed) - } - pub fn fit_to_bounds(&mut self, min: Vec3, max: Vec3) { self.target = (min + max) * 0.5; let size = (max - min).length(); diff --git a/src/scene/mod.rs b/src/scene/mod.rs index 913679360..baa73e4bb 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -208,15 +208,21 @@ impl Scene { pub fn is_content_viewport(vp: &acadrust::entities::Viewport) -> bool { if vp.id == 1 { return false; } if vp.id > 1 { return true; } - // id=0 or id<0 — distinguish by geometry + // id ≤ 0: DWG files never write group-code 69 (viewport id), so all + // viewports arrive with id=0. Distinguish the sheet viewport by scale: + // the sheet ("overall") viewport has view_height ≈ vp.height → scale ≈ 1. + // True content viewports have deliberate drawing scales (1:50, 1:100 …) + // whose scale value is far from 1.0. The old check also required the + // center to be at the origin, but the sheet viewport center is the + // paper centre (e.g. 105, 148.5 for A4), so that condition failed for + // DWG files and incorrectly classified the sheet viewport as a content + // viewport — making it tessellated and enterable via double-click. let scale = if vp.view_height.abs() > 1e-9 { vp.height / vp.view_height } else { 1.0 }; - let at_origin = vp.center.x.abs() < 0.5 && vp.center.y.abs() < 0.5; - let scale_one = (scale - 1.0).abs() < 0.02; - !(at_origin && scale_one) + (scale - 1.0).abs() >= 0.02 }