Skip to content

Commit 28e289b

Browse files
author
Tom
committed
Move length constraint ref coords to own struct
1 parent 0f8a3b9 commit 28e289b

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

detailer/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use drawing::{handler::ToolResponse, tools, Data, Feature, FeatureKey, Handler};
2-
use drawing::{Constraint, ConstraintKey};
2+
use drawing::{Constraint, ConstraintKey, DimensionDisplay};
33

44
#[derive(Debug, Default, Clone, PartialEq)]
55
pub enum Tab {
@@ -113,14 +113,14 @@ impl<'a> Widget<'a> {
113113
y,
114114
)
115115
}
116-
Some(Constraint::LineLength(_, _, d, ref_pt)) => {
116+
Some(Constraint::LineLength(_, _, d, dd)) => {
117117
Widget::show_constraint_line_length(
118118
ui,
119119
&mut commands,
120120
&mut changed,
121121
&ck,
122122
d,
123-
ref_pt,
123+
dd,
124124
)
125125
}
126126
Some(Constraint::LineAlongCardinal(
@@ -186,7 +186,7 @@ impl<'a> Widget<'a> {
186186
changed: &mut bool,
187187
k: &ConstraintKey,
188188
d: &mut f32,
189-
_ref_pt: &mut (f32, f32),
189+
_ref_pt: &mut DimensionDisplay,
190190
) {
191191
ui.horizontal(|ui| {
192192
let r = ui.available_size();

drawing/src/constraints.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ slotmap::new_key_type! {
1010
#[derive(Debug, Clone, Default, serde::Deserialize, serde::Serialize, PartialEq)]
1111
pub struct ConstraintMeta {}
1212

13+
#[derive(Debug, Clone, Default, serde::Deserialize, serde::Serialize, PartialEq)]
14+
pub struct DimensionDisplay {
15+
pub(crate) x: f32,
16+
pub(crate) y: f32,
17+
}
18+
1319
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
1420
pub enum Constraint {
1521
Fixed(ConstraintMeta, FeatureKey, f32, f32),
16-
LineLength(ConstraintMeta, FeatureKey, f32, (f32, f32)),
22+
LineLength(ConstraintMeta, FeatureKey, f32, DimensionDisplay),
1723
LineAlongCardinal(ConstraintMeta, FeatureKey, bool), // true = horizontal
1824
}
1925

@@ -55,7 +61,7 @@ impl Constraint {
5561
use Constraint::{Fixed, LineAlongCardinal, LineLength};
5662
match self {
5763
Fixed(..) => None,
58-
LineLength(_, fk, _, (ref_x, ref_y)) => {
64+
LineLength(_, fk, _, dd) => {
5965
if let Some(Feature::LineSegment(_, f1, f2)) = drawing.features.get(*fk) {
6066
let (a, b) = match (
6167
drawing.features.get(*f1).unwrap(),
@@ -67,7 +73,7 @@ impl Constraint {
6773
_ => panic!("unexpected subkey types: {:?} & {:?}", f1, f2),
6874
};
6975

70-
let reference = egui::Vec2::new(*ref_x, *ref_y);
76+
let reference = egui::Vec2::new(dd.x, dd.y);
7177
let t = (a - b).angle() + reference.angle();
7278
let text_center = vp.translate_point(a.lerp(b, 0.5))
7379
+ egui::Vec2::angled(t) * reference.length();
@@ -123,7 +129,7 @@ impl Constraint {
123129
};
124130
}
125131

126-
LineLength(_, k, d, (ref_x, ref_y)) => {
132+
LineLength(_, k, d, dd) => {
127133
if let Some(Feature::LineSegment(_, f1, f2)) = drawing.features.get(*k) {
128134
let (a, b) = match (
129135
drawing.features.get(*f1).unwrap(),
@@ -139,7 +145,7 @@ impl Constraint {
139145
a,
140146
b,
141147
val: &format!("{:.3}", d),
142-
reference: egui::Vec2::new(*ref_x, *ref_y),
148+
reference: egui::Vec2::new(dd.x, dd.y),
143149
hovered: params.hovered,
144150
selected: params.selected,
145151
}

drawing/src/data/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,12 @@ impl Data {
292292
}
293293
};
294294

295-
if let Some(Constraint::LineLength(_, fk, _, (ref_x, ref_y))) = self.constraint_mut(k) {
295+
if let Some(Constraint::LineLength(_, fk, _, dd)) = self.constraint_mut(k) {
296296
let c = a.lerp(b, 0.5);
297297
let v = c.to_vec2() - pos.to_vec2();
298298
let reference = egui::Vec2::angled((a - b).angle() - v.angle()) * v.length();
299-
*ref_x = -reference.x;
300-
*ref_y = reference.y;
299+
dd.x = -reference.x;
300+
dd.y = reference.y;
301301
};
302302
}
303303
}

drawing/src/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{Data, Feature, FeatureKey, FeatureMeta};
22
use crate::tools::Toolbar;
3-
use crate::{Constraint, ConstraintKey, ConstraintMeta};
3+
use crate::{Constraint, ConstraintKey, ConstraintMeta, DimensionDisplay};
44

55
#[derive(Debug)]
66
pub enum ToolResponse {
@@ -92,7 +92,7 @@ impl Handler {
9292
ConstraintMeta::default(),
9393
k,
9494
d,
95-
(0., 35.0),
95+
DimensionDisplay { x: 0., y: 35.0 },
9696
));
9797

9898
tools.clear();

drawing/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub use data::{Data, Hover, Viewport};
77
mod feature;
88
pub use feature::{Feature, FeatureKey, FeatureMeta};
99
mod constraints;
10-
pub use constraints::{Constraint, ConstraintKey, ConstraintMeta};
10+
pub use constraints::{Constraint, ConstraintKey, ConstraintMeta, DimensionDisplay};
1111
pub mod handler;
1212
mod system;
1313
pub use handler::Handler;
@@ -139,9 +139,10 @@ impl<'a> Widget<'a> {
139139
} => None,
140140
Hover::Constraint {
141141
k,
142-
constraint: Constraint::LineLength(_, _, _, (x, y)),
142+
constraint: Constraint::LineLength(_, _, _, dd),
143143
} => {
144-
let offset = self.drawing.vp.screen_to_point(hp) - egui::Pos2::new(*x, *y);
144+
let offset =
145+
self.drawing.vp.screen_to_point(hp) - egui::Pos2::new(dd.x, dd.y);
145146
let state = DragState::Constraint(*k, offset);
146147
ui.memory_mut(|mem| mem.data.insert_temp(select_id, state));
147148
Some(state)

0 commit comments

Comments
 (0)