Files
OneCAD-Draft/src/modules/draw/defaults.rs
T
Hakan SevenandClaude Opus 4.8 62bd360e46 refactor(precision): widen command transform scalars and defaults to f64 (#311)
Completes the f64 migration on the CPU data path: the only f32 left now
is the GPU/render/screen layer, which is architecturally required (wgpu
vertex buffers and iced are f32; f64 vertices would double memory).

- EntityTransform::Rotate.angle_rad and Scale.factor are now f64 (the
  transform was already applied in f64 around the DVec3 center, so this
  only preserves the typed angle/factor). apply_standard_transform and
  apply_standard_scale take f64.
- CmdResult::ExtrudeEntity.height and AlignSelected.{angle_rad,scale}
  are f64; the EXTRUDE height parses as f64.
- defaults.rs (last-used construction values: circle radius/diameter,
  rotate angle, scale factor, offset/fillet/chamfer distance, array
  spacing/counts/angle) moved from Cell<f32> to Cell<f64>. Array counts
  round-trip through u32 (exact below 2^53).
- Consumers in circle/array/fillet/offset/rotate/scale/align/solid3d and
  dimension.rs rotate_point/scale_point follow. `as f32` is kept only
  where a value feeds a WireModel rubber-band/ghost (the preview path is
  screen-space f32).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-12 00:34:38 +03:00

50 lines
2.2 KiB
Rust

// Persistent command defaults — last-used values survive across command runs
// within the same session. Uses thread_local! so no synchronisation needed.
use std::cell::Cell;
thread_local! {
static CIRCLE_RADIUS: Cell<f64> = Cell::new(1.0);
static CIRCLE_DIAM: Cell<f64> = Cell::new(2.0);
static ROTATE_ANGLE: Cell<f64> = Cell::new(0.0); // degrees
static SCALE_FACTOR: Cell<f64> = Cell::new(1.0);
static OFFSET_DIST: Cell<f64> = Cell::new(1.0);
static FILLET_RADIUS: Cell<f64> = Cell::new(1.0);
static CHAMFER_DIST1: Cell<f64> = Cell::new(10.0);
static CHAMFER_DIST2: Cell<f64> = Cell::new(10.0);
static ARRAY_ROWS: Cell<f64> = Cell::new(2.0);
static ARRAY_COLS: Cell<f64> = Cell::new(2.0);
static ARRAY_ROW_SP: Cell<f64> = Cell::new(100.0);
static ARRAY_COL_SP: Cell<f64> = Cell::new(100.0);
static ARRAY_P_COUNT: Cell<f64> = Cell::new(6.0);
static ARRAY_P_ANGLE: Cell<f64> = Cell::new(360.0); // degrees
static ARRAY_PATH_COUNT: Cell<f64> = Cell::new(6.0);
}
macro_rules! accessors {
($get:ident, $set:ident, $var:ident) => {
pub fn $get() -> f64 {
$var.with(|c| c.get())
}
pub fn $set(v: f64) {
$var.with(|c| c.set(v));
}
};
}
accessors!(get_circle_radius, set_circle_radius, CIRCLE_RADIUS);
accessors!(get_circle_diam, set_circle_diam, CIRCLE_DIAM);
accessors!(get_rotate_angle, set_rotate_angle, ROTATE_ANGLE);
accessors!(get_scale_factor, set_scale_factor, SCALE_FACTOR);
accessors!(get_offset_dist, set_offset_dist, OFFSET_DIST);
accessors!(get_fillet_radius, set_fillet_radius, FILLET_RADIUS);
accessors!(get_chamfer_dist1, set_chamfer_dist1, CHAMFER_DIST1);
accessors!(get_chamfer_dist2, set_chamfer_dist2, CHAMFER_DIST2);
accessors!(get_array_rows, set_array_rows, ARRAY_ROWS);
accessors!(get_array_cols, set_array_cols, ARRAY_COLS);
accessors!(get_array_row_sp, set_array_row_sp, ARRAY_ROW_SP);
accessors!(get_array_col_sp, set_array_col_sp, ARRAY_COL_SP);
accessors!(get_array_p_count, set_array_p_count, ARRAY_P_COUNT);
accessors!(get_array_p_angle, set_array_p_angle, ARRAY_P_ANGLE);
accessors!(get_array_path_count, set_array_path_count, ARRAY_PATH_COUNT);