forked from 1b-agent/opencadstudio-upstream
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 <[email protected]>
This commit is contained in:
1 parent
553b91015f
commit
62bd360e46
12 files changed
+100
-102
No files matched your search
@@ -4,29 +4,29 @@
|
||||
use std::cell::Cell;
|
||||
|
||||
thread_local! {
|
||||
static CIRCLE_RADIUS: Cell<f32> = Cell::new(1.0);
|
||||
static CIRCLE_DIAM: Cell<f32> = Cell::new(2.0);
|
||||
static ROTATE_ANGLE: Cell<f32> = Cell::new(0.0); // degrees
|
||||
static SCALE_FACTOR: Cell<f32> = Cell::new(1.0);
|
||||
static OFFSET_DIST: Cell<f32> = Cell::new(1.0);
|
||||
static FILLET_RADIUS: Cell<f32> = Cell::new(1.0);
|
||||
static CHAMFER_DIST1: Cell<f32> = Cell::new(10.0);
|
||||
static CHAMFER_DIST2: Cell<f32> = Cell::new(10.0);
|
||||
static ARRAY_ROWS: Cell<f32> = Cell::new(2.0);
|
||||
static ARRAY_COLS: Cell<f32> = Cell::new(2.0);
|
||||
static ARRAY_ROW_SP: Cell<f32> = Cell::new(100.0);
|
||||
static ARRAY_COL_SP: Cell<f32> = Cell::new(100.0);
|
||||
static ARRAY_P_COUNT: Cell<f32> = Cell::new(6.0);
|
||||
static ARRAY_P_ANGLE: Cell<f32> = Cell::new(360.0); // degrees
|
||||
static ARRAY_PATH_COUNT: Cell<f32> = Cell::new(6.0);
|
||||
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() -> 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));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<EntityTransform> {
|
||||
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::<u32>().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::<u32>().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::<f32>().unwrap_or(self.default_row_sp);
|
||||
let v = t.parse::<f64>().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::<f32>().unwrap_or(self.default_col_sp);
|
||||
let v = t.parse::<f64>().unwrap_or(self.default_col_sp);
|
||||
defaults::set_array_col_sp(v);
|
||||
v
|
||||
};
|
||||
@@ -255,7 +255,7 @@ pub struct ArrayPolarCommand {
|
||||
wire_models: Vec<WireModel>,
|
||||
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::<u32>().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::<f32>().unwrap_or(self.default_angle);
|
||||
let v = t.parse::<f64>().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<WireModel> = (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::<u32>().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<_>>(),
|
||||
_ => 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<EntityTransform> {
|
||||
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)
|
||||
|
||||
@@ -1211,7 +1211,7 @@ pub struct FilletCommand {
|
||||
}
|
||||
|
||||
impl FilletCommand {
|
||||
pub fn new(radius: f32, all_entities: Vec<EntityType>) -> Self {
|
||||
pub fn new(radius: f64, all_entities: Vec<EntityType>) -> Self {
|
||||
Self {
|
||||
radius: radius as f64,
|
||||
step: FilletStep::First,
|
||||
@@ -1298,7 +1298,7 @@ impl CadCommand for FilletCommand {
|
||||
if let Ok(v) = t.replace(',', ".").parse::<f64>() {
|
||||
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::<f64>() {
|
||||
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<EntityType>) -> Self {
|
||||
pub fn new(dist: f64, all_entities: Vec<EntityType>) -> 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::<f64>() {
|
||||
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::<f64>() {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -779,7 +779,7 @@ impl CadCommand for OffsetCommand {
|
||||
if !t.is_empty() {
|
||||
if let Ok(d) = t.parse::<f64>() {
|
||||
let d = d.abs().max(1e-9);
|
||||
defaults::set_offset_dist(d as f32);
|
||||
defaults::set_offset_dist(d);
|
||||
*locked = Some(d);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ pub struct RotateCommand {
|
||||
handles: Vec<Handle>,
|
||||
wire_models: Vec<WireModel>,
|
||||
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
|
||||
|
||||
@@ -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<Handle>,
|
||||
wire_models: Vec<WireModel>,
|
||||
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 } => {
|
||||
|
||||
@@ -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<CmdResult> {
|
||||
text.trim()
|
||||
.parse::<f32>()
|
||||
.parse::<f64>()
|
||||
.ok()
|
||||
.filter(|&h| h.abs() > 1e-6)
|
||||
.map(|h| CmdResult::ExtrudeEntity {
|
||||
|
||||
Reference in new issue
Block a user