From 65920959d4b6836d95361b6dd7130ca6351a7ba8 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Wed, 20 May 2026 04:45:37 +0300 Subject: [PATCH] feat(scene): fall back to header EXTMIN/EXTMAX for fit-all MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a fresh document hasn't tessellated yet (no wire AABB cache, no per-entity key vertices found), compute_model_space_extents() returned None, so ZOOM EXTENTS / auto_fit_viewport had to wait for the next pass before they could fit. Use the header's saved model_space_extents_min/max as a last-resort answer so the very first ZOOM EXTENTS / fit-all after open lands on the drawing immediately. LIMMIN/LIMMAX and INSBASE remain read-only metadata for now — they need a bounded-grid mode (LIMMIN/LIMMAX) and a "save as block" anchor (INSBASE) before they map onto a visible behaviour. Co-Authored-By: Claude Opus 4.7 --- src/scene/mod.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/scene/mod.rs b/src/scene/mod.rs index a44b8923a..5a2e0e1d4 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -1696,10 +1696,28 @@ impl Scene { } } if any { - Some((min, max)) - } else { - None + return Some((min, max)); } + // Last-resort: the header's saved EXTMIN/EXTMAX. AutoCAD writes these + // on save so opening a file gives ZOOM EXTENTS a useful answer before + // the wire cache is built. + const SANE_EXTENT: f64 = 1.0e16; + let h = &self.document.header; + let hmin = h.model_space_extents_min; + let hmax = h.model_space_extents_max; + if hmin.x < hmax.x + && hmin.y < hmax.y + && hmin.x.abs() < SANE_EXTENT + && hmax.x.abs() < SANE_EXTENT + && hmin.y.abs() < SANE_EXTENT + && hmax.y.abs() < SANE_EXTENT + { + return Some(( + glam::Vec3::new(hmin.x as f32, hmin.y as f32, hmin.z as f32), + glam::Vec3::new(hmax.x as f32, hmax.y as f32, hmax.z as f32), + )); + } + None } /// Set a newly created viewport's `view_target` and `view_height` so that