forked from 1b-agent/opencadstudio-upstream
style: apply cargo fmt across workspace
This commit is contained in:
1 parent
85710e5454
commit
9cf9ff2c5c
531 files changed
+57740
-33906
No files matched your search
+42
-42
@@ -4,13 +4,12 @@
|
||||
use super::util::*;
|
||||
use super::{format_size, VIEWCUBE_HIT_SIZE};
|
||||
use crate::app::helpers::{
|
||||
parse_coord, polar_constrain_near, ucs_rotate_vec, ucs_to_wcs, ucs_z_axis,
|
||||
CoordKind,
|
||||
parse_coord, polar_constrain_near, ucs_rotate_vec, ucs_to_wcs, ucs_z_axis, CoordKind,
|
||||
};
|
||||
use crate::app::{Message, OpenCADStudio, POLY_START_DELAY_MS};
|
||||
use crate::modules::ModuleEvent;
|
||||
use crate::scene::pick::grip::{find_hit_grip, find_hit_grip_paper, find_hit_grip_rte, GripEdit};
|
||||
use crate::scene::model::object::GripApply;
|
||||
use crate::scene::pick::grip::{find_hit_grip, find_hit_grip_paper, find_hit_grip_rte, GripEdit};
|
||||
use crate::scene::{
|
||||
self, hover_id, CubeRegion, Scene, VIEWCUBE_DRAW_PX, VIEWCUBE_PAD, VIEWCUBE_PX,
|
||||
};
|
||||
@@ -83,9 +82,7 @@ impl OpenCADStudio {
|
||||
.active_grip
|
||||
.as_ref()
|
||||
.map(|grip| match grip.mode {
|
||||
crate::scene::pick::grip::GripEditMode::Stretch => {
|
||||
(grip.origin_world, None)
|
||||
}
|
||||
crate::scene::pick::grip::GripEditMode::Stretch => (grip.origin_world, None),
|
||||
crate::scene::pick::grip::GripEditMode::Lengthen => {
|
||||
(grip.origin_world, Some(crate::command::DynRole::Distance))
|
||||
}
|
||||
@@ -111,10 +108,18 @@ impl OpenCADStudio {
|
||||
|
||||
if let Some((origin, scalar_role)) = grip_input {
|
||||
let wanted_roles: Vec<crate::command::DynRole> = if rectangle_frame.is_some() {
|
||||
vec![crate::command::DynRole::Width, crate::command::DynRole::Height]
|
||||
vec![
|
||||
crate::command::DynRole::Width,
|
||||
crate::command::DynRole::Height,
|
||||
]
|
||||
} else {
|
||||
scalar_role.map_or_else(
|
||||
|| vec![crate::command::DynRole::Distance, crate::command::DynRole::Angle],
|
||||
|| {
|
||||
vec![
|
||||
crate::command::DynRole::Distance,
|
||||
crate::command::DynRole::Angle,
|
||||
]
|
||||
},
|
||||
|role| vec![role],
|
||||
)
|
||||
};
|
||||
@@ -259,8 +264,11 @@ impl OpenCADStudio {
|
||||
}
|
||||
// Derive the guide + anchor for the legacy field set so the overlay
|
||||
// draws the right construction without each command opting in.
|
||||
let comps: Vec<DynComponent> =
|
||||
self.tabs[i].dyn_fields.iter().map(|f| f.component).collect();
|
||||
let comps: Vec<DynComponent> = self.tabs[i]
|
||||
.dyn_fields
|
||||
.iter()
|
||||
.map(|f| f.component)
|
||||
.collect();
|
||||
self.tabs[i].dyn_guide = match comps.as_slice() {
|
||||
[DynComponent::Distance, DynComponent::Angle] | [DynComponent::Angle] => {
|
||||
crate::command::DynGuide::Polar
|
||||
@@ -278,13 +286,15 @@ impl OpenCADStudio {
|
||||
|
||||
pub(in crate::app) fn apply_dyn_spec(&mut self, i: usize, spec: crate::command::DynSpec) {
|
||||
use crate::app::document::DynFieldEntry;
|
||||
let new_roles: Vec<crate::command::DynRole> =
|
||||
spec.fields.iter().map(|f| f.role).collect();
|
||||
let new_roles: Vec<crate::command::DynRole> = spec.fields.iter().map(|f| f.role).collect();
|
||||
let cur_roles: Vec<crate::command::DynRole> =
|
||||
self.tabs[i].dyn_fields.iter().map(|f| f.role).collect();
|
||||
if cur_roles != new_roles {
|
||||
self.tabs[i].dyn_fields =
|
||||
spec.fields.iter().map(|f| DynFieldEntry::from_role(f.role)).collect();
|
||||
self.tabs[i].dyn_fields = spec
|
||||
.fields
|
||||
.iter()
|
||||
.map(|f| DynFieldEntry::from_role(f.role))
|
||||
.collect();
|
||||
self.tabs[i].dyn_active = 0;
|
||||
}
|
||||
self.tabs[i].dyn_guide = spec.guide;
|
||||
@@ -394,12 +404,12 @@ impl OpenCADStudio {
|
||||
let dz = d_ucs.z;
|
||||
let live_d = (dx * dx + dy * dy).sqrt();
|
||||
let live_a = dy.atan2(dx); // radians, in the UCS plane
|
||||
// A typed angle is shown unsigned (0..180); give it the sign of the
|
||||
// cursor's current side so an entry made below the X axis sweeps
|
||||
// downward to match the arc instead of mirroring up. An EXPLICIT
|
||||
// `-`/`+` prefix keeps its literal sign though — "-30" must mean
|
||||
// −30° (= 330°) regardless of where the cursor sits (#417).
|
||||
// Untyped → live.
|
||||
// A typed angle is shown unsigned (0..180); give it the sign of the
|
||||
// cursor's current side so an entry made below the X axis sweeps
|
||||
// downward to match the arc instead of mirroring up. An EXPLICIT
|
||||
// `-`/`+` prefix keeps its literal sign though — "-30" must mean
|
||||
// −30° (= 330°) regardless of where the cursor sits (#417).
|
||||
// Untyped → live.
|
||||
let angle_rad = |idx: usize| -> f64 {
|
||||
let raw = fields[idx]
|
||||
.buffer
|
||||
@@ -420,9 +430,7 @@ impl OpenCADStudio {
|
||||
// perpendicular through the anchor at that offset; the command projects
|
||||
// it. Untyped tracks the cursor's signed offset; typed takes the
|
||||
// cursor's side.
|
||||
if let (Some(ref_pt), [DynComponent::Distance]) =
|
||||
(self.tabs[i].dyn_ref, comps.as_slice())
|
||||
{
|
||||
if let (Some(ref_pt), [DynComponent::Distance]) = (self.tabs[i].dyn_ref, comps.as_slice()) {
|
||||
let axis = (ref_pt - base).normalize_or_zero();
|
||||
let perp = glam::DVec3::new(-axis.y, axis.x, 0.0);
|
||||
let signed = (w - base).dot(perp);
|
||||
@@ -449,22 +457,14 @@ impl OpenCADStudio {
|
||||
Some(rel(glam::DVec3::new(val(0, dx), val(1, dy), 0.0)))
|
||||
}
|
||||
[DynComponent::X, DynComponent::Y] => {
|
||||
Some(xf.to_wcs(glam::DVec3::new(
|
||||
val(0, w_ucs.x),
|
||||
val(1, w_ucs.y),
|
||||
0.0,
|
||||
)))
|
||||
Some(xf.to_wcs(glam::DVec3::new(val(0, w_ucs.x), val(1, w_ucs.y), 0.0)))
|
||||
}
|
||||
[DynComponent::X, DynComponent::Y, DynComponent::Z] if relative => {
|
||||
Some(rel(glam::DVec3::new(val(0, dx), val(1, dy), val(2, dz))))
|
||||
}
|
||||
[DynComponent::X, DynComponent::Y, DynComponent::Z] => {
|
||||
Some(xf.to_wcs(glam::DVec3::new(
|
||||
val(0, w_ucs.x),
|
||||
val(1, w_ucs.y),
|
||||
val(2, w_ucs.z),
|
||||
)))
|
||||
}
|
||||
[DynComponent::X, DynComponent::Y, DynComponent::Z] => Some(xf.to_wcs(
|
||||
glam::DVec3::new(val(0, w_ucs.x), val(1, w_ucs.y), val(2, w_ucs.z)),
|
||||
)),
|
||||
[DynComponent::Distance, DynComponent::Angle] => {
|
||||
let d = val(0, live_d);
|
||||
let a = angle_rad(1);
|
||||
@@ -485,7 +485,11 @@ impl OpenCADStudio {
|
||||
.as_deref()
|
||||
.and_then(eval_dynamic_angle)
|
||||
.unwrap_or(live_a);
|
||||
Some(rel(glam::DVec3::new(live_d * a.cos(), live_d * a.sin(), 0.0)))
|
||||
Some(rel(glam::DVec3::new(
|
||||
live_d * a.cos(),
|
||||
live_d * a.sin(),
|
||||
0.0,
|
||||
)))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
@@ -641,7 +645,6 @@ impl OpenCADStudio {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub(in crate::app) fn try_dyn_commit(&mut self) -> Option<Task<Message>> {
|
||||
let i = self.active_tab;
|
||||
if !self.dyn_input
|
||||
@@ -819,16 +822,13 @@ mod tests {
|
||||
context.aunits = 2;
|
||||
set_unit_context(context);
|
||||
assert!(
|
||||
(eval_dynamic_angle("2 * 50").unwrap() - std::f64::consts::FRAC_PI_2).abs()
|
||||
< 1e-12
|
||||
(eval_dynamic_angle("2 * 50").unwrap() - std::f64::consts::FRAC_PI_2).abs() < 1e-12
|
||||
);
|
||||
|
||||
context.aunits = 3;
|
||||
set_unit_context(context);
|
||||
assert!(
|
||||
(eval_dynamic_angle("1.5707963267948966").unwrap()
|
||||
- std::f64::consts::FRAC_PI_2)
|
||||
.abs()
|
||||
(eval_dynamic_angle("1.5707963267948966").unwrap() - std::f64::consts::FRAC_PI_2).abs()
|
||||
< 1e-12
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user