fix: honor GRIDUNIT X/Y spacing and LIMITS option in grid display

The viewport grid ignored the configured spacing and forced square grids: compute_grid_step hardcoded a 1.0 base, a single shared step drove both line families (including the tangent derivative used for gap measurement), and the display always clipped to LIMITS despite the beyond-Limits option.

Grid spacing now scales per-axis from GRIDUNIT via compute_grid_steps (adaptive 5x growth, fixed passthrough), GridParams carries step_x/step_y, snap tolerances follow the visible steps, and the LIMITS clip is skipped when beyond-Limits is set. Also fixes a per-axis overflow fallback that returned the X base for Y. Spacing state (X/Y, adaptive, beyond-Limits) is stored on the app and persisted to UserSettings at defaults; dialog wiring follows separately.
This commit is contained in:
Karim Jerbi committed 2026-09-17 13:52:37 +01:00
1 parent bb29b987c2
commit 05f462f294
7 files changed
+246 -73

No files matched your search

+20 -5
View File
@@ -1924,18 +1924,25 @@ impl OpenCADStudio {
// content), so snap / hit-test / preview run exactly like the
// main model view — no paper projection, tracks pan/zoom/twist.
let cursor_world = self.cursor_model_point(i, &edit_cam, p, bounds);
let (view_rot, eye, grid_spacing) = match &edit_cam {
let (gx, gy, adaptive) = (self.grid_spacing_x, self.grid_spacing_y, self.grid_adaptive);
let visible_step = |distance: f32, fov_y: f32| {
let (sx, sy) = crate::ui::overlay::compute_grid_steps(
gx, gy, distance, fov_y, bounds, adaptive,
);
sx.max(sy)
};
let (view_rot, eye, grid_spacing) = match &edit_cam {
Some(cam) => (
cam.view_proj_rte(bounds),
cam.eye(),
crate::ui::overlay::compute_grid_step(cam.distance, cam.fov_y, bounds),
visible_step(cam.distance, cam.fov_y),
),
None => {
let cam = self.tabs[i].scene.camera.borrow();
(
cam.view_proj_rte(bounds),
cam.eye(),
crate::ui::overlay::compute_grid_step(cam.distance, cam.fov_y, bounds),
visible_step(cam.distance, cam.fov_y),
)
}
};
@@ -2788,18 +2795,26 @@ impl OpenCADStudio {
// Object/grid snap, same path as an entity grip or command drag: the
// dragged UCS point sticks to endpoints/midpoints/grid under the cursor,
// and the snap marker is published via `snap_result`.
let (dgx, dgy, dadaptive) =
(self.grid_spacing_x, self.grid_spacing_y, self.grid_adaptive);
let dvisible_step = |distance: f32, fov_y: f32| {
let (sx, sy) = crate::ui::overlay::compute_grid_steps(
dgx, dgy, distance, fov_y, bounds, dadaptive,
);
sx.max(sy)
};
let (view_rot, eye, grid_spacing) = match &edit_cam {
Some(cam) => (
cam.view_proj_rte(bounds),
cam.eye(),
crate::ui::overlay::compute_grid_step(cam.distance, cam.fov_y, bounds),
dvisible_step(cam.distance, cam.fov_y),
),
None => {
let cam = self.tabs[i].scene.camera.borrow();
(
cam.view_proj_rte(bounds),
cam.eye(),
crate::ui::overlay::compute_grid_step(cam.distance, cam.fov_y, bounds),
dvisible_step(cam.distance, cam.fov_y),
)
}
};