fix: remove dead code warning and fix sheet viewport double-click in DWG files

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 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-05-02 14:55:12 +03:00
commit b346eb4d6e
2 changed files with 10 additions and 14 deletions

View file

@ -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();

View file

@ -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
}