Skip to content

Commit 0f8a3b9

Browse files
author
Tom
committed
Lil improvements
1 parent d7599df commit 0f8a3b9

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

detailer/src/lib.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ impl<'a> Widget<'a> {
198198
*changed |= ui
199199
.add_sized([50., text_height * 1.4], egui::DragValue::new(d))
200200
.changed();
201+
202+
if *changed && *d < 0. {
203+
*d = 0.;
204+
}
205+
201206
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
202207
if ui.button("⊗").clicked() {
203208
commands.push(ToolResponse::ConstraintDelete(*k));
@@ -229,9 +234,16 @@ impl<'a> Widget<'a> {
229234
.rect;
230235
ui.add_space(r.x / 2. - text_rect.width() - ui.spacing().item_spacing.x);
231236

232-
// *changed |= ui
233-
// .add_sized([50., text_height * 1.4], egui::DragValue::new(d))
234-
// .changed();
237+
let resp = ui.add_sized(
238+
[100. + ui.spacing().item_spacing.x, text_height * 1.4],
239+
egui::Button::new("swap direction"),
240+
);
241+
242+
if resp.clicked() {
243+
*changed |= true;
244+
*is_horizontal = !*is_horizontal;
245+
}
246+
235247
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
236248
if ui.button("⊗").clicked() {
237249
commands.push(ToolResponse::ConstraintDelete(*k));

drawing/src/data/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Data {
9494
if num_solutions == 1 {
9595
let f = expr.evaluate(sub_solver_state, 0).unwrap().as_f64();
9696
self.apply_solved(&term, f);
97-
} else if num_solutions < 8 {
97+
} else if num_solutions <= 32 {
9898
let current = match self.term_current_value(&term) {
9999
Some(f) => f as f64,
100100
None => {
@@ -198,6 +198,10 @@ impl Data {
198198
}
199199

200200
fn apply_solved(&mut self, term: &TermRef, v: f64) -> bool {
201+
if v.is_nan() || v.is_infinite() {
202+
return false;
203+
}
204+
201205
if let Some(feature) = term.for_feature {
202206
match self.features.get_mut(feature) {
203207
Some(Feature::Point(_, x, y)) => {

drawing/src/l/draw.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,19 @@ impl<'a> DimensionLengthOverlay<'a> {
9292
}
9393

9494
fn draw_stop_lines(&self, t: f32, sa: egui::Pos2, sb: egui::Pos2, painter: &egui::Painter) {
95-
let l = self.reference.length();
95+
let l = egui::Vec2::angled(std::f32::consts::PI / 2.).dot(self.reference);
96+
let t = t - self.reference.angle() + std::f32::consts::PI / 2.;
97+
98+
let offset = if l >= 0. {
99+
DimensionLengthOverlay::LINE_STOP_OFFSET
100+
} else {
101+
-DimensionLengthOverlay::LINE_STOP_OFFSET
102+
};
96103

97104
painter.line_segment(
98105
[
99106
sa + egui::Vec2::angled(t) * l,
100-
sa + egui::Vec2::angled(t) * DimensionLengthOverlay::LINE_STOP_OFFSET,
107+
sa + egui::Vec2::angled(t) * offset,
101108
],
102109
egui::Stroke {
103110
width: 1.,
@@ -107,7 +114,7 @@ impl<'a> DimensionLengthOverlay<'a> {
107114
painter.line_segment(
108115
[
109116
sb + egui::Vec2::angled(t) * l,
110-
sb + egui::Vec2::angled(t) * DimensionLengthOverlay::LINE_STOP_OFFSET,
117+
sb + egui::Vec2::angled(t) * offset,
111118
],
112119
egui::Stroke {
113120
width: 1.,

eq/src/solve.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl SubSolver {
202202
if out.expr.num_solutions() == 1 {
203203
let cc = out.expr.evaluate(st, 0).unwrap();
204204
match cc {
205-
Concrete::Float(ref f) if !f.is_nan() => {
205+
Concrete::Float(ref f) if !f.is_nan() && !f.is_infinite() => {
206206
st.resolved
207207
.insert(var.clone(), SolvePlan::Concrete(cc.clone()));
208208
return Ok(SolvePlan::Concrete(cc));
@@ -339,6 +339,8 @@ impl SubSolver {
339339
}
340340
}
341341
}
342+
// TODO: Sometimes the substitutions are such that there's a ton of possible solutions.
343+
// Maybe we can try and find better substitutions in those cases?
342344

343345
for v in vars {
344346
if let Some(p) = st.resolved.get(&v).clone() {

0 commit comments

Comments
 (0)