From 62bd360e465acd1490a02284fe12e63672f06812 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Sun, 12 Jul 2026 00:34:38 +0300 Subject: [PATCH] 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 to Cell. 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 --- src/command.rs | 10 ++--- src/entities/dimension.rs | 8 ++-- src/modules/draw/defaults.rs | 34 ++++++++-------- src/modules/draw/draw/circle.rs | 14 +++---- src/modules/draw/modify/align.rs | 6 +-- src/modules/draw/modify/array.rs | 64 +++++++++++++++--------------- src/modules/draw/modify/fillet.rs | 20 +++++----- src/modules/draw/modify/offset.rs | 2 +- src/modules/draw/modify/rotate.rs | 12 +++--- src/modules/draw/modify/scale.rs | 20 +++++----- src/modules/insert/solid3d_cmds.rs | 4 +- src/scene/view/transform.rs | 8 ++-- 12 files changed, 100 insertions(+), 102 deletions(-) diff --git a/src/command.rs b/src/command.rs index 279559ac7..b46940ace 100644 --- a/src/command.rs +++ b/src/command.rs @@ -28,9 +28,9 @@ pub enum EntityTransform { /// Move every point by the given world-space delta (world XY plane). Translate(DVec3), /// Rotate around `center` by `angle_rad` in the world XY plane. - Rotate { center: DVec3, angle_rad: f32 }, + Rotate { center: DVec3, angle_rad: f64 }, /// Uniform scale from `center` by `factor`. - Scale { center: DVec3, factor: f32 }, + Scale { center: DVec3, factor: f64 }, /// Mirror across the line through `p1`→`p2` in the world XY plane. Mirror { p1: DVec3, p2: DVec3 }, } @@ -236,8 +236,8 @@ pub enum CmdResult { handles: Vec, src1: DVec3, dst1: DVec3, - angle_rad: f32, - scale: f32, + angle_rad: f64, + scale: f64, }, /// Set the plot window on the active layout's PlotSettings. SetPlotWindow { p1: DVec3, p2: DVec3 }, @@ -291,7 +291,7 @@ pub enum CmdResult { /// Extrude the profile entity `handle` by `height` along Z. ExtrudeEntity { handle: Handle, - height: f32, + height: f64, color: [f32; 4], }, /// Revolve the profile entity `handle` around the given axis by `angle_deg`. diff --git a/src/entities/dimension.rs b/src/entities/dimension.rs index 6134bf554..46c62328b 100644 --- a/src/entities/dimension.rs +++ b/src/entities/dimension.rs @@ -559,16 +559,16 @@ where } } -fn rotate_point(p: &mut acadrust::types::Vector3, center: DVec3, angle_rad: f32) { +fn rotate_point(p: &mut acadrust::types::Vector3, center: DVec3, angle_rad: f64) { let dx = p.x - center.x; let dy = p.y - center.y; - let (s, c) = (angle_rad as f64).sin_cos(); + let (s, c) = angle_rad.sin_cos(); p.x = center.x + dx * c - dy * s; p.y = center.y + dx * s + dy * c; } -fn scale_point(p: &mut acadrust::types::Vector3, center: DVec3, factor: f32) { - let f = factor as f64; +fn scale_point(p: &mut acadrust::types::Vector3, center: DVec3, factor: f64) { + let f = factor; p.x = center.x + (p.x - center.x) * f; p.y = center.y + (p.y - center.y) * f; p.z = center.z + (p.z - center.z) * f; diff --git a/src/modules/draw/defaults.rs b/src/modules/draw/defaults.rs index 2cec20fc8..392cd2d7a 100644 --- a/src/modules/draw/defaults.rs +++ b/src/modules/draw/defaults.rs @@ -4,29 +4,29 @@ use std::cell::Cell; thread_local! { - static CIRCLE_RADIUS: Cell = Cell::new(1.0); - static CIRCLE_DIAM: Cell = Cell::new(2.0); - static ROTATE_ANGLE: Cell = Cell::new(0.0); // degrees - static SCALE_FACTOR: Cell = Cell::new(1.0); - static OFFSET_DIST: Cell = Cell::new(1.0); - static FILLET_RADIUS: Cell = Cell::new(1.0); - static CHAMFER_DIST1: Cell = Cell::new(10.0); - static CHAMFER_DIST2: Cell = Cell::new(10.0); - static ARRAY_ROWS: Cell = Cell::new(2.0); - static ARRAY_COLS: Cell = Cell::new(2.0); - static ARRAY_ROW_SP: Cell = Cell::new(100.0); - static ARRAY_COL_SP: Cell = Cell::new(100.0); - static ARRAY_P_COUNT: Cell = Cell::new(6.0); - static ARRAY_P_ANGLE: Cell = Cell::new(360.0); // degrees - static ARRAY_PATH_COUNT: Cell = Cell::new(6.0); + static CIRCLE_RADIUS: Cell = Cell::new(1.0); + static CIRCLE_DIAM: Cell = Cell::new(2.0); + static ROTATE_ANGLE: Cell = Cell::new(0.0); // degrees + static SCALE_FACTOR: Cell = Cell::new(1.0); + static OFFSET_DIST: Cell = Cell::new(1.0); + static FILLET_RADIUS: Cell = Cell::new(1.0); + static CHAMFER_DIST1: Cell = Cell::new(10.0); + static CHAMFER_DIST2: Cell = Cell::new(10.0); + static ARRAY_ROWS: Cell = Cell::new(2.0); + static ARRAY_COLS: Cell = Cell::new(2.0); + static ARRAY_ROW_SP: Cell = Cell::new(100.0); + static ARRAY_COL_SP: Cell = Cell::new(100.0); + static ARRAY_P_COUNT: Cell = Cell::new(6.0); + static ARRAY_P_ANGLE: Cell = Cell::new(360.0); // degrees + static ARRAY_PATH_COUNT: Cell = Cell::new(6.0); } macro_rules! accessors { ($get:ident, $set:ident, $var:ident) => { - pub fn $get() -> f32 { + pub fn $get() -> f64 { $var.with(|c| c.get()) } - pub fn $set(v: f32) { + pub fn $set(v: f64) { $var.with(|c| c.set(v)); } }; diff --git a/src/modules/draw/draw/circle.rs b/src/modules/draw/draw/circle.rs index c7b4faea5..46dc019f5 100644 --- a/src/modules/draw/draw/circle.rs +++ b/src/modules/draw/draw/circle.rs @@ -113,7 +113,7 @@ fn circumcircle(a: DVec3, b: DVec3, c: DVec3) -> Option<(DVec3, f64)> { pub struct CircleCommand { step: StepCR, - default_r: f32, + default_r: f64, } enum StepCR { Center, @@ -168,7 +168,7 @@ impl CadCommand for CircleCommand { } StepCR::Radius(c) => { let r = c.distance(pt); - defaults::set_circle_radius(r as f32); + defaults::set_circle_radius(r); CmdResult::CommitAndExit(make_circle(*c, r)) } } @@ -177,7 +177,7 @@ impl CadCommand for CircleCommand { if let StepCR::Radius(c) = &self.step { let c = *c; let r = self.default_r; - return CmdResult::CommitAndExit(make_circle(c, r as f64)); + return CmdResult::CommitAndExit(make_circle(c, r)); } CmdResult::Cancel } @@ -207,7 +207,7 @@ impl CadCommand for CircleCommand { if let StepCR::Radius(c) = &self.step { let r: f64 = text.trim().replace(',', ".").parse().ok()?; if r > 0.0 { - defaults::set_circle_radius(r as f32); + defaults::set_circle_radius(r); return Some(CmdResult::CommitAndExit(make_circle(*c, r))); } } @@ -241,7 +241,7 @@ impl CadCommand for CircleCommand { pub struct CircleCDCommand { step: StepCR, - default_d: f32, + default_d: f64, } impl CircleCDCommand { @@ -274,7 +274,7 @@ impl CadCommand for CircleCDCommand { } StepCR::Radius(c) => { let d = c.distance(pt) * 2.0; - defaults::set_circle_diam(d as f32); + defaults::set_circle_diam(d); CmdResult::CommitAndExit(make_circle(*c, d / 2.0)) } } @@ -302,7 +302,7 @@ impl CadCommand for CircleCDCommand { if let StepCR::Radius(c) = &self.step { let d: f64 = text.trim().replace(',', ".").parse().ok()?; if d > 0.0 { - defaults::set_circle_diam(d as f32); + defaults::set_circle_diam(d); return Some(CmdResult::CommitAndExit(make_circle(*c, d / 2.0))); } } diff --git a/src/modules/draw/modify/align.rs b/src/modules/draw/modify/align.rs index 389f8f7ce..236f60d27 100644 --- a/src/modules/draw/modify/align.rs +++ b/src/modules/draw/modify/align.rs @@ -184,10 +184,8 @@ impl AlignCommand { handles: self.handles.clone(), src1: s1, dst1: d1, - // Reference points (src1/dst1) stay f64 exact; the derived - // similarity scalars feed the f32 EntityTransform, so downcast here. - angle_rad: angle as f32, - scale: scale_factor as f32, + angle_rad: angle, + scale: scale_factor, } } } diff --git a/src/modules/draw/modify/array.rs b/src/modules/draw/modify/array.rs index 09ec63140..eba3d9e5e 100644 --- a/src/modules/draw/modify/array.rs +++ b/src/modules/draw/modify/array.rs @@ -51,7 +51,7 @@ enum RectStep { Rows, Cols { rows: u32 }, RowSp { rows: u32, cols: u32 }, - ColSp { rows: u32, cols: u32, row_sp: f32 }, + ColSp { rows: u32, cols: u32, row_sp: f64 }, } pub struct ArrayRectCommand { @@ -60,8 +60,8 @@ pub struct ArrayRectCommand { step: RectStep, default_rows: u32, default_cols: u32, - default_row_sp: f32, - default_col_sp: f32, + default_row_sp: f64, + default_col_sp: f64, ucs: Mat4, } @@ -84,8 +84,8 @@ impl ArrayRectCommand { fn build_transforms( rows: u32, cols: u32, - row_sp: f32, - col_sp: f32, + row_sp: f64, + col_sp: f64, ucs: Mat4, ) -> Vec { let mut t = Vec::new(); @@ -95,7 +95,7 @@ impl ArrayRectCommand { continue; } t.push(EntityTransform::Translate(ucs.as_dmat4().transform_vector3( - glam::DVec3::new((col_sp * c as f32) as f64, (row_sp * r as f32) as f64, 0.0), + glam::DVec3::new(col_sp * c as f64, row_sp * r as f64, 0.0), ))); } } @@ -147,7 +147,7 @@ impl CadCommand for ArrayRectCommand { self.default_rows } else { let v = t.parse::().unwrap_or(self.default_rows).max(1); - defaults::set_array_rows(v as f32); + defaults::set_array_rows(v as f64); self.default_rows = v; v }; @@ -159,7 +159,7 @@ impl CadCommand for ArrayRectCommand { self.default_cols } else { let v = t.parse::().unwrap_or(self.default_cols).max(1); - defaults::set_array_cols(v as f32); + defaults::set_array_cols(v as f64); self.default_cols = v; v }; @@ -170,7 +170,7 @@ impl CadCommand for ArrayRectCommand { let row_sp = if t.is_empty() { self.default_row_sp } else { - let v = t.parse::().unwrap_or(self.default_row_sp); + let v = t.parse::().unwrap_or(self.default_row_sp); defaults::set_array_row_sp(v); self.default_row_sp = v; v @@ -182,7 +182,7 @@ impl CadCommand for ArrayRectCommand { let col_sp = if t.is_empty() { self.default_col_sp } else { - let v = t.parse::().unwrap_or(self.default_col_sp); + let v = t.parse::().unwrap_or(self.default_col_sp); defaults::set_array_col_sp(v); v }; @@ -255,7 +255,7 @@ pub struct ArrayPolarCommand { wire_models: Vec, step: PolarStep, default_count: u32, - default_angle: f32, + default_angle: f64, } impl ArrayPolarCommand { @@ -313,7 +313,7 @@ impl CadCommand for ArrayPolarCommand { self.default_count } else { let v = t.parse::().unwrap_or(self.default_count).max(2); - defaults::set_array_p_count(v as f32); + defaults::set_array_p_count(v as f64); self.default_count = v; v }; @@ -326,15 +326,15 @@ impl CadCommand for ArrayPolarCommand { let total_deg = if t.is_empty() { self.default_angle } else { - let v = t.parse::().unwrap_or(self.default_angle); + let v = t.parse::().unwrap_or(self.default_angle); defaults::set_array_p_angle(v); v }; - let step_rad = total_deg.to_radians() / count as f32; + let step_rad = total_deg.to_radians() / count as f64; let transforms = (1..count) .map(|n| EntityTransform::Rotate { center, - angle_rad: step_rad * n as f32, + angle_rad: step_rad * n as f64, }) .collect(); Some(CmdResult::BatchCopy(self.handles.clone(), transforms)) @@ -354,10 +354,10 @@ impl CadCommand for ArrayPolarCommand { (center.as_vec3(), *count, self.default_angle) } }; - let step_rad = total_deg.to_radians() / count as f32; + let step_rad = total_deg.to_radians() / count as f64; let mut out: Vec = (1..count) .flat_map(|n| { - let angle_rad = step_rad * n as f32; + let angle_rad = (step_rad * n as f64) as f32; self.wire_models .iter() .map(move |w| w.rotated(center, angle_rad)) @@ -667,7 +667,7 @@ impl ArrayPathCommand { let center = Self::rigid_center(p0, p, dth); EntityTransform::Rotate { center, - angle_rad: dth as f32, + angle_rad: dth, } } }) @@ -779,7 +779,7 @@ impl CadCommand for ArrayPathCommand { self.default_count } else { let v = t.parse::().unwrap_or(self.default_count).max(2); - defaults::set_array_path_count(v as f32); + defaults::set_array_path_count(v as f64); self.default_count = v; v }; @@ -808,7 +808,7 @@ impl CadCommand for ArrayPathCommand { EntityTransform::Rotate { center, angle_rad } => self .wire_models .iter() - .map(|w| w.rotated(center.as_vec3(), *angle_rad)) + .map(|w| w.rotated(center.as_vec3(), *angle_rad as f32)) .collect::>(), _ => vec![], }) @@ -851,14 +851,14 @@ enum Array3DStep { rows: u32, cols: u32, levels: u32, - row_sp: f32, + row_sp: f64, }, LvlSp { rows: u32, cols: u32, levels: u32, - row_sp: f32, - col_sp: f32, + row_sp: f64, + col_sp: f64, }, } @@ -879,9 +879,9 @@ impl Array3DCommand { rows: u32, cols: u32, levels: u32, - row_sp: f32, - col_sp: f32, - lvl_sp: f32, + row_sp: f64, + col_sp: f64, + lvl_sp: f64, ) -> Vec { let mut t = Vec::new(); for l in 0..levels { @@ -893,9 +893,9 @@ impl Array3DCommand { // Drawing plane is world XY: X = col dir, Y = row dir, // Z = level (elevation). t.push(EntityTransform::Translate(DVec3::new( - (col_sp * c as f32) as f64, - (row_sp * r as f32) as f64, - (lvl_sp * l as f32) as f64, + col_sp * c as f64, + row_sp * r as f64, + lvl_sp * l as f64, ))); } } @@ -981,7 +981,7 @@ impl CadCommand for Array3DCommand { Some(CmdResult::NeedPoint) } Array3DStep::RowSp { rows, cols, levels } => { - let v: f32 = if t.is_empty() { + let v: f64 = if t.is_empty() { 1.0 } else { t.parse().unwrap_or(1.0) @@ -1000,7 +1000,7 @@ impl CadCommand for Array3DCommand { levels, row_sp, } => { - let v: f32 = if t.is_empty() { + let v: f64 = if t.is_empty() { 1.0 } else { t.parse().unwrap_or(1.0) @@ -1021,7 +1021,7 @@ impl CadCommand for Array3DCommand { row_sp, col_sp, } => { - let v: f32 = if t.is_empty() { + let v: f64 = if t.is_empty() { 1.0 } else { t.parse().unwrap_or(1.0) diff --git a/src/modules/draw/modify/fillet.rs b/src/modules/draw/modify/fillet.rs index 8567aa615..8cc07e1e9 100644 --- a/src/modules/draw/modify/fillet.rs +++ b/src/modules/draw/modify/fillet.rs @@ -1211,7 +1211,7 @@ pub struct FilletCommand { } impl FilletCommand { - pub fn new(radius: f32, all_entities: Vec) -> Self { + pub fn new(radius: f64, all_entities: Vec) -> Self { Self { radius: radius as f64, step: FilletStep::First, @@ -1298,7 +1298,7 @@ impl CadCommand for FilletCommand { if let Ok(v) = t.replace(',', ".").parse::() { if v >= 0.0 { self.radius = v; - defaults::set_fillet_radius(v as f32); + defaults::set_fillet_radius(v); } self.resume_after_radius(); return Some(CmdResult::NeedPoint); @@ -1320,7 +1320,7 @@ impl CadCommand for FilletCommand { if let Ok(v) = body.replace(',', ".").parse::() { if v >= 0.0 { self.radius = v; - defaults::set_fillet_radius(v as f32); + defaults::set_fillet_radius(v); } // Stay in the current step (keeps any first pick). return Some(CmdResult::NeedPoint); @@ -1590,10 +1590,10 @@ pub struct ChamferCommand { } impl ChamferCommand { - pub fn new(dist: f32, all_entities: Vec) -> Self { + pub fn new(dist: f64, all_entities: Vec) -> Self { Self { dist1: dist as f64, - dist2: defaults::get_chamfer_dist2() as f64, + dist2: defaults::get_chamfer_dist2(), step: ChamferStep::First, all_entities, resume_pick: None, @@ -1695,7 +1695,7 @@ impl CadCommand for ChamferCommand { } if let Ok(v) = t.replace(',', ".").parse::() { self.dist1 = v.max(0.0); - defaults::set_chamfer_dist1(self.dist1 as f32); + defaults::set_chamfer_dist1(self.dist1); self.step = ChamferStep::WaitingForDist2; return Some(CmdResult::NeedPoint); } @@ -1711,7 +1711,7 @@ impl CadCommand for ChamferCommand { } if let Ok(v) = t.replace(',', ".").parse::() { self.dist2 = v.max(0.0); - defaults::set_chamfer_dist2(self.dist2 as f32); + defaults::set_chamfer_dist2(self.dist2); self.resume_after_dist(); return Some(CmdResult::NeedPoint); } @@ -1738,14 +1738,14 @@ impl CadCommand for ChamferCommand { if !parts.is_empty() { if let Some(&v) = parts.first() { self.dist1 = v.max(0.0); - defaults::set_chamfer_dist1(self.dist1 as f32); + defaults::set_chamfer_dist1(self.dist1); } if let Some(&v) = parts.get(1) { self.dist2 = v.max(0.0); - defaults::set_chamfer_dist2(self.dist2 as f32); + defaults::set_chamfer_dist2(self.dist2); } else { self.dist2 = self.dist1; - defaults::set_chamfer_dist2(self.dist2 as f32); + defaults::set_chamfer_dist2(self.dist2); } return Some(CmdResult::NeedPoint); } diff --git a/src/modules/draw/modify/offset.rs b/src/modules/draw/modify/offset.rs index e21878353..f0f23d610 100644 --- a/src/modules/draw/modify/offset.rs +++ b/src/modules/draw/modify/offset.rs @@ -779,7 +779,7 @@ impl CadCommand for OffsetCommand { if !t.is_empty() { if let Ok(d) = t.parse::() { let d = d.abs().max(1e-9); - defaults::set_offset_dist(d as f32); + defaults::set_offset_dist(d); *locked = Some(d); } } diff --git a/src/modules/draw/modify/rotate.rs b/src/modules/draw/modify/rotate.rs index fbf772855..7aec475d7 100644 --- a/src/modules/draw/modify/rotate.rs +++ b/src/modules/draw/modify/rotate.rs @@ -37,7 +37,7 @@ pub struct RotateCommand { handles: Vec, wire_models: Vec, step: Step, - default_angle: f32, // degrees + default_angle: f64, // degrees } impl RotateCommand { @@ -90,13 +90,13 @@ impl CadCommand for RotateCommand { let ref_angle = *ref_angle; let dest_angle = (pt.y - center.y).atan2(pt.x - center.x); let delta = dest_angle - ref_angle; - defaults::set_rotate_angle(delta.to_degrees() as f32); - self.default_angle = delta.to_degrees() as f32; + defaults::set_rotate_angle(delta.to_degrees()); + self.default_angle = delta.to_degrees(); CmdResult::TransformSelected( self.handles.clone(), EntityTransform::Rotate { center, - angle_rad: delta as f32, + angle_rad: delta, }, ) } @@ -131,7 +131,7 @@ impl CadCommand for RotateCommand { }; // The value already carries the correct sign (the dynamic-input // layer applies the cursor's side for a bare magnitude). - let deg: f32 = text.trim().replace(',', ".").parse().ok()?; + let deg: f64 = text.trim().replace(',', ".").parse().ok()?; defaults::set_rotate_angle(deg); Some(CmdResult::TransformSelected( self.handles.clone(), @@ -165,7 +165,7 @@ impl CadCommand for RotateCommand { // committing with Enter rotates the way the cursor is dragging — the // dynamic-input box shows the unsigned magnitude, but the committed // value must keep its direction (clockwise = negative). - self.default_angle = angle_rad.to_degrees() as f32; + self.default_angle = angle_rad.to_degrees(); // Object ghosts rotated to the new angle. The rotation sweep arc is // drawn by the dynamic-input overlay (polar guide), not here. self.wire_models diff --git a/src/modules/draw/modify/scale.rs b/src/modules/draw/modify/scale.rs index b212d14a4..19d085fec 100644 --- a/src/modules/draw/modify/scale.rs +++ b/src/modules/draw/modify/scale.rs @@ -37,14 +37,14 @@ enum Step { /// Reference flow: defining the reference length from `base`. RefLen { base: DVec3 }, /// Reference flow: factor is `cursor_dist / ref_dist` from `base`. - RefNew { base: DVec3, ref_dist: f32 }, + RefNew { base: DVec3, ref_dist: f64 }, } pub struct ScaleCommand { handles: Vec, wire_models: Vec, step: Step, - default_factor: f32, + default_factor: f64, } impl ScaleCommand { @@ -58,7 +58,7 @@ impl ScaleCommand { } /// Commit a uniform scale about `base` and end the command. - fn commit(&self, base: DVec3, factor: f32) -> CmdResult { + fn commit(&self, base: DVec3, factor: f64) -> CmdResult { defaults::set_scale_factor(factor); CmdResult::TransformSelected( self.handles.clone(), @@ -112,18 +112,18 @@ impl CadCommand for ScaleCommand { } Step::Factor { base } => { let base = *base; - let factor = base.distance(pt).max(1e-6) as f32; + let factor = base.distance(pt).max(1e-6); self.commit(base, factor) } Step::RefLen { base } => { let base = *base; - let ref_dist = base.distance(pt).max(1e-6) as f32; + let ref_dist = base.distance(pt).max(1e-6); self.step = Step::RefNew { base, ref_dist }; CmdResult::NeedPoint } Step::RefNew { base, ref_dist } => { let base = *base; - let new_dist = base.distance(pt).max(1e-6) as f32; + let new_dist = base.distance(pt).max(1e-6); self.commit(base, new_dist / *ref_dist) } } @@ -152,12 +152,12 @@ impl CadCommand for ScaleCommand { self.step = Step::RefLen { base }; return Some(CmdResult::NeedPoint); } - let factor: f32 = t.replace(',', ".").parse().ok()?; + let factor: f64 = t.replace(',', ".").parse().ok()?; (factor > 0.0).then(|| self.commit(base, factor)) } Step::RefLen { base } => { let base = *base; - let ref_dist: f32 = t.replace(',', ".").parse().ok()?; + let ref_dist: f64 = t.replace(',', ".").parse().ok()?; if ref_dist > 0.0 { self.step = Step::RefNew { base, ref_dist }; return Some(CmdResult::NeedPoint); @@ -166,7 +166,7 @@ impl CadCommand for ScaleCommand { } Step::RefNew { base, ref_dist } => { let (base, ref_dist) = (*base, *ref_dist); - let new_len: f32 = t.replace(',', ".").parse().ok()?; + let new_len: f64 = t.replace(',', ".").parse().ok()?; (new_len > 0.0).then(|| self.commit(base, new_len / ref_dist)) } Step::Base => None, @@ -179,7 +179,7 @@ impl CadCommand for ScaleCommand { Step::Factor { base } => (*base, base.distance(pt).max(1e-6) as f32), // Reference flow, new-length step: factor = cursor_dist / ref_dist. Step::RefNew { base, ref_dist } => { - (*base, base.distance(pt).max(1e-6) as f32 / ref_dist) + (*base, (base.distance(pt).max(1e-6) / ref_dist) as f32) } // Reference-length step: rubber-band only, no factor defined yet. Step::RefLen { base } => { diff --git a/src/modules/insert/solid3d_cmds.rs b/src/modules/insert/solid3d_cmds.rs index 9ed1f6124..0e805899a 100644 --- a/src/modules/insert/solid3d_cmds.rs +++ b/src/modules/insert/solid3d_cmds.rs @@ -61,7 +61,7 @@ impl CadCommand for ExtrudeCommand { self.step = ExtrudeStep::Height; CmdResult::NeedPoint } - fn on_point(&mut self, pt: DVec3) -> CmdResult { let pt = pt.as_vec3(); + fn on_point(&mut self, pt: DVec3) -> CmdResult { if self.step == ExtrudeStep::Height { return CmdResult::ExtrudeEntity { handle: self.target_handle, @@ -76,7 +76,7 @@ impl CadCommand for ExtrudeCommand { } fn on_text_input(&mut self, text: &str) -> Option { text.trim() - .parse::() + .parse::() .ok() .filter(|&h| h.abs() > 1e-6) .map(|h| CmdResult::ExtrudeEntity { diff --git a/src/scene/view/transform.rs b/src/scene/view/transform.rs index 8f3853833..b7e7f73a7 100644 --- a/src/scene/view/transform.rs +++ b/src/scene/view/transform.rs @@ -8,22 +8,22 @@ fn to_v3(v: DVec3) -> Vector3 { Vector3::new(v.x, v.y, v.z) } -pub fn apply_standard_transform(entity: &mut T, center: DVec3, angle_rad: f32) +pub fn apply_standard_transform(entity: &mut T, center: DVec3, angle_rad: f64) where T: acadrust::Entity, { let z_axis = Vector3::new(0.0, 0.0, 1.0); let t = Transform::from_translation(to_v3(-center)) - .then(&Transform::from_rotation(z_axis, angle_rad as f64)) + .then(&Transform::from_rotation(z_axis, angle_rad)) .then(&Transform::from_translation(to_v3(center))); entity.apply_transform(&t); } -pub fn apply_standard_scale(entity: &mut T, center: DVec3, factor: f32) +pub fn apply_standard_scale(entity: &mut T, center: DVec3, factor: f64) where T: acadrust::Entity, { - let s = factor as f64; + let s = factor; let t = Transform::from_scaling_with_origin(Vector3::new(s, s, s), to_v3(center)); entity.apply_transform(&t); }