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

+19
View File
@@ -459,6 +459,17 @@ pub struct UserSettings {
pub snap_spacing_x: f32,
#[serde(default = "default_snap_spacing")]
pub snap_spacing_y: f32,
/// GRIDUNIT X/Y display spacing (grid resizing). Falls back to 10.
#[serde(default = "default_snap_spacing")]
pub grid_spacing_x: f32,
#[serde(default = "default_snap_spacing")]
pub grid_spacing_y: f32,
/// Adaptive grid scaling (default on).
#[serde(default = "default_true")]
pub grid_adaptive: bool,
/// Display grid beyond LIMITS (default on, matches dialog).
#[serde(default = "default_true")]
pub grid_beyond_limits: bool,
/// Most-recently-inserted block names, most recent first, capped to 20.
/// Used to rank INSERT suggestions without touching the drawing file.
#[serde(default)]
@@ -485,6 +496,10 @@ fn default_snap_spacing() -> f32 {
10.0
}
fn default_true() -> bool {
true
}
/// Clamp a snap spacing to the positive range the dialog accepts.
pub fn sanitize_snap_spacing(v: f32) -> f32 {
if v.is_finite() && v > 0.0 && v <= 1e9 {
@@ -599,6 +614,10 @@ impl Default for UserSettings {
commandline_fade_ms: 3000,
snap_spacing_x: 10.0,
snap_spacing_y: 10.0,
grid_spacing_x: 10.0,
grid_spacing_y: 10.0,
grid_adaptive: true,
grid_beyond_limits: true,
block_mru: Vec::new(),
block_freq: std::collections::HashMap::new(),
}