From 5e6a4d31c7dd36f8f75d593a0852ac9ce5279d35 Mon Sep 17 00:00:00 2001 From: william-wwh Date: Sat, 24 Oct 2026 10:35:24 +0800 Subject: [PATCH 1/9] ci: add dispatch-only FreeBSD cross-compile validation workflow Calls william-wwh/craft-common-actions/.github/workflows/freebsd-cross.yml @ci/freebsd-cross-final for both x86_64 and aarch64. workflow_dispatch only, so pushing to main never starts it. cold-start defaults to true: the Cargo cache restore is skipped so the build starts empty, while the resulting artifacts are still saved. The branch is reset to upstream 7bf5905 first, so this runs against the current main code, including the harfrust 0.14 port. --- .github/workflows/test-common-actions.yml | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/test-common-actions.yml diff --git a/.github/workflows/test-common-actions.yml b/.github/workflows/test-common-actions.yml new file mode 100644 index 0000000000..a288fb06f0 --- /dev/null +++ b/.github/workflows/test-common-actions.yml @@ -0,0 +1,27 @@ +# FreeBSD cross-compile and real aarch64 test execution for cadcraft. +# Points at william-wwh/craft-common-actions@ci/freebsd-cross-final, the fork branch +# under evaluation. Dispatch-only: pushing to any branch never starts a run, so the +# default branch stays quiet while the per-binary timeout profile is collected. +name: FreeBSD Cross Validation + +on: + workflow_dispatch: + inputs: + cold-start: + description: "Skip the Cargo cache restore so the build starts from an empty target/ (the fresh artifacts are still saved)" + type: boolean + default: true + +permissions: + contents: read + +jobs: + freebsd-cross: + uses: william-wwh/craft-common-actions/.github/workflows/freebsd-cross.yml@ci/freebsd-cross-final + with: + architectures: '["x86_64","aarch64"]' + cold-start: ${{ inputs.cold-start }} + require-craft-fonts: false + skip-tests: false + run-package-check: false + craft-fonts-ref: 3d9ab3a132ed0eff457e424226a435a901da30d3 From 63ec2ec03c3652bd58ec4063d17e2c7715d89fa2 Mon Sep 17 00:00:00 2001 From: william-wwh <60587573+william-wwh@users.noreply.github.com> Date: Tue, 13 Oct 2026 22:51:08 +0800 Subject: [PATCH 2/9] Input: PointInput layer; LINE resolves deferred TAN first point from typed polar --- crates/engine/src/cmd/annotate.rs | 53 +++++--- crates/engine/src/cmd/annotate_dimedit.rs | 20 +-- crates/engine/src/cmd/annotate_qdim.rs | 11 +- crates/engine/src/cmd/annotate_tedit.rs | 5 +- crates/engine/src/cmd/array.rs | 39 ++++-- crates/engine/src/cmd/array/edit.rs | 25 ++-- crates/engine/src/cmd/blocks.rs | 23 ++-- crates/engine/src/cmd/blocks/dyngrip.rs | 5 +- crates/engine/src/cmd/blocks/extract.rs | 3 +- crates/engine/src/cmd/constraints.rs | 6 +- crates/engine/src/cmd/constraints_tests.rs | 24 ++-- crates/engine/src/cmd/draw.rs | 71 ++++++----- crates/engine/src/cmd/draw2.rs | 111 +++++++++++------ crates/engine/src/cmd/draw2/mline.rs | 6 +- crates/engine/src/cmd/edit.rs | 9 +- crates/engine/src/cmd/griphot.rs | 21 ++-- crates/engine/src/cmd/hatch.rs | 12 +- crates/engine/src/cmd/hatch/edit.rs | 2 +- crates/engine/src/cmd/hatch/pick.rs | 6 +- crates/engine/src/cmd/inquiry.rs | 17 ++- crates/engine/src/cmd/inquiry/count.rs | 3 +- crates/engine/src/cmd/layout/viewports.rs | 37 ++++-- crates/engine/src/cmd/layout/vplayer.rs | 6 +- crates/engine/src/cmd/machines.rs | 4 +- crates/engine/src/cmd/mleader_edit.rs | 10 +- crates/engine/src/cmd/mleader_edit_tests.rs | 10 +- crates/engine/src/cmd/modify.rs | 115 +++++++++++------- crates/engine/src/cmd/modify2.rs | 46 ++++--- crates/engine/src/cmd/modify2/pedit_vertex.rs | 5 +- crates/engine/src/cmd/modify2/splinedit.rs | 8 +- crates/engine/src/cmd/modify2_tests.rs | 2 +- crates/engine/src/cmd/mtext_opts.rs | 22 ++-- crates/engine/src/cmd/pline_opts.rs | 20 ++- crates/engine/src/cmd/plotters.rs | 6 +- crates/engine/src/cmd/settings/iso.rs | 8 +- crates/engine/src/cmd/spline_opts.rs | 3 +- crates/engine/src/cmd/table.rs | 5 +- crates/engine/src/cmd/table/breaks.rs | 3 +- crates/engine/src/cmd/table/cells.rs | 6 +- crates/engine/src/cmd/tolerance.rs | 3 +- crates/engine/src/cmd/trimextend.rs | 11 +- crates/engine/src/cmd/utility.rs | 3 +- crates/engine/src/cmd/view.rs | 37 +++--- crates/engine/src/cmd/view/named_views.rs | 6 +- crates/engine/src/guard.rs | 6 +- crates/engine/src/lib.rs | 37 +++--- crates/engine/src/lisp/drawing.rs | 4 +- crates/engine/src/lisp/input.rs | 5 +- crates/engine/src/lisp/tests.rs | 6 +- crates/engine/src/pointmod.rs | 9 +- crates/engine/src/prompt.rs | 71 +++++++---- crates/engine/src/snap.rs | 3 +- crates/engine/src/tests.rs | 10 +- crates/ui-egui/src/canvas.rs | 16 ++- crates/ui-egui/src/control.rs | 4 +- crates/ui-egui/src/dialogs.rs | 2 +- crates/ui-egui/src/grip_dyn.rs | 6 +- crates/ui-egui/src/hatchdlg.rs | 6 +- crates/ui-egui/src/mtext_editor.rs | 4 +- 59 files changed, 660 insertions(+), 377 deletions(-) diff --git a/crates/engine/src/cmd/annotate.rs b/crates/engine/src/cmd/annotate.rs index b1c732c2c7..ef5a9153d3 100644 --- a/crates/engine/src/cmd/annotate.rs +++ b/crates/engine/src/cmd/annotate.rs @@ -10,7 +10,7 @@ use serde_json::{Value, json}; use super::helpers::v3; use super::machines::{SelOutcome, SelectPhase, SelectRun}; use super::*; -use crate::{Accept, EngineError, Input, Interactive, LeaderOrder, MLeaderOptions, Prompt, Result, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, LeaderOrder, MLeaderOptions, PointInput, Prompt, Result, Session, Step}; pub fn specs() -> Vec { vec![ @@ -1019,7 +1019,8 @@ impl Interactive for LinearM { return Ok(Step::Continue); } if self.selecting { - if let Input::Point(p) = i { + if let Input::Point(pi) = i { + let p = pi.point(); let Some(h) = pick_at(s, p) else { s.echo("*Invalid selection*"); return Ok(Step::Continue); @@ -1048,11 +1049,13 @@ impl Interactive for LinearM { self.selecting = true; Ok(Step::Continue) } - (n, Input::Point(p)) if n < 2 => { + (n, Input::Point(pi)) if n < 2 => { + let p = pi.point(); self.pts.push(p); Ok(Step::Continue) } - (_, Input::Point(at)) => { + (_, Input::Point(pi)) => { + let at = pi.point(); let (Some(&a), Some(&b)) = (self.pts.first(), self.pts.get(1)) else { return Ok(Step::Continue) }; let k = self.text.apply(dim(s, linear_kind(a, b, at, self.rotation, self.aligned), at, a, b, Vec2::ZERO, Vec2::ZERO, "")); add_dim(s, k)?; @@ -1126,14 +1129,16 @@ impl Interactive for RadialM { return Ok(Step::Continue); } match (self.target, i) { - (None, Input::Point(p)) => { + (None, Input::Point(pi)) => { + let p = pi.point(); match pick_at(s, p).and_then(|h| circle_of(s, h)) { Some(t) => self.target = Some(t), None => s.echo("Object selected is not a circle or arc."), } Ok(Step::Continue) } - (Some((c, r)), Input::Point(at)) => { + (Some((c, r)), Input::Point(pi)) => { + let at = pi.point(); let k = self.kind(s, c, r, at); add_dim(s, k)?; Ok(Step::Done) @@ -1221,7 +1226,8 @@ impl Interactive for AngularM { return Ok(Step::Continue); } if self.asking_quadrant { - if let Input::Point(q) = i { + if let Input::Point(pi) = i { + let q = pi.point(); self.quadrant = Some(q); } self.asking_quadrant = false; @@ -1229,7 +1235,8 @@ impl Interactive for AngularM { } if let Some((v, a, b)) = self.geometry() { return match i { - Input::Point(at) => { + Input::Point(pi) => { + let at = pi.point(); let at = self.located(v, at); let k = match (self.handles.as_slice(), self.arc) { ([h1, h2], None) => angular_from_lines(s, *h1, *h2, at), @@ -1253,7 +1260,10 @@ impl Interactive for AngularM { } if self.vertex { match i { - Input::Point(p) => self.vertex_mode.push(p), + Input::Point(pi) => { + let p = pi.point(); + self.vertex_mode.push(p) + } Input::Enter => return Ok(Step::Cancel), _ => {} } @@ -1264,7 +1274,8 @@ impl Interactive for AngularM { self.vertex = true; Ok(Step::Continue) } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let Some(h) = pick_at(s, p) else { s.echo("*Invalid selection*"); return Ok(Step::Continue); @@ -1359,8 +1370,8 @@ impl Interactive for ArcLenM { } if let Some(picked) = self.partial.take() { match (i, picked.first().copied(), self.arc) { - (Input::Point(p), None, _) => self.partial = Some(vec![p]), - (Input::Point(q), Some(p), Some(g)) => match arc_part(&g, p, q) { + (Input::Point(PointInput::Picked(p)), None, _) => self.partial = Some(vec![p]), + (Input::Point(PointInput::Picked(q)), Some(p), Some(g)) => match arc_part(&g, p, q) { Some(part) => self.arc = Some(part), None => s.echo("The two points must be different."), }, @@ -1370,7 +1381,8 @@ impl Interactive for ArcLenM { return Ok(Step::Continue); } match (self.arc, i) { - (None, Input::Point(p)) => { + (None, Input::Point(pi)) => { + let p = pi.point(); if let Some(EntityKind::Arc(a)) = pick_at(s, p).and_then(|h| s.doc().ok()?.entity(h).map(|e| e.kind.clone())) { self.arc = Some(cadcraft_geom::Arc::new(a.center.xy(), a.radius, a.start, a.end)); } else { @@ -1378,7 +1390,8 @@ impl Interactive for ArcLenM { } Ok(Step::Continue) } - (Some(g), Input::Point(at)) => { + (Some(g), Input::Point(pi)) => { + let at = pi.point(); add_dim(s, self.text.apply(dim(s, DimKind::ArcLength, at, g.start_point(), g.end_point(), g.center, Vec2::ZERO, "")))?; Ok(Step::Done) } @@ -1438,7 +1451,8 @@ impl Interactive for OrdinateM { return Ok(Step::Continue); } match (self.feature, i) { - (None, Input::Point(p)) => { + (None, Input::Point(pi)) => { + let p = pi.point(); self.feature = Some(p); Ok(Step::Continue) } @@ -1452,7 +1466,8 @@ impl Interactive for OrdinateM { } Ok(Step::Continue) } - (Some(f), Input::Point(l)) => { + (Some(f), Input::Point(pi)) => { + let l = pi.point(); add_dim(s, self.kind(s, f, l))?; Ok(Step::Done) } @@ -1495,7 +1510,8 @@ impl Interactive for ChainM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let prev = last_linear(s).ok_or_else(|| EngineError::Other("no linear dimension".into()))?; let k = chained(s, &prev, p, self.baseline); self.created.push(add_dim(s, k)?); @@ -1786,7 +1802,8 @@ impl Interactive for MLeaderM { return if self.leader_done { self.finish(s) } else { Ok(Step::Continue) }; } match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let p = self.constrained(p); self.pts.push(p); if self.pts.len() >= self.max_points || self.no_leader() { diff --git a/crates/engine/src/cmd/annotate_dimedit.rs b/crates/engine/src/cmd/annotate_dimedit.rs index 19538e0d59..af0f66d4a9 100644 --- a/crates/engine/src/cmd/annotate_dimedit.rs +++ b/crates/engine/src/cmd/annotate_dimedit.rs @@ -7,7 +7,7 @@ use serde_json::{Value, json}; use super::machines::{SelOutcome, SelectPhase}; use super::*; -use crate::{Accept, Input, Interactive, Prompt, Result, Session, Step}; +use crate::{Accept, Input, Interactive, PointInput, Prompt, Result, Session, Step}; /// Most objects DIMBREAK Auto looks at, and most breaks it adds to one dimension. const MAX_BREAK_OBJECTS: usize = 20_000; @@ -329,16 +329,17 @@ impl Interactive for JoggedM { return Ok(Step::Continue); } match (self.circle, self.center, self.at, i) { - (None, _, _, Input::Point(p)) => match pick_at(s, p).and_then(|h| circle_of(s, h)) { + (None, _, _, Input::Point(PointInput::Picked(p))) => match pick_at(s, p).and_then(|h| circle_of(s, h)) { Some(t) => self.circle = Some(t), None => s.echo("Object selected is not a circle or arc."), }, - (Some(_), None, _, Input::Point(p)) => self.center = Some(p), + (Some(_), None, _, Input::Point(pi)) => self.center = Some(pi.point()), (Some(_), Some(_), None, Input::Keyword(k)) => { self.text.keyword(&k); } - (Some(_), Some(_), None, Input::Point(p)) => self.at = Some(p), - (Some((c, r)), Some(o), Some(at), Input::Point(j)) => { + (Some(_), Some(_), None, Input::Point(pi)) => self.at = Some(pi.point()), + (Some((c, r)), Some(o), Some(at), Input::Point(pi)) => { + let j = pi.point(); if let Some(k) = jogged_kind(s, c, r, o, at, Some(j), "") { add_dim(s, self.text.apply(k))?; } @@ -432,7 +433,8 @@ impl Interactive for JogLineM { None => s.echo("Select a linear or aligned dimension."), } } - (Some(h), Input::Point(at)) => { + (Some(h), Input::Point(pi)) => { + let at = pi.point(); run_jogline(s, &json!({ "handle": h.hex(), "at": [at.x, at.y] }))?; return Ok(Step::Done); } @@ -628,11 +630,13 @@ impl Interactive for DimBreakM { } if self.manual_mode { return match i { - Input::Point(p) if self.manual.is_empty() => { + Input::Point(pi) if self.manual.is_empty() => { + let p = pi.point(); self.manual.push(p); Ok(Step::Continue) } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let a = self.manual.first().copied().unwrap_or(p); self.run(s, json!({ "mode": "manual", "first": [a.x, a.y], "second": [p.x, p.y] })) } diff --git a/crates/engine/src/cmd/annotate_qdim.rs b/crates/engine/src/cmd/annotate_qdim.rs index 49e604f9a6..1201cbfa01 100644 --- a/crates/engine/src/cmd/annotate_qdim.rs +++ b/crates/engine/src/cmd/annotate_qdim.rs @@ -310,7 +310,8 @@ impl Interactive for QDimM { }; } match (self.ask, i) { - (Ask::Position, Input::Point(at)) => { + (Ask::Position, Input::Point(pi)) => { + let at = pi.point(); let r = run(s, &self.params(at))?; let n = r.get("handles").and_then(Value::as_array).map_or(0, Vec::len); s.echo(format!("{n} dimension(s) created.")); @@ -327,15 +328,17 @@ impl Interactive for QDimM { } } }, - (Ask::Datum, Input::Point(p)) => { + (Ask::Datum, Input::Point(pi)) => { + let p = pi.point(); self.datum = Some(p); self.ask = Ask::Position; } - (Ask::Remove, Input::Point(p)) => { + (Ask::Remove, Input::Point(pi)) => { + let p = pi.point(); self.tol = self.tol.max(s.pixel_size() * s.settings.pickbox.max(1.0)); self.remove.push(p); } - (Ask::Add, Input::Point(p)) => self.add.push(p), + (Ask::Add, Input::Point(pi)) => self.add.push(pi.point()), (Ask::Remove, Input::Keyword(k)) if k == "Add" => self.ask = Ask::Add, (Ask::Add, Input::Keyword(k)) if k == "Remove" => self.ask = Ask::Remove, (Ask::Remove | Ask::Add | Ask::Settings, Input::Keyword(_) | Input::Enter) => self.ask = Ask::Position, diff --git a/crates/engine/src/cmd/annotate_tedit.rs b/crates/engine/src/cmd/annotate_tedit.rs index a1317b2a59..86a42c5f12 100644 --- a/crates/engine/src/cmd/annotate_tedit.rs +++ b/crates/engine/src/cmd/annotate_tedit.rs @@ -81,7 +81,10 @@ impl Interactive for TEditM { }; } match i { - Input::Point(p) => self.run(s, json!({ "at": [p.x, p.y] })), + Input::Point(pi) => { + let p = pi.point(); + self.run(s, json!({ "at": [p.x, p.y] })) + } Input::Keyword(k) if k == "Angle" => { self.asking_angle = true; Ok(Step::Continue) diff --git a/crates/engine/src/cmd/array.rs b/crates/engine/src/cmd/array.rs index 04cbda2259..82839c598e 100644 --- a/crates/engine/src/cmd/array.rs +++ b/crates/engine/src/cmd/array.rs @@ -18,7 +18,7 @@ use super::helpers::{line, v3}; use super::machines::{SelOutcome, SelectPhase, number}; use super::modify::transform_entities; use super::*; -use crate::{Accept, EngineError, Input, Interactive, Prompt, Result, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, PointInput, Prompt, Result, Session, Step}; mod edit; @@ -546,7 +546,10 @@ impl RectM { let d = match i { Input::Enter => return Ok(Some(cur)), Input::Text(t) => number(t), - Input::Point(p) => Some(self.base.dist(*p)), + Input::Point(pi) => { + let p = pi.point(); + Some(self.base.dist(p)) + } _ => return Ok(None), }; d.filter(|d| d.is_finite() && d.abs() > 1e-12).map(Some).ok_or_else(|| other("Requires a nonzero distance.")) @@ -567,7 +570,10 @@ impl RectM { let k = match i { Input::Enter => return self.finish(s), Input::Keyword(k) => k, - Input::Point(_) => return Err(other("Editing the array with grips is not available yet; choose an option.")), + Input::Point(pi) => { + let _ = pi.point(); + return Err(other("Editing the array with grips is not available yet; choose an option.")); + } _ => return Err(other("Invalid option keyword.")), }; self.stage = match k.as_str() { @@ -661,8 +667,9 @@ impl Interactive for RectM { } None => return Err(other("Requires Yes or No.")), }, - (Base, Input::Point(p)) => { - self.base = *p; + (Base, Input::Point(pi)) => { + let p = pi.point(); + self.base = p; Main } (Base, Input::Enter) => { @@ -757,7 +764,7 @@ impl Interactive for RectM { } _ => return Err(other("Requires a number.")), }, - (UnitCell, Input::Point(p)) => match self.corner { + (UnitCell, Input::Point(PointInput::Picked(p))) => match self.corner { None => { self.corner = Some(*p); UnitCell @@ -940,7 +947,10 @@ impl PolarM { let k = match i { Input::Enter => return self.finish(s), Input::Keyword(k) => k, - Input::Point(_) => return Err(other("Editing the array with grips is not available yet; choose an option.")), + Input::Point(pi) => { + let _ = pi.point(); + return Err(other("Editing the array with grips is not available yet; choose an option.")); + } _ => return Err(other("Invalid option keyword.")), }; self.stage = match k.as_str() { @@ -963,7 +973,10 @@ impl PolarM { let d = match i { Input::Enter => return Ok(Some(cur)), Input::Text(t) => number(t), - Input::Point(p) => Some(self.center.dist(*p)), + Input::Point(pi) => { + let p = pi.point(); + Some(self.center.dist(p)) + } _ => return Ok(None), }; d.filter(|d| d.is_finite() && d.abs() > 1e-12).map(Some).ok_or_else(|| other("Requires a nonzero distance.")) @@ -1031,8 +1044,9 @@ impl Interactive for PolarM { } None => return Err(other("Requires Yes or No.")), }, - (Center, Input::Point(p)) => { - self.center = *p; + (Center, Input::Point(pi)) => { + let p = pi.point(); + self.center = p; Main } (Center, Input::Keyword(k)) if k == "Base point" => CenterBase, @@ -1041,8 +1055,9 @@ impl Interactive for PolarM { Center } (Center, _) => return Err(other("Requires a point or an option keyword.")), - (CenterBase | Base, Input::Point(p)) => { - self.base = Some(*p); + (CenterBase | Base, Input::Point(pi)) => { + let p = pi.point(); + self.base = Some(p); if stage == CenterBase { Center } else { Main } } (CenterBase | Base, Input::Enter) => { diff --git a/crates/engine/src/cmd/array/edit.rs b/crates/engine/src/cmd/array/edit.rs index 806a755912..b6b8197eb5 100644 --- a/crates/engine/src/cmd/array/edit.rs +++ b/crates/engine/src/cmd/array/edit.rs @@ -569,10 +569,11 @@ impl EditM { let d = match i { Input::Enter => return Ok(Some(cur)), Input::Text(t) => number(t), - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let h = self.array.ok_or_else(|| other("No array selected."))?; let (ins, blk, _) = array_of(s.doc()?, h)?; - ins.transform(blk.base.xy()).inverse().map(|inv| inv.apply(*p).len()) + ins.transform(blk.base.xy()).inverse().map(|inv| inv.apply(p).len()) } _ => return Ok(None), }; @@ -729,8 +730,9 @@ impl Interactive for EditM { let (c64, r64, l64) = (u64::from(cols), u64::from(rows), u64::from(levels)); let next = match (stage, &i) { (Main, _) => return self.main(s, i), - (Base, Input::Point(p)) => { - rebase(s, h, *p)?; + (Base, Input::Point(pi)) => { + let p = pi.point(); + rebase(s, h, p)?; Main } (Base, Input::Enter) => { @@ -863,15 +865,19 @@ impl Interactive for EditM { } (RepBase, Input::Point(_) | Input::Enter) => { let base = match &i { - Input::Point(p) => *p, + Input::Point(pi) => { + let p = pi.point(); + p + } _ => centroid(s.doc()?, &self.rep_objs), }; self.rep_block = Some(block_from(s, h, &self.rep_objs.clone(), base)?); RepItems } - (RepItems, Input::Point(at)) => { + (RepItems, Input::Point(pi)) => { + let at = pi.point(); let tol = s.pixel_size() * s.settings.pickbox; - let item = item_at(s.doc()?, h, *at, tol).ok_or_else(|| other("No array item there; select an item of the array."))?; + let item = item_at(s.doc()?, h, at, tol).ok_or_else(|| other("No array item there; select an item of the array."))?; let name = self.rep_block.clone().ok_or_else(|| other("No replacement objects."))?; self.change(s, |p| { p.replaced.push(ReplacedItem { i: item.0, j: item.1, level: item.2, block: name }); @@ -888,9 +894,10 @@ impl Interactive for EditM { Main } (RepItems, Input::Enter) => Main, - (SourceItem, Input::Point(at)) => { + (SourceItem, Input::Point(pi)) => { + let at = pi.point(); let tol = s.pixel_size() * s.settings.pickbox; - let item = item_at(s.doc()?, h, *at, tol).ok_or_else(|| other("No array item there; select an item of the array."))?; + let item = item_at(s.doc()?, h, at, tol).ok_or_else(|| other("No array item there; select an item of the array."))?; open_source(s, h, item)?; return Ok(Step::Done); } diff --git a/crates/engine/src/cmd/blocks.rs b/crates/engine/src/cmd/blocks.rs index 6b968f8cf2..62619baa6c 100644 --- a/crates/engine/src/cmd/blocks.rs +++ b/crates/engine/src/cmd/blocks.rs @@ -507,7 +507,8 @@ impl Interactive for BlockM { Ok(Step::Continue) } (Some(_), None) => { - if let Input::Point(p) = i { + if let Input::Point(pi) = i { + let p = pi.point(); self.base = Some(p); self.sel = SelectPhase::begin(s); if self.sel.done { @@ -723,7 +724,8 @@ impl Interactive for InsertM { } } InsStage::Point => match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); self.at = Some(p); return self.advance(s); } @@ -733,7 +735,8 @@ impl Interactive for InsertM { _ => {} }, InsStage::BasePoint => { - if let Input::Point(p) = i { + if let Input::Point(pi) = i { + let p = pi.point(); self.base = Some(p); self.stage = InsStage::Point; } @@ -761,7 +764,8 @@ impl Interactive for InsertM { } InsStage::XScale => match i { Input::Keyword(k) if k == "Corner" => self.stage = InsStage::Corner, - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); self.scale = Some(Self::corner(self.at.unwrap_or_default(), p)?); return self.advance(s); } @@ -776,7 +780,8 @@ impl Interactive for InsertM { _ => {} }, InsStage::Corner => { - if let Input::Point(p) = i { + if let Input::Point(pi) = i { + let p = pi.point(); self.scale = Some(Self::corner(self.at.unwrap_or_default(), p)?); return self.advance(s); } @@ -794,7 +799,10 @@ impl Interactive for InsertM { InsStage::Rotation => { let a = self.at.unwrap_or_default(); self.rotation = Some(match i { - Input::Point(p) => a.angle_to(p), + Input::Point(pi) => { + let p = pi.point(); + a.angle_to(p) + } Input::Text(t) => s.angle_settings().direction(&t).ok_or_else(|| EngineError::Other("Requires an angle.".into()))?, _ => 0.0, }); @@ -864,7 +872,8 @@ impl Interactive for AttdefM { (Some(_), None, _) => self.prompt = text, (Some(_), Some(_), None) => self.default = text, (Some(tag), Some(pr), Some(def)) => { - if let Input::Point(p) = i { + if let Input::Point(pi) = i { + let p = pi.point(); let h = s.doc()?.header.f64("TEXTSIZE", 0.2); let k = attdef_kind(s, tag, pr, def, p, h, false); s.add_entity(k)?; diff --git a/crates/engine/src/cmd/blocks/dyngrip.rs b/crates/engine/src/cmd/blocks/dyngrip.rs index dbc92b7fbd..f61ab199a5 100644 --- a/crates/engine/src/cmd/blocks/dyngrip.rs +++ b/crates/engine/src/cmd/blocks/dyngrip.rs @@ -139,7 +139,10 @@ impl Interactive for DynGripEdit { fn input(&mut self, s: &mut Session, i: Input) -> Result { let to = match i { - Input::Point(p) => p, + Input::Point(pi) => { + let p = pi.point(); + p + } Input::Deferred(d) => d.at, Input::Text(t) if self.distance => { let mut d = s.doc()?.clone(); diff --git a/crates/engine/src/cmd/blocks/extract.rs b/crates/engine/src/cmd/blocks/extract.rs index 10785f08f1..f68c38e97b 100644 --- a/crates/engine/src/cmd/blocks/extract.rs +++ b/crates/engine/src/cmd/blocks/extract.rs @@ -367,7 +367,8 @@ impl Interactive for ExtractM { self.stage = if self.table { Stage::Point } else { Stage::File }; } Stage::Point => match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); self.at = Some(p); return self.after_point(s); } diff --git a/crates/engine/src/cmd/constraints.rs b/crates/engine/src/cmd/constraints.rs index 54af88c805..e20eb8c33a 100644 --- a/crates/engine/src/cmd/constraints.rs +++ b/crates/engine/src/cmd/constraints.rs @@ -458,7 +458,8 @@ impl Interactive for GcM { self.two_points = true; Ok(Step::Continue) } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let space = s.space(); let Some(h) = crate::select::pick(s.doc()?, &space, p, aperture(s)) else { s.echo("*Invalid selection*"); @@ -702,7 +703,8 @@ impl Interactive for DcM { self.points = true; Ok(Step::Continue) } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let space = s.space(); let ap = aperture(s); let d = s.doc()?; diff --git a/crates/engine/src/cmd/constraints_tests.rs b/crates/engine/src/cmd/constraints_tests.rs index 0e2dbf829f..2bb17ec755 100644 --- a/crates/engine/src/cmd/constraints_tests.rs +++ b/crates/engine/src/cmd/constraints_tests.rs @@ -2,7 +2,7 @@ use cadcraft_doc::{ConstraintKind, EntityKind, Handle}; use cadcraft_geom::Vec2; use serde_json::json; -use crate::{Input, Session, command_specs}; +use crate::{Input, PointInput, Session, command_specs}; fn line(s: &mut Session, a: [f64; 2], b: [f64; 2]) -> String { s.execute("line", &json!({ "points": [a, b] })).unwrap(); @@ -120,18 +120,18 @@ fn interactive_prompts() { let b = line(&mut s, [0.0, 3.0], [8.0, 3.9]); s.cmdline("gchorizontal").unwrap(); assert!(s.prompt_text().contains("Select an object")); - s.input(Input::Point(Vec2::new(4.0, 0.2))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(4.0, 0.2)))).unwrap(); assert!(s.running.is_none()); s.cmdline("geomconstraint pa").unwrap(); assert!(s.prompt_text().contains("Select first object"), "{}", s.prompt_text()); - s.input(Input::Point(Vec2::new(4.0, 0.2))).unwrap(); - s.input(Input::Point(Vec2::new(4.0, 3.45))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(4.0, 0.2)))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(4.0, 3.45)))).unwrap(); assert!(s.running.is_none()); let ((a0, a1), (b0, b1)) = (ends(&s, &a), ends(&s, &b)); assert!((a0.y - a1.y).abs() < 1e-6 && (b0.y - b1.y).abs() < 1e-6); // DIMCONSTRAINT → aligned → pick → value with a name. s.cmdline("dimconstraint al").unwrap(); - s.input(Input::Point(Vec2::new(4.0, a0.y))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(4.0, a0.y)))).unwrap(); assert!(s.prompt_text().contains("dimension value"), "{}", s.prompt_text()); s.cmdline("width=5").unwrap(); assert!(s.running.is_none()); @@ -146,8 +146,8 @@ fn interactive_prompts() { let c = line(&mut s, [20.0, 0.0], [30.0, 0.0]); let e = line(&mut s, [30.3, 0.2], [30.0, 9.0]); s.cmdline("gccoincident").unwrap(); - s.input(Input::Point(Vec2::new(29.98, 0.0))).unwrap(); - s.input(Input::Point(Vec2::new(30.28, 0.3))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(29.98, 0.0)))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(30.28, 0.3)))).unwrap(); assert!(ends(&s, &c).1.near(ends(&s, &e).0, 1e-6)); // AUTOCONSTRAIN with a pickfirst selection. let f = line(&mut s, [40.0, 0.0], [50.0, 0.01]); @@ -238,9 +238,13 @@ fn hostile_constraint_params_never_panic() { } // Interactive: start, junk inputs, cancel. s.start(id).unwrap(); - for i in - [Input::Point(Vec2::new(5.0, 0.0)), Input::Text("x".into()), Input::Point(Vec2::new(0.0, 7.0)), Input::Enter, Input::Text("1/0".into())] - { + for i in [ + Input::Point(PointInput::Picked(Vec2::new(5.0, 0.0))), + Input::Text("x".into()), + Input::Point(PointInput::Picked(Vec2::new(0.0, 7.0))), + Input::Enter, + Input::Text("1/0".into()), + ] { let _ = s.input(i); } s.cancel(); diff --git a/crates/engine/src/cmd/draw.rs b/crates/engine/src/cmd/draw.rs index 8fa3f6d613..e407d3dc0c 100644 --- a/crates/engine/src/cmd/draw.rs +++ b/crates/engine/src/cmd/draw.rs @@ -9,7 +9,7 @@ use super::helpers::*; use super::machines::number; use super::pline_opts::{Outcome, PlineAsk}; use super::*; -use crate::{Accept, Input, Interactive, Prompt, Result, Session, Step, snap}; +use crate::{Accept, Input, Interactive, PointInput, Prompt, Result, Session, Step, snap}; pub fn specs() -> Vec { vec![ @@ -428,20 +428,21 @@ impl Interactive for LineM { && let Some(first) = self.first { match i { - Input::Point(p) => { + Input::Point(pi @ PointInput::RelativePolar { dist, angle, .. }) => { // A deferred TAN first point with a typed `@d { + return self.resolve_first(s, first, snap::LineEnd::Point(pi.point())); } Input::Deferred(d) => return self.resolve_first(s, first, snap::LineEnd::Deferred(d)), _ => {} @@ -455,12 +456,13 @@ impl Interactive for LineM { // A deferred pick with a known last point (not offered by the prompt, but harmless). Input::Deferred(d) => match self.pts.last().copied() { Some(last) => match snap::resolve_deferred(snap::LineEnd::Point(last), snap::LineEnd::Deferred(d)) { - Some((_, p)) => self.input(s, Input::Point(p)), + Some((_, p)) => self.input(s, Input::Point(PointInput::Picked(p))), None => Err(crate::EngineError::Other("No tangent or perpendicular from the last point.".into())), }, None => Ok(Step::Continue), }, - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); if let Some(last) = self.pts.last().copied() { if last.near(p, 1e-12) { return Ok(Step::Continue); @@ -653,7 +655,8 @@ impl Interactive for PlineM { return Ok(Step::Continue); } match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); if self.verts.is_empty() { s.echo(format!("Current line-width is {:.4}", self.start_w)); } @@ -796,7 +799,8 @@ impl Interactive for CircleM { }; Ok(Step::Continue) } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); if self.mode == 0 && self.pts.first().is_some_and(|c| c.near(p, 1e-12)) { return Err(crate::EngineError::Other("Value must be positive and nonzero.".into())); } @@ -914,7 +918,8 @@ impl Interactive for PolygonM { } let n = self.sides.unwrap_or(4); if self.edge { - if let Input::Point(p) = i { + if let Input::Point(pi) = i { + let p = pi.point(); if self.edge_pts.first().is_some_and(|a| a.near(p, 1e-12)) { return Err(crate::EngineError::Other("Edge endpoints must differ.".into())); } @@ -928,7 +933,7 @@ impl Interactive for PolygonM { } match (self.center, self.inscribed, i) { (None, _, Input::Keyword(k)) if k == "Edge" => self.edge = true, - (None, _, Input::Point(p)) => self.center = Some(p), + (None, _, Input::Point(pi)) => self.center = Some(pi.point()), (Some(_), None, inp @ (Input::Keyword(_) | Input::Enter | Input::Text(_))) => { // Enter takes the option used last time (the prompt's default). let ins = match inp { @@ -939,7 +944,8 @@ impl Interactive for PolygonM { self.inscribed = Some(ins); s.last_used.polygon_circumscribed = !ins; } - (Some(c), Some(ins), Input::Point(p)) => { + (Some(c), Some(ins), Input::Point(pi)) => { + let p = pi.point(); if c.near(p, 1e-12) { return Err(crate::EngineError::Other("Value must be positive and nonzero.".into())); } @@ -1075,8 +1081,11 @@ impl Interactive for EllipseM { return Ok(Step::Continue); } // A parameter is the angle from the major axis taken as the parameter itself. - Input::Point(p) if self.param => cadcraft_geom::norm_angle((p - e.center).angle() - e.major.angle()), - Input::Point(p) => ge.param_of(p), + Input::Point(pi) if self.param => cadcraft_geom::norm_angle((pi.point() - e.center).angle() - e.major.angle()), + Input::Point(pi) => { + let p = pi.point(); + ge.param_of(p) + } Input::Text(t) => { let a = s.angle_settings().amount(&t).ok_or_else(|| crate::EngineError::Other("Requires an angle.".into()))?; if self.param { @@ -1116,13 +1125,15 @@ impl Interactive for EllipseM { Input::Keyword(k) if k == "Center" => self.center_mode = true, Input::Keyword(k) if k == "Arc" => self.arc_mode = true, Input::Keyword(k) if k == "Rotation" && self.pts.len() == 2 => self.rotation = true, - Input::Point(p) if self.pts.len() < 2 => self.pts.push(p), - Input::Point(p) if self.rotation => { + Input::Point(pi) if self.pts.len() < 2 => self.pts.push(pi.point()), + Input::Point(pi) if self.rotation => { + let p = pi.point(); if let Some(e) = self.axis().and_then(|(c, _)| self.rotated((p - c).angle())) { return self.place(s, e); } } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); if let Some(e) = self.build(p) { return self.place(s, e); } @@ -1189,7 +1200,8 @@ impl Interactive for PointM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); s.add_entity(EntityKind::Point(Point { p: v3(p), angle: 0.0 }))?; Ok(if self.multiple { Step::Continue } else { Step::Done }) } @@ -1217,7 +1229,8 @@ impl Interactive for RayM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); match self.base { None => self.base = Some(p), Some(b) => { @@ -1328,7 +1341,8 @@ impl Interactive for SplineM { return Ok(Step::Continue); } match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); self.pts.push(p); Ok(Step::Continue) } @@ -1415,7 +1429,8 @@ impl Interactive for DonutM { self.outside = Some(number(&t).ok_or_else(|| crate::EngineError::Other("Requires a distance.".into()))?.abs()) } (Some(_), None, Input::Enter) => self.outside = Some(hdr(s, "DONUTOD", 1.0)), - (Some(a), Some(b), Input::Point(p)) => { + (Some(a), Some(b), Input::Point(pi)) => { + let p = pi.point(); s.add_entity(donut(p, a, b))?; let d = s.doc_mut()?; d.header.set_f64("DONUTID", a); @@ -1499,16 +1514,16 @@ impl Interactive for TextM { let th = s.doc()?.header.f64("TEXTSIZE", 0.2); match (self.at, self.height, self.rotation, i) { (None, _, _, Input::Keyword(k)) if k == "Justify" => self.asking_justify = true, - (None, _, _, Input::Point(p)) => self.at = Some(p), + (None, _, _, Input::Point(pi)) => self.at = Some(pi.point()), (Some(_), None, _, Input::Enter) => self.height = Some(th), - (Some(a), None, _, Input::Point(p)) => self.height = Some(a.dist(p).max(1e-9)), + (Some(a), None, _, Input::Point(pi)) => self.height = Some(a.dist(pi.point()).max(1e-9)), (Some(_), None, _, Input::Text(t)) => { let h = number(&t).filter(|h| *h > 0.0).ok_or_else(|| crate::EngineError::Other("Requires a positive height.".into()))?; self.height = Some(h); s.doc_mut()?.header.set_f64("TEXTSIZE", h); } (Some(_), Some(_), None, Input::Enter) => self.rotation = Some(0.0), - (Some(a), Some(_), None, Input::Point(p)) => self.rotation = Some(a.angle_to(p)), + (Some(a), Some(_), None, Input::Point(pi)) => self.rotation = Some(a.angle_to(pi.point())), (Some(_), Some(_), None, Input::Text(t)) => { self.rotation = Some(s.angle_settings().direction(&t).ok_or_else(|| crate::EngineError::Other("Requires an angle.".into()))?) } @@ -1586,8 +1601,8 @@ impl Interactive for MTextM { return Ok(Step::Continue); } match (self.first, self.boxed(), i) { - (None, _, Input::Point(p)) => self.first = Some(p), - (Some(_), false, Input::Point(p)) => self.second = Some(p), + (None, _, Input::Point(pi)) => self.first = Some(pi.point()), + (Some(_), false, Input::Point(pi)) => self.second = Some(pi.point()), (Some(_), false, Input::Keyword(k)) => { self.ask = Some(super::mtext_opts::MTextAsk::from_keyword(&k).ok_or_else(|| crate::EngineError::Other("Invalid option keyword.".into()))?); diff --git a/crates/engine/src/cmd/draw2.rs b/crates/engine/src/cmd/draw2.rs index 1d3b10c6ca..9e58388e3f 100644 --- a/crates/engine/src/cmd/draw2.rs +++ b/crates/engine/src/cmd/draw2.rs @@ -10,7 +10,7 @@ use super::curves::{self, Chain, MAX_GEN, TanObj}; use super::helpers::*; use super::machines::number; use super::*; -use crate::{Accept, EngineError, Input, Interactive, Prompt, Result, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, PointInput, Prompt, Result, Session, Step}; pub(crate) mod breakline; pub(crate) mod mline; @@ -353,7 +353,8 @@ impl Interactive for SeqM { // modifiers so it remains UI-agnostic. let dir = if s.ctrl_down { -dir } else { dir }; return match i { - Input::Point(e) => { + Input::Point(pi) => { + let e = pi.point(); let a = curves::arc_sed(st, e, dir).ok_or_else(|| other("Invalid end point."))?; s.add_entity(arc(&a))?; Ok(Step::Done) @@ -378,7 +379,7 @@ impl Interactive for SeqM { } let Some((_, ask)) = self.ask() else { return Ok(Step::Done) }; let val = match (&i, ask) { - (Input::Point(q), _) => self.value_from_point(ask, *q), + (Input::Point(PointInput::Picked(q)), _) => self.value_from_point(ask, *q), (Input::Text(t), Ask::Angle(_) | Ask::Sweep(..)) => { // The tangent direction is a direction; included angles are sizes. let au = s.angle_settings(); @@ -506,7 +507,8 @@ impl Interactive for ArcContinueM { // Ctrl flips the direction, exactly as in `SeqM::input`. let dir = if s.ctrl_down { -dir } else { dir }; match i { - Input::Point(e) => { + Input::Point(pi) => { + let e = pi.point(); let a = curves::arc_sed(st, e, dir).ok_or_else(|| other("Invalid end point."))?; s.add_entity(arc(&a))?; Ok(Step::Done) @@ -614,7 +616,8 @@ impl Interactive for TanCircleM { let need = if self.radius_mode { 2 } else { 3 }; if self.picks.len() < need { return match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; let o = tan_obj(s, h, p)?; self.picks.push((o, p)); @@ -636,7 +639,10 @@ impl Interactive for TanCircleM { }; } let r = match i { - Input::Point(p) => self.picks.last().map(|x| x.1.dist(p)).unwrap_or(0.0), + Input::Point(pi) => { + let p = pi.point(); + self.picks.last().map(|x| x.1.dist(p)).unwrap_or(0.0) + } Input::Text(t) => number(&t).ok_or_else(|| other("Requires numeric distance or second point."))?, Input::Enter => s.doc()?.header.f64("CIRCLERAD", 0.0), _ => return Ok(Step::Continue), @@ -845,7 +851,8 @@ impl Interactive for DivideM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match (self.phase, i) { - (DivPhase::Object, Input::Point(p)) => { + (DivPhase::Object, Input::Point(pi)) => { + let p = pi.point(); let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; chain_of(s, h)?; self.obj = Some((h, p)); @@ -876,7 +883,10 @@ impl Interactive for DivideM { let Some((h, pick)) = self.obj else { return Ok(Step::Cancel) }; let v = match inp { Input::Text(t) => number(&t).ok_or_else(|| other("Requires a number."))?, - Input::Point(q) => pick.dist(q), + Input::Point(pi) => { + let q = pi.point(); + pick.dist(q) + } _ => return Ok(Step::Continue), }; let mut params = json!({ "handle": h.hex(), "align": self.align, "from": [pick.x, pick.y] }); @@ -1109,7 +1119,7 @@ impl Interactive for RevcloudM { return Ok(Step::Continue); } if self.object { - let Input::Point(p) = i else { return if i == Input::Enter { Ok(Step::Cancel) } else { Ok(Step::Continue) } }; + let Input::Point(PointInput::Picked(p)) = i else { return if i == Input::Enter { Ok(Step::Cancel) } else { Ok(Step::Continue) } }; let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; let pts = object_outline(s, h)?; let vs = cloud_vertices(&pts, self.arc_len, false, false).ok_or_else(|| other("The object has no area."))?; @@ -1137,7 +1147,8 @@ impl Interactive for RevcloudM { } Ok(Step::Continue) } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); self.pts.push(p); if self.kind == CloudKind::Rect && self.pts.len() == 2 { return self.finish(s); @@ -1240,7 +1251,8 @@ impl Interactive for WipeoutM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match (self.phase, i) { - (1, Input::Point(p)) => { + (1, Input::Point(pi)) => { + let p = pi.point(); let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; let e = curves::entity(s, h)?; if !matches!(&e.kind, EntityKind::LwPolyline(pl) if pl.closed) { @@ -1276,7 +1288,8 @@ impl Interactive for WipeoutM { } Ok(Step::Continue) } - (0, Input::Point(p)) => { + (0, Input::Point(pi)) => { + let p = pi.point(); if self.pts.len() < MAX_GEN { self.pts.push(p); } @@ -1462,7 +1475,8 @@ impl Interactive for XlineM2 { }; Ok(Step::Continue) } - (XMode::Two, Input::Point(p)) => { + (XMode::Two, Input::Point(pi)) => { + let p = pi.point(); match self.base { None => self.base = Some(p), Some(b) => { @@ -1473,7 +1487,8 @@ impl Interactive for XlineM2 { } Ok(Step::Continue) } - (XMode::Fixed(a), Input::Point(p)) => { + (XMode::Fixed(a), Input::Point(pi)) => { + let p = pi.point(); add_xline(s, p, Vec2::from_angle(a))?; Ok(Step::Continue) } @@ -1486,7 +1501,8 @@ impl Interactive for XlineM2 { self.mode = XMode::Fixed(a); Ok(Step::Continue) } - (XMode::RefSelect, Input::Point(p)) => { + (XMode::RefSelect, Input::Point(pi)) => { + let p = pi.point(); let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; let (_, d) = linear_of(s, h, Some(p))?; self.mode = XMode::RefAngle(d.angle()); @@ -1497,7 +1513,8 @@ impl Interactive for XlineM2 { self.mode = XMode::Fixed(base + a); Ok(Step::Continue) } - (XMode::Bisect, Input::Point(p)) => { + (XMode::Bisect, Input::Point(pi)) => { + let p = pi.point(); if self.bis.len() < 2 { self.bis.push(p); } else if let (Some(v), Some(a)) = (self.bis.first().copied(), self.bis.get(1).copied()) { @@ -1519,13 +1536,15 @@ impl Interactive for XlineM2 { self.mode = XMode::OffSelect; Ok(Step::Continue) } - (XMode::OffSelect, Input::Point(p)) => { + (XMode::OffSelect, Input::Point(pi)) => { + let p = pi.point(); let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; self.line = Some(linear_of(s, h, Some(p))?); self.mode = XMode::OffSide; Ok(Step::Continue) } - (XMode::OffSide, Input::Point(p)) => { + (XMode::OffSide, Input::Point(pi)) => { + let p = pi.point(); let (b, d) = self.line.ok_or_else(|| other("No line selected."))?; let (nb, nd) = match self.offset { Some(dist) => offset_xline(b, d, dist, p), @@ -1775,17 +1794,22 @@ impl Interactive for RectM2 { } RAsk::Rotation => match i { Input::Keyword(_) => self.asking = Some(RAsk::RotPick1), - Input::Point(p) => self.rotation = self.first.map(|f| f.angle_to(p)).unwrap_or(0.0), + Input::Point(pi) => { + let p = pi.point(); + self.rotation = self.first.map(|f| f.angle_to(p)).unwrap_or(0.0) + } Input::Text(t) => self.rotation = s.angle_settings().direction(&t).ok_or_else(|| other("Requires a valid angle."))?, _ => {} }, RAsk::RotPick1 => { - if let Input::Point(p) = i { + if let Input::Point(pi) = i { + let p = pi.point(); self.asking = Some(RAsk::RotPick2(p)); } } RAsk::RotPick2(b) => { - if let Input::Point(p) = i { + if let Input::Point(pi) = i { + let p = pi.point(); self.rotation = b.angle_to(p); } } @@ -1806,16 +1830,19 @@ impl Interactive for RectM2 { }); Ok(Step::Continue) } - Input::Point(p) => match self.first { - None => { - self.first = Some(p); - Ok(Step::Continue) - } - Some(_) => { - let (w, h) = self.other_corner(p).ok_or_else(|| other("No first corner."))?; - self.make(s, w, h) + Input::Point(pi) => { + let p = pi.point(); + match self.first { + None => { + self.first = Some(p); + Ok(Step::Continue) + } + Some(_) => { + let (w, h) = self.other_corner(p).ok_or_else(|| other("No first corner."))?; + self.make(s, w, h) + } } - }, + } Input::Enter => Ok(Step::Cancel), _ => Ok(Step::Continue), } @@ -1889,7 +1916,8 @@ impl Interactive for Poly3dM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); if self.pts.last().is_none_or(|l| !l.near(p, 1e-12)) && self.pts.len() < MAX_GEN { self.pts.push(p); self.sync(s, false)?; @@ -2030,14 +2058,18 @@ impl Interactive for HelixM { } let num = |i: &Input, base: Option| -> Option { match i { - Input::Point(p) => base.map(|b| b.dist(*p)), + Input::Point(pi) => { + let p = pi.point(); + base.map(|b| b.dist(p)) + } Input::Text(t) => number(t), _ => None, } }; match (self.center, self.rb, self.rt, &i) { - (None, _, _, Input::Point(p)) => { - self.center = Some(*p); + (None, _, _, Input::Point(pi)) => { + let p = pi.point(); + self.center = Some(p); Ok(Step::Continue) } (Some(_), None | Some(_), _, Input::Keyword(k)) if k == "Diameter" => { @@ -2050,8 +2082,9 @@ impl Interactive for HelixM { _ => num(&i, Some(c)), }; let v = v.filter(|v| *v > 0.0).ok_or_else(|| other("Requires a positive distance."))?; - if let Input::Point(p) = &i { - self.start = Some(c.angle_to(*p)); + if let Input::Point(pi) = &i { + let p = pi.point(); + self.start = Some(c.angle_to(p)); } self.rb = Some(if self.diameter { v / 2.0 } else { v }); self.diameter = false; @@ -2152,7 +2185,8 @@ impl Interactive for SplineCvM { } let deg = self.degree.unwrap_or(3); match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); if self.pts.len() < MAX_GEN { self.pts.push(p); } @@ -2292,7 +2326,8 @@ impl Interactive for CenterM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; if self.mark { center_mark(s, h)?; diff --git a/crates/engine/src/cmd/draw2/mline.rs b/crates/engine/src/cmd/draw2/mline.rs index 2f1b7edc6b..d344d309ea 100644 --- a/crates/engine/src/cmd/draw2/mline.rs +++ b/crates/engine/src/cmd/draw2/mline.rs @@ -193,7 +193,8 @@ impl Interactive for MlineM { } Ok(Step::Continue) } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); if self.pts.last().is_none_or(|l| !l.near(p, 1e-12)) && self.pts.len() < MAX_GEN { self.pts.push(p); } @@ -788,7 +789,8 @@ impl Interactive for MleditM { self.first = None; Ok(Step::Continue) } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let pick = || -> Result { let h = curves::pick_at(s, p).ok_or_else(|| other("Select a multiline."))?; mline_of(s, h).map(|_| h) diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index 822ef87603..1205d224ac 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -596,11 +596,13 @@ impl Interactive for PasteM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match i { - Input::Point(p) if self.mode == PasteMode::Block => { + Input::Point(pi) if self.mode == PasteMode::Block => { + let p = pi.point(); clipboard::paste_block(s, p)?; Ok(Step::Done) } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let base = s.clipboard_base; paste(s, p - base)?; Ok(Step::Done) @@ -676,7 +678,8 @@ impl Interactive for CopyBaseM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { if self.base.is_none() { - if let Input::Point(p) = i { + if let Input::Point(pi) = i { + let p = pi.point(); self.base = Some(p); if self.sel.done { let hs = self.sel.picked.clone(); diff --git a/crates/engine/src/cmd/griphot.rs b/crates/engine/src/cmd/griphot.rs index 802f65e695..31dfc55f80 100644 --- a/crates/engine/src/cmd/griphot.rs +++ b/crates/engine/src/cmd/griphot.rs @@ -189,7 +189,10 @@ impl GripEdit { fn action_input(&mut self, s: &mut Session, action: GripAction, i: Input) -> Result { match i { - Input::Point(p) => self.act(s, action, Some(p), None), + Input::Point(pi) => { + let p = pi.point(); + self.act(s, action, Some(p), None) + } Input::Deferred(d) => self.act(s, action, Some(d.at), None), Input::Text(t) if matches!(action, GripAction::Lengthen | GripAction::Radius) => { let v = number(&t).filter(|v| v.is_finite()).ok_or_else(|| other("Requires a number or point."))?; @@ -271,7 +274,8 @@ impl GripEdit { s.echo(self.label()); Ok(Step::Continue) } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let m = self.matrix(p); self.edit(s, p, m) } @@ -309,11 +313,12 @@ impl GripEdit { Ok(if rotate { a.angle_to(b) } else { a.dist(b) }) }; match (self.ask, i) { - (Ask::RefFirst, Input::Point(p)) => self.ask = Ask::RefSecond(p), + (Ask::RefFirst, Input::Point(pi)) => self.ask = Ask::RefSecond(pi.point()), (Ask::RefFirst, Input::Text(t)) => self.ask = Ask::RefNew(value(&t)?), (Ask::RefFirst, Input::Enter) => self.ask = Ask::RefNew(if rotate { 0.0 } else { 1.0 }), - (Ask::RefSecond(a), Input::Point(p)) => self.ask = Ask::RefNew(between(a, p)?), - (Ask::RefNew(_), Input::Point(p)) => { + (Ask::RefSecond(a), Input::Point(pi)) => self.ask = Ask::RefNew(between(a, pi.point())?), + (Ask::RefNew(_), Input::Point(pi)) => { + let p = pi.point(); let m = self.matrix(p).ok_or_else(|| other("Requires a positive length."))?; return self.edit(s, p, Some(m)); } @@ -391,7 +396,8 @@ impl Interactive for GripEdit { fn input(&mut self, s: &mut Session, i: Input) -> Result { if self.picking { return match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let found = Self::grips_at(s, p); if found.is_empty() { return Err(other("No grip of a selected object there.")); @@ -413,7 +419,8 @@ impl Interactive for GripEdit { match self.ask { Ask::Mode => self.mode_input(s, i), Ask::Base => match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); self.base = p; self.ask = Ask::Mode; Ok(Step::Continue) diff --git a/crates/engine/src/cmd/hatch.rs b/crates/engine/src/cmd/hatch.rs index 308c7d7d2b..1a2a4a73c3 100644 --- a/crates/engine/src/cmd/hatch.rs +++ b/crates/engine/src/cmd/hatch.rs @@ -11,7 +11,7 @@ use serde_json::{Value, json}; use super::helpers::lwpoly; use super::*; -use crate::{Accept, EngineError, Input, Interactive, Picker, Prompt, Result, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, Picker, PointInput, Prompt, Result, Session, Step}; mod assoc; mod edit; @@ -676,14 +676,15 @@ impl Interactive for HatchM { fn input(&mut self, s: &mut Session, i: Input) -> Result { if let Some(a) = self.asking.take() { match &i { - Input::Point(p) if a == HatchAsk::Origin => self.set_origin(s, Some(*p), OriginMode::Current)?, + Input::Point(pi) if a == HatchAsk::Origin => self.set_origin(s, Some(pi.point()), OriginMode::Current)?, Input::Text(t) | Input::Keyword(t) => self.answer(s, a, t)?, _ => {} } return Ok(Step::Continue); } match i { - Input::Point(p) if !self.selecting => { + Input::Point(pi) if !self.selecting => { + let p = pi.point(); match loops_at(s, p) { Ok(l) => { s.echo(format!("Analyzing the selected data... {} loop(s)", l.len())); @@ -756,7 +757,8 @@ impl Interactive for BoundaryM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); match boundary_at(s, p) { Ok(hs) => s.echo(format!("BOUNDARY created {} polyline(s)", hs.len())), Err(e) => s.echo(e.to_string()), @@ -827,7 +829,7 @@ mod tests { s.input(Input::Keyword("Pattern".into())).unwrap(); assert!(s.current_prompt().unwrap().picker.is_some()); s.input(Input::Text("BRICK".into())).unwrap(); - s.input(Input::Point(Vec2::new(5.0, 5.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(5.0, 5.0)))).unwrap(); s.input(Input::Enter).unwrap(); assert_eq!(only_hatch(&s).1.pattern, "BRICK"); // An unknown name keeps the pattern. diff --git a/crates/engine/src/cmd/hatch/edit.rs b/crates/engine/src/cmd/hatch/edit.rs index c0f5c74400..f337888e80 100644 --- a/crates/engine/src/cmd/hatch/edit.rs +++ b/crates/engine/src/cmd/hatch/edit.rs @@ -663,7 +663,7 @@ impl Interactive for HatchEditM { } self.apply(s, Value::Object(self.props.clone())) } - (Ask::Origin, Input::Point(p)) => self.apply(s, json!({ "origin": [p.x, p.y], "originMode": "current" })), + (Ask::Origin, Input::Point(pi)) => self.apply(s, json!({ "origin": [pi.point().x, pi.point().y], "originMode": "current" })), (Ask::Origin, Input::Enter) => Ok(Step::Done), (Ask::Origin, _) => { let mode = match text.as_deref() { diff --git a/crates/engine/src/cmd/hatch/pick.rs b/crates/engine/src/cmd/hatch/pick.rs index b5fc607c26..931f238343 100644 --- a/crates/engine/src/cmd/hatch/pick.rs +++ b/crates/engine/src/cmd/hatch/pick.rs @@ -160,7 +160,8 @@ impl Interactive for HatchPickM { self.keep(s, mode); Ok(Step::Done) } - (PickMode::Points, Input::Point(q)) => { + (PickMode::Points, Input::Point(pi)) => { + let q = pi.point(); if self.count() >= MAX_PICKS { s.echo(format!("At most {MAX_PICKS} picks.")); return Ok(Step::Continue); @@ -188,7 +189,8 @@ impl Interactive for HatchPickM { s.echo(if others == 0 { format!("{} found", closed.len()) } else { format!("{} found, {others} not closed", closed.len()) }); Ok(Step::Continue) } - (PickMode::Origin, Input::Point(q)) => { + (PickMode::Origin, Input::Point(pi)) => { + let q = pi.point(); s.hatch_picks = Some(HatchPicks { mode, origin: Some(q), ..HatchPicks::default() }); Ok(Step::Done) } diff --git a/crates/engine/src/cmd/inquiry.rs b/crates/engine/src/cmd/inquiry.rs index 84abfade48..79110fdaa3 100644 --- a/crates/engine/src/cmd/inquiry.rs +++ b/crates/engine/src/cmd/inquiry.rs @@ -628,7 +628,8 @@ impl Interactive for DistM { return Ok(Step::Continue); } match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); pts.push(p); self.sources.push(s.picked_viewport); let model = model_points(&self.sources); @@ -649,12 +650,14 @@ impl Interactive for DistM { return Ok(Step::Continue); } match (self.first, i) { - (None, Input::Point(p)) => { + (None, Input::Point(pi)) => { + let p = pi.point(); self.first = Some(p); self.first_source = s.picked_viewport; Ok(Step::Continue) } - (Some(a), Input::Point(b)) => { + (Some(a), Input::Point(pi)) => { + let b = pi.point(); let (a, b) = match (self.first_source, s.picked_viewport) { (Some(first), Some(second)) if first.viewport == second.viewport => (first.point, second.point), _ => (a, b), @@ -706,7 +709,8 @@ impl Interactive for IdM { Prompt::new("Specify point", Accept::POINT) } fn input(&mut self, s: &mut Session, i: Input) -> Result { - if let Input::Point(p) = i { + if let Input::Point(pi) = i { + let p = pi.point(); let m = id_text(s, Vec3::new(p.x, p.y, z_at(s, p))); s.echo(m); } @@ -865,7 +869,10 @@ impl Interactive for AreaM { return Ok(Step::Continue); } match i { - Input::Point(p) => self.pts.push(p), + Input::Point(pi) => { + let p = pi.point(); + self.pts.push(p) + } Input::Keyword(k) => match k.as_str() { "Object" => self.object = true, "Add area" => self.mode = AreaMode::Add, diff --git a/crates/engine/src/cmd/inquiry/count.rs b/crates/engine/src/cmd/inquiry/count.rs index cce92859dc..da53a9b327 100644 --- a/crates/engine/src/cmd/inquiry/count.rs +++ b/crates/engine/src/cmd/inquiry/count.rs @@ -398,7 +398,8 @@ impl Interactive for CountTableM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match i { - Input::Point(at) => { + Input::Point(pi) => { + let at = pi.point(); let r = run_counttable(s, &json!({ "at": [at.x, at.y] }))?; echo_lines(s, &r); Ok(Step::Done) diff --git a/crates/engine/src/cmd/layout/viewports.rs b/crates/engine/src/cmd/layout/viewports.rs index 7f47c4e319..7ba2beb6d2 100644 --- a/crates/engine/src/cmd/layout/viewports.rs +++ b/crates/engine/src/cmd/layout/viewports.rs @@ -412,7 +412,8 @@ impl PolygonInput { } pub fn input(&mut self, i: Input) -> Result { match i { - Input::Point(q) => { + Input::Point(pi) => { + let q = pi.point(); if self.vs.last().is_some_and(|l| l.p.near(q, 1e-12)) { return Ok(PolyStep::More); } @@ -507,7 +508,10 @@ fn handles_json(hs: &[Handle]) -> Value { fn pick_viewports(s: &mut Session, i: &Input, picked: &mut Vec) { let found: Vec = match i { Input::Pick(hs) => s.doc().map(|d| viewports_in(d, &s.space(), hs)).unwrap_or_default(), - Input::Point(p) => any_viewport_at(s, *p).into_iter().collect(), + Input::Point(pi) => { + let p = pi.point(); + any_viewport_at(s, p).into_iter().collect() + } _ => Vec::new(), }; let before = picked.len(); @@ -652,7 +656,8 @@ impl Interactive for MviewM { Stage::Corner => match i { Input::Enter => self.create(s, None), Input::Keyword(k) | Input::Text(k) => self.corner_keyword(s, &k.trim().to_ascii_lowercase()), - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); self.stage = Stage::Opposite(p); Ok(Step::Continue) } @@ -675,7 +680,10 @@ impl Interactive for MviewM { Ok(Step::Continue) } Stage::Opposite(a) => match i { - Input::Point(b) => self.create(s, Some(Bounds2::new(a, b))), + Input::Point(pi) => { + let b = pi.point(); + self.create(s, Some(Bounds2::new(a, b))) + } _ => { self.stage = Stage::Opposite(a); Ok(Step::Continue) @@ -697,7 +705,8 @@ impl Interactive for MviewM { } }, Stage::Object => match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let Some(h) = curves::pick_at(s, p) else { self.stage = Stage::Object; s.echo("No object found."); @@ -762,7 +771,8 @@ impl Interactive for MviewM { Stage::RestoreCorner(name) => match i { Input::Enter => Self::restore(s, &name, None), Input::Keyword(k) | Input::Text(k) if matches!(k.trim().to_ascii_lowercase().as_str(), "fit" | "f") => Self::restore(s, &name, None), - Input::Point(a) => { + Input::Point(pi) => { + let a = pi.point(); self.stage = Stage::RestoreOpposite(name, a); Ok(Step::Continue) } @@ -776,7 +786,10 @@ impl Interactive for MviewM { } }, Stage::RestoreOpposite(name, a) => match i { - Input::Point(b) => Self::restore(s, &name, Some(Bounds2::new(a, b))), + Input::Point(pi) => { + let b = pi.point(); + Self::restore(s, &name, Some(Bounds2::new(a, b))) + } _ => { self.stage = Stage::RestoreOpposite(name, a); Ok(Step::Continue) @@ -870,7 +883,10 @@ impl Interactive for VpclipM { match std::mem::take(&mut self.stage) { ClipStage::Viewport => { let h = match &i { - Input::Point(p) => viewport_at(s, *p), + Input::Point(pi) => { + let p = pi.point(); + viewport_at(s, p) + } Input::Pick(hs) => s.doc().ok().and_then(|d| viewports_in(d, &s.layout_space(), hs).first().copied()), _ => None, }; @@ -889,8 +905,9 @@ impl Interactive for VpclipM { } ClipStage::Clip(vh) => { let object = match &i { - Input::Point(p) => { - let Some(o) = curves::pick_at(s, *p) else { + Input::Point(pi) => { + let p = pi.point(); + let Some(o) = curves::pick_at(s, p) else { self.stage = ClipStage::Clip(vh); s.echo("No object found."); return Ok(Step::Continue); diff --git a/crates/engine/src/cmd/layout/vplayer.rs b/crates/engine/src/cmd/layout/vplayer.rs index 0d2e7d9eb5..dd9f8ebb19 100644 --- a/crates/engine/src/cmd/layout/vplayer.rs +++ b/crates/engine/src/cmd/layout/vplayer.rs @@ -186,7 +186,8 @@ impl VplayerM { self.stage = match stage { Stage::Option => Stage::Option, Stage::List => match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); match viewport_at(s, p) { Some(h) => Self::list(s, h), None => s.echo("No viewport found there."), @@ -257,7 +258,8 @@ impl VplayerM { } } Stage::Select(change, layers, mut picked) => match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); match viewport_at(s, p) { Some(h) if !picked.contains(&h) => { picked.push(h); diff --git a/crates/engine/src/cmd/machines.rs b/crates/engine/src/cmd/machines.rs index e7db0abcfc..5db2a51fce 100644 --- a/crates/engine/src/cmd/machines.rs +++ b/crates/engine/src/cmd/machines.rs @@ -3,7 +3,7 @@ use cadcraft_doc::Handle; use serde_json::{Value, json}; -use crate::{Accept, EngineError, Input, Interactive, Prompt, Result, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, PointInput, Prompt, Result, Session, Step}; /// A "Select objects:" phase. Uses the pickfirst selection when there is one. #[derive(Clone, Debug, Default)] @@ -249,7 +249,7 @@ mod tests { // COPYBASE asks for the base point first, then for objects. s.start("copybase").unwrap(); assert!(s.prompt_text().contains("Specify base point"), "{}", s.prompt_text()); - s.input(Input::Point(Vec2::new(3.0, 4.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(3.0, 4.0)))).unwrap(); assert!(s.prompt_text().contains("Select objects"), "{}", s.prompt_text()); s.input(Input::Pick(vec![hs[0]])).unwrap(); s.input(Input::Enter).unwrap(); diff --git a/crates/engine/src/cmd/mleader_edit.rs b/crates/engine/src/cmd/mleader_edit.rs index ee61346055..b9b3e0292a 100644 --- a/crates/engine/src/cmd/mleader_edit.rs +++ b/crates/engine/src/cmd/mleader_edit.rs @@ -10,7 +10,7 @@ use serde_json::{Value, json}; use super::helpers::v3; use super::machines::{SelOutcome, SelectPhase}; use super::*; -use crate::{Accept, Input, Interactive, Prompt, Result, Session, Step}; +use crate::{Accept, Input, Interactive, PointInput, Prompt, Result, Session, Step}; /// Most arrowheads added by one call, and most multileaders aligned / collected by one call. const MAX_ITEMS: usize = 10_000; @@ -243,7 +243,8 @@ impl Interactive for EditM { self.remove = kw_is(&k, "Remove leaders"); Ok(Step::Continue) } - Input::Point(pt) => { + Input::Point(pi) => { + let pt = pi.point(); if self.remove { let Some(m) = get_mleader(s, h) else { return Ok(Step::Cancel) }; match nearest_leader(&m, pt) { @@ -557,7 +558,7 @@ impl Interactive for AlignM { } return Ok(Step::Continue); } - let Input::Point(pt) = i else { return Ok(Step::Continue) }; + let Input::Point(PointInput::Picked(pt)) = i else { return Ok(Step::Continue) }; if self.mode() == Spacing::Parallel { return self.finish(s, None); } @@ -764,7 +765,8 @@ impl Interactive for CollectM { } Ok(Step::Continue) } - Input::Point(at) => { + Input::Point(pi) => { + let at = pi.point(); let r = collect(s, &self.picked, at, self.layout, None)?; s.set_selection(Vec::new()); s.echo(format!("{} multileader(s) collected.", r.get("collected").and_then(Value::as_u64).unwrap_or(0))); diff --git a/crates/engine/src/cmd/mleader_edit_tests.rs b/crates/engine/src/cmd/mleader_edit_tests.rs index 304a5ecebe..3c82eec06b 100644 --- a/crates/engine/src/cmd/mleader_edit_tests.rs +++ b/crates/engine/src/cmd/mleader_edit_tests.rs @@ -2,7 +2,7 @@ use cadcraft_doc::{EntityKind, Handle, MLeader}; use cadcraft_geom::Vec2; use serde_json::{Value, json}; -use crate::{Input, Session}; +use crate::{Input, PointInput, Session}; fn hd(v: &Value) -> Handle { Handle::parse_hex(v["handle"].as_str().unwrap_or("0")).unwrap_or(Handle(0)) @@ -34,13 +34,13 @@ fn edit_adds_and_removes_leaders() { // Interactive: Add Leader then Remove Leader, one undo step each. s.start("mleaderedit.add").unwrap(); s.input(Input::Pick(vec![h])).unwrap(); - s.input(Input::Point(Vec2::new(-3.0, 2.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(-3.0, 2.0)))).unwrap(); s.input(Input::Enter).unwrap(); assert!(s.running.is_none()); assert_eq!(ml(&s, h).leaders.len(), 3); s.start("mleaderedit.remove").unwrap(); s.input(Input::Pick(vec![h])).unwrap(); - s.input(Input::Point(Vec2::new(-3.0, 2.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(-3.0, 2.0)))).unwrap(); s.input(Input::Enter).unwrap(); assert_eq!(ml(&s, h).leaders.len(), 2); } @@ -75,8 +75,8 @@ fn align_distribute_parallel_and_spacing() { s.input(Input::Pick(vec![b, c])).unwrap(); s.input(Input::Enter).unwrap(); s.input(Input::Pick(vec![a])).unwrap(); - s.input(Input::Point(Vec2::new(0.0, 0.0))).unwrap(); - s.input(Input::Point(Vec2::new(0.0, 1.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(0.0, 0.0)))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(0.0, 1.0)))).unwrap(); assert!(s.running.is_none()); assert!((ml(&s, b).landing.x - ml(&s, a).landing.x).abs() < 1e-9); } diff --git a/crates/engine/src/cmd/modify.rs b/crates/engine/src/cmd/modify.rs index cbb199f69e..a427a46249 100644 --- a/crates/engine/src/cmd/modify.rs +++ b/crates/engine/src/cmd/modify.rs @@ -373,8 +373,9 @@ impl StretchM { fn select(&mut self, s: &mut Session, i: Input) -> Result { if let Some(mut m) = self.mode.take() { match &i { - Input::Point(p) => { - if m.push(*p) { + Input::Point(pi) => { + let p = pi.point(); + if m.push(p) { self.finish_mode(s, m)?; } else { self.mode = Some(m); @@ -396,25 +397,28 @@ impl StretchM { } } match i { - Input::Point(p) => match self.corner.take() { - Some(c) => { - let bx = cadcraft_geom::Bounds2::new(c, p); - let space = s.space(); - let hs = crate::select::select_window(s.doc()?, &space, bx, p.x < c.x); - if !self.removing { - self.windows.push(StretchArea::Box(bx)); + Input::Point(pi) => { + let p = pi.point(); + match self.corner.take() { + Some(c) => { + let bx = cadcraft_geom::Bounds2::new(c, p); + let space = s.space(); + let hs = crate::select::select_window(s.doc()?, &space, bx, p.x < c.x); + if !self.removing { + self.windows.push(StretchArea::Box(bx)); + } + self.add(s, hs, false); } - self.add(s, hs, false); - } - None => { - let aperture = s.pixel_size() * s.settings.pickbox.max(1.0) * 1.5; - let space = s.space(); - match crate::select::pick(s.doc()?, &space, p, aperture) { - Some(h) => self.add(s, vec![h], true), - None => self.corner = Some(p), + None => { + let aperture = s.pixel_size() * s.settings.pickbox.max(1.0) * 1.5; + let space = s.space(); + match crate::select::pick(s.doc()?, &space, p, aperture) { + Some(h) => self.add(s, vec![h], true), + None => self.corner = Some(p), + } } } - }, + } Input::Pick(hs) => self.add(s, hs, true), Input::Text(t) | Input::Keyword(t) => { self.corner = None; @@ -498,7 +502,8 @@ impl Interactive for StretchM { fn input(&mut self, s: &mut Session, i: Input) -> Result { match (self.phase, i) { (StretchPhase::Select, i) => self.select(s, i), - (StretchPhase::Base, Input::Point(p)) => { + (StretchPhase::Base, Input::Point(pi)) => { + let p = pi.point(); self.base = Some(p); self.phase = StretchPhase::Second; Ok(Step::Continue) @@ -511,9 +516,9 @@ impl Interactive for StretchM { self.phase = StretchPhase::Displacement; Ok(Step::Continue) } - (StretchPhase::Displacement, Input::Point(p)) => self.apply(s, p), + (StretchPhase::Displacement, Input::Point(pi)) => self.apply(s, pi.point()), (StretchPhase::Displacement, Input::Enter) => Ok(Step::Done), - (StretchPhase::Second, Input::Point(p)) => self.apply(s, p - self.base.unwrap_or(p)), + (StretchPhase::Second, Input::Point(pi)) => self.apply(s, pi.point() - self.base.unwrap_or(pi.point())), (StretchPhase::Second, Input::Enter) => self.apply(s, self.base.unwrap_or(Vec2::ZERO)), _ => Ok(Step::Continue), } @@ -1796,7 +1801,8 @@ impl SelectThen { fn scale_reference(&mut self, s: &mut Session, i: Input) -> Result { let Some(base) = self.pts.first().copied() else { return Ok(Step::Done) }; match (self.ref_len, self.ref_from, i) { - (None, None, Input::Point(p)) => { + (None, None, Input::Point(pi)) => { + let p = pi.point(); self.ref_from = Some(p); Ok(Step::Continue) } @@ -1808,11 +1814,12 @@ impl SelectThen { self.ref_len = Some(1.0); Ok(Step::Continue) } - (None, Some(a), Input::Point(p)) => { + (None, Some(a), Input::Point(pi)) => { + let p = pi.point(); self.ref_len = Some(require_length(Some(a.dist(p)))?); Ok(Step::Continue) } - (Some(r), _, Input::Point(p)) => self.scale_by(s, base, base.dist(p) / r), + (Some(r), _, Input::Point(pi)) => self.scale_by(s, base, base.dist(pi.point()) / r), (Some(r), _, Input::Text(t)) => { let n = require_length(number(&t))?; self.scale_by(s, base, n / r) @@ -1834,10 +1841,11 @@ impl SelectThen { }; let Some(r) = self.ref_angle else { match (self.ref_from, i) { - (None, Input::Point(p)) => self.ref_from = Some(p), + (None, Input::Point(pi)) => self.ref_from = Some(pi.point()), (None, Input::Text(t)) => self.ref_angle = Some(angle(&t)?), (None, Input::Enter) => self.ref_angle = Some(0.0), - (Some(a), Input::Point(p)) => { + (Some(a), Input::Point(pi)) => { + let p = pi.point(); self.ref_angle = Some(two_points(a, p)?); self.ref_from = None; } @@ -1850,14 +1858,15 @@ impl SelectThen { self.ref_points = true; return Ok(Step::Continue); } - (false, _, Input::Point(p)) => base.angle_to(p), + (false, _, Input::Point(pi)) => base.angle_to(pi.point()), (false, _, Input::Text(t)) => angle(&t)?, (false, _, Input::Enter) => 0.0, - (true, None, Input::Point(p)) => { + (true, None, Input::Point(pi)) => { + let p = pi.point(); self.ref_from = Some(p); return Ok(Step::Continue); } - (true, Some(a), Input::Point(p)) => two_points(a, p)?, + (true, Some(a), Input::Point(pi)) => two_points(a, pi.point())?, _ => return Ok(Step::Continue), }; transform_entities(s, &self.objs, &Mat3::rotate_about(base, new - r), self.copy_mode)?; @@ -2054,11 +2063,13 @@ impl Interactive for SelectThen { s.set_selection(Vec::new()); Ok(Step::Done) } - (_, 0, Input::Point(p)) => { + (_, 0, Input::Point(pi)) => { + let p = pi.point(); self.pts.push(p); Ok(Step::Continue) } - (Op::Move, 1, Input::Point(p)) => { + (Op::Move, 1, Input::Point(pi)) => { + let p = pi.point(); let d = p - self.pts[0]; transform_entities(s, &self.objs, &Mat3::translate(d), false)?; s.set_selection(Vec::new()); @@ -2070,7 +2081,8 @@ impl Interactive for SelectThen { s.set_selection(Vec::new()); Ok(Step::Done) } - (Op::Copy, _, Input::Point(p)) => { + (Op::Copy, _, Input::Point(pi)) => { + let p = pi.point(); let d = p - self.pts[0]; transform_entities(s, &self.objs, &Mat3::translate(d), true)?; Ok(Step::Continue) @@ -2081,7 +2093,10 @@ impl Interactive for SelectThen { } (Op::Rotate, 1, inp @ (Input::Point(_) | Input::Text(_) | Input::Enter)) => { let a = match inp { - Input::Point(p) => self.pts[0].angle_to(p), + Input::Point(pi) => { + let p = pi.point(); + self.pts[0].angle_to(p) + } Input::Text(t) => s .angle_settings() .rotation(&t) @@ -2096,7 +2111,10 @@ impl Interactive for SelectThen { } (Op::Scale, 1, inp @ (Input::Point(_) | Input::Text(_) | Input::Enter)) => { let f = match inp { - Input::Point(p) => self.pts[0].dist(p), + Input::Point(pi) => { + let p = pi.point(); + self.pts[0].dist(p) + } Input::Text(t) => { number(&t).filter(|f| f.is_finite() && *f > 0.0).ok_or_else(|| EngineError::Other("Requires a positive number.".into()))? } @@ -2109,7 +2127,8 @@ impl Interactive for SelectThen { s.set_selection(Vec::new()); Ok(Step::Done) } - (Op::Mirror, 1, Input::Point(p)) => { + (Op::Mirror, 1, Input::Point(pi)) => { + let p = pi.point(); if p.near(self.pts[0], 1e-12) { return Err(EngineError::Other("Mirror line points must differ.".into())); } @@ -2322,7 +2341,8 @@ impl Interactive for OffsetM { let d = number(&t).ok_or_else(|| EngineError::Other("Requires a positive distance.".into()))?; self.set_distance(s, d)?; } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); if !p.is_finite() { return Err(EngineError::Other("Invalid point.".into())); } @@ -2387,7 +2407,8 @@ impl Interactive for OffsetM { s.set_selection(Vec::new()); Ok(Step::Done) } - (None, Input::Point(p)) => { + (None, Input::Point(pi)) => { + let p = pi.point(); let ap = s.pixel_size() * s.settings.pickbox.max(1.0) * 1.5; let space = s.space(); match crate::select::pick(s.doc()?, &space, p, ap) { @@ -2399,7 +2420,8 @@ impl Interactive for OffsetM { } Ok(Step::Continue) } - (Some(h), Input::Point(p)) => { + (Some(h), Input::Point(pi)) => { + let p = pi.point(); let e = s.doc()?.entity(h).map(|e| (**e).clone()); let mut made = None; if let Some(e) = e { @@ -2648,7 +2670,8 @@ impl Interactive for FilletM { s.set_selection(Vec::new()); Ok(Step::Continue) } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let ap = s.pixel_size() * s.settings.pickbox.max(1.0) * 1.5; let space = s.space(); let Some(h) = crate::select::pick(s.doc()?, &space, p, ap) else { @@ -2904,7 +2927,8 @@ impl Interactive for BreakM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match (self.obj, i) { - (None, Input::Point(p)) => { + (None, Input::Point(pi)) => { + let p = pi.point(); let ap = s.pixel_size() * s.settings.pickbox.max(1.0) * 1.5; let space = s.space(); match crate::select::pick(s.doc()?, &space, p, ap) { @@ -2920,12 +2944,14 @@ impl Interactive for BreakM { self.first_point = true; Ok(Step::Continue) } - (Some((h, _)), Input::Point(p1)) if self.first_point => { + (Some((h, _)), Input::Point(pi)) if self.first_point => { + let p1 = pi.point(); self.obj = Some((h, p1)); self.first_point = false; Ok(Step::Continue) } - (Some((h, p1)), Input::Point(p2)) => { + (Some((h, p1)), Input::Point(pi)) => { + let p2 = pi.point(); break_entity(s, h, p1, p2)?; s.set_selection(Vec::new()); Ok(Step::Done) @@ -2972,7 +2998,10 @@ impl Interactive for DisplaceM { fn input(&mut self, s: &mut Session, i: Input) -> Result { if self.displacement { let d = match i { - Input::Point(p) => p, + Input::Point(pi) => { + let p = pi.point(); + p + } Input::Enter => Vec2::ZERO, _ => return Ok(Step::Continue), }; diff --git a/crates/engine/src/cmd/modify2.rs b/crates/engine/src/cmd/modify2.rs index e6493e526f..54b56f46ea 100644 --- a/crates/engine/src/cmd/modify2.rs +++ b/crates/engine/src/cmd/modify2.rs @@ -517,7 +517,8 @@ impl Interactive for PeditM { }; match self.phase { PPhase::Select => match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; let k = curves::entity(s, h)?.kind; self.h = Some(h); @@ -649,7 +650,8 @@ impl Interactive for PeditM { Ok(Step::Continue) } PPhase::VMove | PPhase::VInsert => { - if let Input::Point(p) = i { + if let Input::Point(pi) = i { + let p = pi.point(); let action = if self.phase == PPhase::VMove { "move" } else { "insert" }; self.apply(s, "vertex", json!({ "action": action, "index": self.vertex, "to": [p.x, p.y] }))?; if action == "insert" { @@ -921,8 +923,9 @@ impl Interactive for LengthenM { let au = s.angle_settings(); let ang = |i: &Input| -> Option { if let Input::Text(t) = i { au.amount(t) } else { None } }; match (self.phase, &i) { - (LPhase::Main, Input::Point(p)) => { - let h = curves::pick_at(s, *p).ok_or_else(|| other("*Invalid selection*"))?; + (LPhase::Main, Input::Point(pi)) => { + let p = pi.point(); + let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; let k = curves::entity(s, h)?.kind; match measure_len(&k) { Some((l, Some(a))) => s.echo(format!("Current length: {l:.4}, included angle: {:.0}", a.to_degrees())), @@ -979,22 +982,24 @@ impl Interactive for LengthenM { self.phase = LPhase::Change; Ok(Step::Continue) } - (LPhase::Change, Input::Point(p)) => { - let h = curves::pick_at(s, *p).ok_or_else(|| other("*Invalid selection*"))?; + (LPhase::Change, Input::Point(pi)) => { + let p = pi.point(); + let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; if self.dynamic { - self.phase = LPhase::DynEnd(h, *p); + self.phase = LPhase::DynEnd(h, p); return Ok(Step::Continue); } let mode = self.mode.ok_or_else(|| other("No lengthen mode."))?; let k = curves::entity(s, h)?.kind; - let nk = lengthen_kind(&k, Some(*p), mode)?; + let nk = lengthen_kind(&k, Some(p), mode)?; set_kind(s, h, nk)?; self.history.push((h, k)); Ok(Step::Continue) } - (LPhase::DynEnd(h, pick), Input::Point(p)) => { + (LPhase::DynEnd(h, pick), Input::Point(pi)) => { + let p = pi.point(); let k = curves::entity(s, h)?.kind; - let nk = lengthen_kind(&k, Some(pick), LenMode::To(*p))?; + let nk = lengthen_kind(&k, Some(pick), LenMode::To(p))?; set_kind(s, h, nk)?; self.history.push((h, k)); self.phase = LPhase::Change; @@ -1110,7 +1115,8 @@ impl Interactive for AlignM { return self.finish(s, yes); } match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); if self.pts.len() < 4 { self.pts.push(p); } else { @@ -1237,7 +1243,8 @@ impl Interactive for BlendM { self.asking = true; Ok(Step::Continue) } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; match self.first { None => { @@ -1630,7 +1637,8 @@ impl Interactive for NcopyM { fn input(&mut self, s: &mut Session, i: Input) -> Result { if !self.selecting_done { return match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; let leaf = nearest_leaf(leaves_of(s, h)?, p).ok_or_else(|| other("Nothing nested there."))?; s.echo(format!("Nested object: {}", leaf.1.type_name())); @@ -1654,7 +1662,8 @@ impl Interactive for NcopyM { }; } match (self.base, i) { - (None, Input::Point(p)) => { + (None, Input::Point(pi)) => { + let p = pi.point(); self.base = Some(p); Ok(Step::Continue) } @@ -1662,7 +1671,8 @@ impl Interactive for NcopyM { place_copies(s, &self.items, Vec2::ZERO)?; Ok(Step::Done) } - (Some(b), Input::Point(p)) => { + (Some(b), Input::Point(pi)) => { + let p = pi.point(); place_copies(s, &self.items, p - b)?; Ok(Step::Done) } @@ -2142,7 +2152,8 @@ impl Interactive for PathArrayM { }; } match (self.path, i) { - (None, Input::Point(p)) => { + (None, Input::Point(pi)) => { + let p = pi.point(); let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; Chain::of(&curves::entity(s, h)?.kind).ok_or_else(|| other("Select a curve as the path."))?; self.path = Some(h); @@ -2243,7 +2254,8 @@ impl Interactive for TextEditM { return Ok(Step::Continue); } match (&self.h, i) { - (None, Input::Point(p)) => { + (None, Input::Point(pi)) => { + let p = pi.point(); let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; let old = text_of(&curves::entity(s, h)?.kind).ok_or_else(|| other("Select a text, mtext, attribute definition or dimension."))?; self.h = Some((h, old)); diff --git a/crates/engine/src/cmd/modify2/pedit_vertex.rs b/crates/engine/src/cmd/modify2/pedit_vertex.rs index be0d5d3834..592122d042 100644 --- a/crates/engine/src/cmd/modify2/pedit_vertex.rs +++ b/crates/engine/src/cmd/modify2/pedit_vertex.rs @@ -121,7 +121,10 @@ impl PeditM { pub(super) fn tangent_input(&mut self, s: &mut Session, i: &Input) -> Result<()> { let v = self.poly(s).and_then(|p| p.vertices.get(self.vertex).map(|v| v.p)).ok_or_else(|| other("No vertex."))?; let d = match i { - Input::Point(p) => *p - v, + Input::Point(pi) => { + let p = pi.point(); + p - v + } Input::Text(t) => Vec2::from_angle(s.angle_settings().direction(t).ok_or_else(|| other("Requires a point or an angle."))?), Input::Enter => { self.phase = PPhase::Vertex; diff --git a/crates/engine/src/cmd/modify2/splinedit.rs b/crates/engine/src/cmd/modify2/splinedit.rs index 212433ea72..14b2f14d75 100644 --- a/crates/engine/src/cmd/modify2/splinedit.rs +++ b/crates/engine/src/cmd/modify2/splinedit.rs @@ -549,7 +549,8 @@ impl Interactive for SplineditM { fn input(&mut self, s: &mut Session, i: Input) -> Result { let Some(h) = self.h else { return match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; if !matches!(curves::entity(s, h)?.kind, EntityKind::Spline(_)) { return Err(other("Object selected is not a spline.")); @@ -568,7 +569,10 @@ impl Interactive for SplineditM { }; let kw = k.as_deref().unwrap_or(""); let point = match &i { - Input::Point(p) => Some(*p), + Input::Point(pi) => { + let p = pi.point(); + Some(p) + } _ => None, }; let enter = i == Input::Enter; diff --git a/crates/engine/src/cmd/modify2_tests.rs b/crates/engine/src/cmd/modify2_tests.rs index 7c8f92625d..ad2181c47d 100644 --- a/crates/engine/src/cmd/modify2_tests.rs +++ b/crates/engine/src/cmd/modify2_tests.rs @@ -707,7 +707,7 @@ fn editing_commands_leave_locked_layer_objects_alone() { // The interactive STRETCH (crossing window, base point, second point) too. s.start("stretch").unwrap(); for (x, y) in [(-1.0, -1.0), (11.0, 1.0), (0.0, 0.0), (10.0, 0.0)] { - s.input(crate::Input::Point(Vec2::new(x, y))).unwrap(); + s.input(crate::Input::Point(PointInput::Picked(Vec2::new(x, y)))).unwrap(); } assert_eq!(model_dump(&s), before); // Unlocked, the same edits work. diff --git a/crates/engine/src/cmd/mtext_opts.rs b/crates/engine/src/cmd/mtext_opts.rs index c234271bf8..30e5821270 100644 --- a/crates/engine/src/cmd/mtext_opts.rs +++ b/crates/engine/src/cmd/mtext_opts.rs @@ -186,7 +186,7 @@ impl MTextAsk { } match (self, &i) { (_, Input::Enter) => Ok(if self == MTextAsk::SpacingType { Outcome::Ask(MTextAsk::SpacingFactor) } else { Outcome::Back }), - (MTextAsk::Height, Input::Point(p)) => set_height(s, o, first.dist(*p)), + (MTextAsk::Height, Input::Point(pi)) => set_height(s, o, first.dist(pi.point())), (MTextAsk::Height, Input::Text(t)) => set_height(s, o, number(t).unwrap_or(f64::NAN)), (MTextAsk::Justify, _) => { let k = word(&i).unwrap_or_default(); @@ -214,8 +214,9 @@ impl MTextAsk { .ok_or_else(|| other("Requires a factor between 0.25x and 4x, or a distance."))?; Ok(Outcome::Back) } - (MTextAsk::Rotation, Input::Point(p)) => { - o.rotation = first.angle_to(*p); + (MTextAsk::Rotation, Input::Point(pi)) => { + let p = pi.point(); + o.rotation = first.angle_to(p); Ok(Outcome::Back) } (MTextAsk::Rotation, Input::Text(t)) => { @@ -233,9 +234,10 @@ impl MTextAsk { o.style = d.text_style(&name).map(|t| t.name.clone()).ok_or_else(|| other(format!("Cannot find text style \"{name}\".")))?; Ok(Outcome::Back) } - (MTextAsk::Width, Input::Point(p)) => { + (MTextAsk::Width, Input::Point(pi)) => { + let p = pi.point(); // The distance along the text direction from the first corner. - o.width = Some((*p - first).rotate(-o.rotation).x.abs()); + o.width = Some((p - first).rotate(-o.rotation).x.abs()); Ok(Outcome::Text) } (MTextAsk::Width, Input::Text(t)) => { @@ -261,7 +263,10 @@ fn column_input(q: MTextAsk, i: Input, o: &mut MTextOpts, first: Vec2) -> Result // A distance: typed, picked (along the text or down it from the first corner) or the default. let length = |i: &Input, current: Option, down: bool| -> Result { let v = match i { - Input::Point(p) => Some(if down { local(*p).y.abs() } else { local(*p).x.abs() }), + Input::Point(pi) => { + let p = pi.point(); + Some(if down { local(p).y.abs() } else { local(p).x.abs() }) + } Input::Text(t) => number(t), Input::Enter => current, _ => None, @@ -317,7 +322,10 @@ fn column_input(q: MTextAsk, i: Input, o: &mut MTextOpts, first: Vec2) -> Result let current = o.columns.as_ref().map(|c| c.gutter); let g = match &i { Input::Text(t) => number(t).filter(|g| g.is_finite() && *g >= 0.0), - Input::Point(p) => Some(local(*p).x.abs()), + Input::Point(pi) => { + let p = pi.point(); + Some(local(p).x.abs()) + } Input::Enter => current, _ => None, } diff --git a/crates/engine/src/cmd/pline_opts.rs b/crates/engine/src/cmd/pline_opts.rs index 195a66c96a..9bd622a547 100644 --- a/crates/engine/src/cmd/pline_opts.rs +++ b/crates/engine/src/cmd/pline_opts.rs @@ -140,7 +140,10 @@ impl PlineAsk { // A typed or picked size (distance from the last vertex). let size = |i: &Input| -> Option { match i { - Input::Point(p) => Some(st.dist(*p)), + Input::Point(pi) => { + let p = pi.point(); + Some(st.dist(p)) + } Input::Text(t) => number(t), _ => None, } @@ -166,13 +169,15 @@ impl PlineAsk { (PlineAsk::CenterEnd(c), Input::Keyword(k)) if k == "Angle" => Outcome::Ask(PlineAsk::CenterAngle(c)), (PlineAsk::CenterEnd(c), Input::Keyword(k)) if k == "Length" => Outcome::Ask(PlineAsk::CenterLength(c)), (PlineAsk::RadiusEnd(r), Input::Keyword(k)) if k == "Angle" => Outcome::Ask(PlineAsk::RadiusAngle(r)), - (PlineAsk::Center, Input::Point(c)) => { + (PlineAsk::Center, Input::Point(pi)) => { + let c = pi.point(); if c.near(st, 1e-12) { return Err(invalid()); } Outcome::Ask(PlineAsk::CenterEnd(c)) } - (PlineAsk::Second, Input::Point(m)) => { + (PlineAsk::Second, Input::Point(pi)) => { + let m = pi.point(); if m.near(st, 1e-12) { return Err(invalid()); } @@ -180,7 +185,10 @@ impl PlineAsk { } (PlineAsk::Direction, i) => { let d = match i { - Input::Point(p) => p - st, + Input::Point(pi) => { + let p = pi.point(); + p - st + } Input::Text(t) => Vec2::from_angle(angles.direction(&t).ok_or_else(|| other("Requires an angle."))?), _ => return Err(other("Requires a direction.")), }; @@ -204,7 +212,7 @@ impl PlineAsk { } (PlineAsk::Chord(a, r), i) => { let dir = match i { - Input::Point(p) if !p.near(st, 1e-12) => st.angle_to(p), + Input::Point(pi) if !pi.point().near(st, 1e-12) => st.angle_to(pi.point()), Input::Text(t) => angles.direction(&t).ok_or_else(|| other("Requires an angle."))?, Input::Enter => chord_default(tangent, a), _ => return Err(other("Requires a direction.")), @@ -215,7 +223,7 @@ impl PlineAsk { let l = size(&i).filter(|l| l.is_finite() && *l > 1e-12).ok_or_else(|| other("Requires a positive length."))?; Outcome::Segment(st + tangent * l, 0.0) } - (_, Input::Point(p)) => segment(self.segment_at(st, tangent, p))?, + (_, Input::Point(pi)) => segment(self.segment_at(st, tangent, pi.point()))?, _ => return Err(other("Point or option keyword required.")), }) } diff --git a/crates/engine/src/cmd/plotters.rs b/crates/engine/src/cmd/plotters.rs index 454b977ae6..346ae6c954 100644 --- a/crates/engine/src/cmd/plotters.rs +++ b/crates/engine/src/cmd/plotters.rs @@ -15,7 +15,7 @@ use cadcraft_geom::{Bounds2, Vec2}; use serde_json::{Value, json}; use super::*; -use crate::{Accept, EngineError, Input, Interactive, Prompt, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, PointInput, Prompt, Session, Step}; /// Where plotter configuration files live. Names are file names ending in /// [`cadcraft_doc::PLOTTER_FILE_EXT`]; the engine never passes paths. @@ -370,11 +370,11 @@ impl Interactive for PlotWindowM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match (i, self.first) { - (Input::Point(p), None) => { + (Input::Point(PointInput::Picked(p)), None) => { self.first = Some(p); Ok(Step::Continue) } - (Input::Point(p), Some(a)) => { + (Input::Point(PointInput::Picked(p)), Some(a)) => { set_plot_window(s, a, p)?; Ok(Step::Done) } diff --git a/crates/engine/src/cmd/settings/iso.rs b/crates/engine/src/cmd/settings/iso.rs index 810d2b577b..d704eaa6ca 100644 --- a/crates/engine/src/cmd/settings/iso.rs +++ b/crates/engine/src/cmd/settings/iso.rs @@ -165,7 +165,8 @@ impl IsoCircle { pub(crate) fn input(&mut self, s: &Session, i: Input) -> Result> { let plane = s.settings.isoplane; let Some(c) = self.center else { - if let Input::Point(p) = i { + if let Input::Point(pi) = i { + let p = pi.point(); self.center = Some(p); } return Ok(None); @@ -175,7 +176,10 @@ impl IsoCircle { self.diameter = true; return Ok(None); } - Input::Point(p) => iso::iso_radius(plane, c, p).map(|r| if self.diameter { r / 2.0 } else { r }), + Input::Point(pi) => { + let p = pi.point(); + iso::iso_radius(plane, c, p).map(|r| if self.diameter { r / 2.0 } else { r }) + } Input::Text(t) => { let d = crate::units::parse_distance(&t).ok_or_else(|| EngineError::Other("Requires a distance.".into()))?; Some(if self.diameter { d / 2.0 } else { d }) diff --git a/crates/engine/src/cmd/spline_opts.rs b/crates/engine/src/cmd/spline_opts.rs index a5512db729..32bc070019 100644 --- a/crates/engine/src/cmd/spline_opts.rs +++ b/crates/engine/src/cmd/spline_opts.rs @@ -83,7 +83,8 @@ impl SplineAsk { let start = matches!(self, SplineAsk::StartTangent); let from = if start { pts.first() } else { pts.last() }.copied().unwrap_or_default(); let dir = match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let d = p - from; if d.len() < 1e-12 { return Err(other("The tangent point must differ from the fit point.")); diff --git a/crates/engine/src/cmd/table.rs b/crates/engine/src/cmd/table.rs index be156fb1d2..4a2d8f5754 100644 --- a/crates/engine/src/cmd/table.rs +++ b/crates/engine/src/cmd/table.rs @@ -491,8 +491,9 @@ impl Interactive for TableM { } Ok(Step::Continue) } - (Some(_), Some(_), Input::Point(p)) => { - let t = self.table(*p); + (Some(_), Some(_), Input::Point(pi)) => { + let p = pi.point(); + let t = self.table(p); s.add_entity(EntityKind::Table(t))?; Ok(Step::Done) } diff --git a/crates/engine/src/cmd/table/breaks.rs b/crates/engine/src/cmd/table/breaks.rs index 38ed33bce6..2c9d160123 100644 --- a/crates/engine/src/cmd/table/breaks.rs +++ b/crates/engine/src/cmd/table/breaks.rs @@ -130,7 +130,8 @@ impl Interactive for BreakM { } Ok(Step::Continue) } - (None, Input::Point(p)) => { + (None, Input::Point(pi)) => { + let p = pi.point(); self.table = table_at(s, p); if self.table.is_none() { s.echo("No table there."); diff --git a/crates/engine/src/cmd/table/cells.rs b/crates/engine/src/cmd/table/cells.rs index a2efca4d64..f62f6df21a 100644 --- a/crates/engine/src/cmd/table/cells.rs +++ b/crates/engine/src/cmd/table/cells.rs @@ -455,7 +455,8 @@ impl Interactive for TableEditM { fn input(&mut self, s: &mut Session, i: Input) -> Result { match (&self.cell, i) { (_, Input::Cancel) => Ok(Step::Cancel), - (None, Input::Point(p)) => { + (None, Input::Point(pi)) => { + let p = pi.point(); match cell_under(s, p) { Some(c) => self.cell = Some(c), None => s.echo("No table cell there."), @@ -595,7 +596,8 @@ impl Interactive for ExportM { self.pick(s, &hs); Ok(Step::Continue) } - (None, Input::Point(p)) => { + (None, Input::Point(pi)) => { + let p = pi.point(); match cell_under(s, p) { Some((h, ..)) => self.table = Some(h), None => s.echo("No table there."), diff --git a/crates/engine/src/cmd/tolerance.rs b/crates/engine/src/cmd/tolerance.rs index 1a33a5670f..189eaf7cbe 100644 --- a/crates/engine/src/cmd/tolerance.rs +++ b/crates/engine/src/cmd/tolerance.rs @@ -253,7 +253,8 @@ impl Interactive for ToleranceM { self.step += 1; } _ => match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let t = make(self.style.clone(), p, 0.0, self.text()); s.add_entity(EntityKind::Tolerance(t))?; return Ok(Step::Done); diff --git a/crates/engine/src/cmd/trimextend.rs b/crates/engine/src/cmd/trimextend.rs index 4640c58acb..34a0245d32 100644 --- a/crates/engine/src/cmd/trimextend.rs +++ b/crates/engine/src/cmd/trimextend.rs @@ -434,7 +434,8 @@ impl Interactive for TrimM { } Stage::Fence(mut pts) => { match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); pts.push(p); self.stage = Stage::Fence(pts); } @@ -457,8 +458,9 @@ impl Interactive for TrimM { } Stage::Crossing(first) => { match (first, i) { - (None, Input::Point(p)) => self.stage = Stage::Crossing(Some(p)), - (Some(a), Input::Point(b)) => { + (None, Input::Point(pi)) => self.stage = Stage::Crossing(Some(pi.point())), + (Some(a), Input::Point(pi)) => { + let b = pi.point(); self.stage = Stage::Pick; let r = self.step(s, |m, s| crossing(s, a, b, extending, m.edges(quick, implied), quick).map(|_| ())); if let Err(e) = r { @@ -471,7 +473,8 @@ impl Interactive for TrimM { Ok(Step::Continue) } Stage::Pick => match i { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let ap = s.pixel_size() * s.settings.pickbox.max(1.0) * 1.5; let space = s.space(); let Some(h) = crate::select::pick(s.doc()?, &space, p, ap) else { diff --git a/crates/engine/src/cmd/utility.rs b/crates/engine/src/cmd/utility.rs index 89c00f7a6b..a5b4ed3551 100644 --- a/crates/engine/src/cmd/utility.rs +++ b/crates/engine/src/cmd/utility.rs @@ -156,7 +156,8 @@ impl Interactive for PickM { self.mode = calc::Pick::parse(&k); Ok(Step::Continue) } - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let mode = *self.mode.get_or_insert(calc::Pick::Point); self.pts.push(p); if self.pts.len() >= mode.points() { self.finish(s, mode) } else { Ok(Step::Continue) } diff --git a/crates/engine/src/cmd/view.rs b/crates/engine/src/cmd/view.rs index e6051a6e9d..d82cef6190 100644 --- a/crates/engine/src/cmd/view.rs +++ b/crates/engine/src/cmd/view.rs @@ -443,15 +443,17 @@ impl Interactive for ZoomM { st.set_zoom_frame(View { center: b.center, height: b.height }); return Ok(Step::Done); } - (ZoomStage::Dynamic(mut b), Input::Point(p)) => { - (b.center, b.height) = b.moved(*p); + (ZoomStage::Dynamic(mut b), Input::Point(pi)) => { + let p = pi.point(); + (b.center, b.height) = b.moved(p); b.sizing = !b.sizing; self.stage = ZoomStage::Dynamic(b); return Ok(Step::Continue); } (ZoomStage::Dynamic(_), _) => return Err(crate::EngineError::Other("Requires a point, or Enter to accept the view.".into())), - (ZoomStage::Center, Input::Point(c)) => { - self.stage = ZoomStage::CenterHeight(*c); + (ZoomStage::Center, Input::Point(pi)) => { + let c = pi.point(); + self.stage = ZoomStage::CenterHeight(c); return Ok(Step::Continue); } (ZoomStage::Center, Input::Enter) => return Ok(Step::Done), @@ -503,16 +505,19 @@ impl Interactive for ZoomM { zoom(s, &json!({ "mode": mode }))?; Ok(Step::Done) } - Input::Point(p) => match self.first { - None => { - self.first = Some(p); - Ok(Step::Continue) - } - Some(a) => { - fit(s, Bounds2::new(a, p))?; - Ok(Step::Done) + Input::Point(pi) => { + let p = pi.point(); + match self.first { + None => { + self.first = Some(p); + Ok(Step::Continue) + } + Some(a) => { + fit(s, Bounds2::new(a, p))?; + Ok(Step::Done) + } } - }, + } Input::Text(t) => { // nX: relative to the current view; nXP: to paper space; n: to the limits. let p = typed_factor(&t).ok_or_else(|| crate::EngineError::Other("Requires a point, scale factor or option keyword.".into()))?; @@ -596,11 +601,13 @@ impl Interactive for PanM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match (self.first, i) { - (None, Input::Point(p)) => { + (None, Input::Point(pi)) => { + let p = pi.point(); self.first = Some(p); Ok(Step::Continue) } - (Some(a), Input::Point(b)) => { + (Some(a), Input::Point(pi)) => { + let b = pi.point(); run_pan(s, &json!({ "from": [a.x, a.y], "to": [b.x, b.y] }))?; Ok(Step::Done) } diff --git a/crates/engine/src/cmd/view/named_views.rs b/crates/engine/src/cmd/view/named_views.rs index 40c25632b1..d145347297 100644 --- a/crates/engine/src/cmd/view/named_views.rs +++ b/crates/engine/src/cmd/view/named_views.rs @@ -338,7 +338,8 @@ impl Interactive for ViewM { report(s, |s| save(s, &name, None, snapshot)) } Stage::WindowFirst => match i { - Input::Point(a) => { + Input::Point(pi) => { + let a = pi.point(); self.stage = Stage::WindowSecond(a); Ok(Step::Continue) } @@ -346,7 +347,8 @@ impl Interactive for ViewM { _ => Err(EngineError::Other("Requires a point.".into())), }, Stage::WindowSecond(a) => match i { - Input::Point(b) => { + Input::Point(pi) => { + let b = pi.point(); let snapshot = s.settings.view_layer_snapshot; let name = std::mem::take(&mut self.name); report(s, |s| save(s, &name, Some(Bounds2::new(a, b)), snapshot)) diff --git a/crates/engine/src/guard.rs b/crates/engine/src/guard.rs index 7d05f1c10c..cbf924a1cf 100644 --- a/crates/engine/src/guard.rs +++ b/crates/engine/src/guard.rs @@ -14,7 +14,7 @@ use cadcraft_doc::EntityKind; use cadcraft_geom::Vec2; use crate::cmd::Factory; -use crate::{Accept, EngineError, Input, Interactive, Prompt, Result, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, PointInput, Prompt, Result, Session, Step}; pub(crate) struct Guarded { inner: Box, @@ -195,14 +195,14 @@ mod tests { assert!(s.preview(at).is_empty()); assert!(s.preview(at).is_empty(), "not called again"); assert!(s.current_prompt().unwrap().message.contains("Internal error")); - assert!(matches!(s.input(Input::Point(at)), Err(EngineError::Internal(_, m)) if m == "panic in preview")); + assert!(matches!(s.input(Input::Point(PointInput::Picked(at))), Err(EngineError::Internal(_, m)) if m == "panic in preview")); assert!(s.running.is_none()); assert_eq!(points(&s), 0, "the drawing is restored"); // Input (already guarded by the session; the wrapper agrees). let mut s = Session::new(); start(&mut s, "input").unwrap(); - assert!(matches!(s.input(Input::Point(Vec2::ZERO)), Err(EngineError::Internal(..)))); + assert!(matches!(s.input(Input::Point(PointInput::Picked(Vec2::ZERO))), Err(EngineError::Internal(..)))); assert!(s.running.is_none()); assert_eq!(points(&s), 0); } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 1bf8e00592..9f9d9026b3 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -47,7 +47,7 @@ pub use cadcraft_geom as geom; pub use cadcraft_render as render; pub use cmd::hatch::{HatchPicks, PatternChoice, PickMode, pattern_choices}; pub use cmd::{CommandInfo, CommandSpec, command_specs, find_command}; -pub use prompt::{Accept, Drag, Input, Interactive, Picker, Prompt, Step}; +pub use prompt::{Accept, Drag, Input, Interactive, Picker, PointInput, Prompt, Step}; #[derive(Debug, thiserror::Error)] pub enum EngineError { @@ -651,11 +651,6 @@ pub struct Session { /// The last segment given at a point prompt (its base point and the point): polar angles /// relative to the last segment (POLARMODE bit 1) are measured from it. pub last_segment: Option<(Vec2, Vec2)>, - /// The last typed `@distance, /// Point modifiers pending at the current point prompt (`FROM`, `M2P`, `.x`, `, /// Cursor position in world coordinates (from the UI; used for direct distance entry). @@ -725,7 +720,6 @@ impl Session { last_command: None, last_point: Vec2::ZERO, last_segment: None, - last_polar: None, point_mods: Vec::new(), cursor: Vec2::ZERO, cursor_deferred: None, @@ -952,7 +946,6 @@ impl Session { /// Start a command by name or alias as if typed at the command line. pub fn start(&mut self, name: &str) -> Result<()> { - self.last_polar = None; let name = name.trim(); let (transparent, name) = match name.strip_prefix('\'') { Some(n) => (true, n), @@ -1080,7 +1073,7 @@ impl Session { // A deferred snap is only meaningful where the prompt resolves it; elsewhere it is the // point it was picked at. let input = match input { - Input::Deferred(d) if !self.current_prompt().is_some_and(|p| p.deferred) => Input::Point(d.at), + Input::Deferred(d) if !self.current_prompt().is_some_and(|p| p.deferred) => Input::Point(PointInput::Picked(d.at)), other => other, }; // Generic selection handling during "Select objects:" prompts. @@ -1139,7 +1132,8 @@ impl Session { } let space = self.space(); match input { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); let ap = self.pixel_size() * self.settings.pickbox.max(1.0) * 1.5; if let Some(pw) = self.pending_window.take() { let crossing = p.x < pw.corner.x; @@ -1201,7 +1195,8 @@ impl Session { }; } match input { - Input::Point(p) => { + Input::Point(pi) => { + let p = pi.point(); if mode.push(p) { return Ok(mode.select(self.doc()?, &self.space()).map(Input::Pick)); } @@ -1224,10 +1219,11 @@ impl Session { let step = match input { Some(Input::Cancel) => Ok(Step::Cancel), Some(i) => { - if let Input::Point(p) = &i { - self.last_point = *p; - if let Some(b) = base.filter(|b| b.is_finite() && p.is_finite() && b.dist(*p) > 1e-12) { - self.last_segment = Some((b, *p)); + if let Input::Point(pi) = &i { + let p = pi.point(); + self.last_point = p; + if let Some(b) = base.filter(|b| b.is_finite() && p.is_finite() && b.dist(p) > 1e-12) { + self.last_segment = Some((b, p)); } // A temporary tracking point (TT) serves one point. self.tracking.release_temporary(); @@ -1555,7 +1551,7 @@ impl Session { lisp::value::Value::Real(r) => self.typed(&format!("{r}")), lisp::value::Value::Str(s) => self.typed(&s), other => match other.as_point() { - Some(p) => self.input(Input::Point(Vec2::new(p[0], p[1]))), + Some(p) => self.input(Input::Point(PointInput::Picked(Vec2::new(p[0], p[1])))), None => { self.echo(format!("Invalid input: {}", lisp::value::to_text(&other, true))); Ok(()) @@ -1577,16 +1573,15 @@ impl Session { return self.input(Input::Keyword(k)); } if prompt.accept.point { - if let Some(p) = prompt::parse_point_with(tt, self.last_point, &self.angle_settings()) { - self.last_polar = prompt::parse_polar_text(tt, &self.angle_settings()); - return self.input(Input::Point(p)); + if let Some(pi) = prompt::parse_point_input(tt, self.last_point, &self.angle_settings()) { + return self.input(Input::Point(pi)); } // Direct distance entry along the tracking path the cursor is on, from the point it // comes from (an acquired or temporary tracking point needs no base point). if let Some(dist) = units::parse_distance(tt).filter(|_| !prompt.accept.number) && let Some((from, dir)) = self.tracking.last.as_ref().filter(|t| t.point.near(self.cursor, 1e-9)).and_then(|t| t.along()) { - return self.input(Input::Point(from + dir * dist)); + return self.input(Input::Point(PointInput::Picked(from + dir * dist))); } // Direct distance entry along the rubber band. if let (Some(base), Some(dist)) = (prompt.base, units::parse_distance(tt)) @@ -1598,7 +1593,7 @@ impl Session { } let dir = (c - base).normalized(); let dir = if dir == Vec2::ZERO { Vec2::X } else { dir }; - return self.input(Input::Point(base + dir * dist)); + return self.input(Input::Point(PointInput::Picked(base + dir * dist))); } } self.input(Input::Text(tt.to_string())) diff --git a/crates/engine/src/lisp/drawing.rs b/crates/engine/src/lisp/drawing.rs index 53c7af8689..ba985bbaf7 100644 --- a/crates/engine/src/lisp/drawing.rs +++ b/crates/engine/src/lisp/drawing.rs @@ -17,7 +17,7 @@ use super::LispError; use super::builtins::args_err; use super::eval::{Ctx, Flow, Need}; use super::value::{PickSet, Value, to_text}; -use crate::{Input, Session}; +use crate::{Input, PointInput, Session}; fn arity(a: &[Value], min: usize, max: usize) -> Result<(), LispError> { if a.len() < min { @@ -112,7 +112,7 @@ pub fn command(ctx: &mut Ctx<'_>, a: Vec) -> Result { Value::PickSet(p) => feed(ctx.s, Input::Pick(items(p))), Value::Cons(_) => { if let Some(p) = arg.as_point() { - feed(ctx.s, Input::Point(Vec2::new(p[0], p[1]))); + feed(ctx.s, Input::Point(PointInput::Picked(Vec2::new(p[0], p[1])))); } else if let Value::Ename(h) = arg.car() { // An `entsel` result: (ename point). feed(ctx.s, Input::Pick(vec![h])); diff --git a/crates/engine/src/lisp/input.rs b/crates/engine/src/lisp/input.rs index d12dcbbce7..8d26e05334 100644 --- a/crates/engine/src/lisp/input.rs +++ b/crates/engine/src/lisp/input.rs @@ -106,7 +106,10 @@ impl GetRequest { Ok(Value::Nil) } Input::Keyword(k) => Ok(Value::str(&k)), - Input::Point(p) => self.point(s, [p.x, p.y, 0.0]), + Input::Point(pi) => { + let p = pi.point(); + self.point(s, [p.x, p.y, 0.0]) + } // A deferred tangent/perpendicular snap is the point it was picked at here. Input::Deferred(d) => self.point(s, [d.at.x, d.at.y, 0.0]), Input::Pick(hs) => match (self.kind, hs.first()) { diff --git a/crates/engine/src/lisp/tests.rs b/crates/engine/src/lisp/tests.rs index 9104e2525f..be4f1adafd 100644 --- a/crates/engine/src/lisp/tests.rs +++ b/crates/engine/src/lisp/tests.rs @@ -457,7 +457,7 @@ fn interactive_routine_waits_for_the_user() { s.cmdline("PT").unwrap(); assert!(s.lisp_running()); assert_eq!(s.prompt_text(), "Where: "); - s.input(crate::Input::Point(cadcraft_geom::Vec2::new(3.0, 4.0))).unwrap(); + s.input(crate::Input::Point(PointInput::Picked(cadcraft_geom::Vec2::new(3.0, 4.0)))).unwrap(); assert!(!s.lisp_running()); assert!(s.doc().unwrap().model.iter().any(|e| matches!(&e.kind, cadcraft_doc::EntityKind::Circle(c) if c.center.x == 3.0 && c.center.y == 4.0))); // Typed answers and keywords. @@ -474,7 +474,7 @@ fn interactive_routine_waits_for_the_user() { // `pause` lets the user answer one prompt of a command. s.cmdline("(command \"_.CIRCLE\" pause 2)").unwrap(); assert!(s.lisp_running()); - s.input(crate::Input::Point(cadcraft_geom::Vec2::new(50.0, 50.0))).unwrap(); + s.input(crate::Input::Point(PointInput::Picked(cadcraft_geom::Vec2::new(50.0, 50.0)))).unwrap(); assert!(!s.lisp_running()); assert!(s.doc().unwrap().model.iter().any(|e| matches!(&e.kind, cadcraft_doc::EntityKind::Circle(c) if c.center.x == 50.0 && c.radius == 2.0))); } @@ -591,7 +591,7 @@ fn a_waiting_routine_is_a_prompt_with_a_rubber_band() { // getcorner drags a rectangle from its corner. let band = s.preview(cadcraft_geom::Vec2::new(3.0, 2.0)); assert_eq!(band.len(), 4); - s.input(crate::Input::Point(cadcraft_geom::Vec2::new(3.0, 2.0))).unwrap(); + s.input(crate::Input::Point(PointInput::Picked(cadcraft_geom::Vec2::new(3.0, 2.0)))).unwrap(); assert!(!s.prompting()); // getpoint with a base point drags a line; without one, nothing. s.cmdline("(getpoint '(1 1))").unwrap(); diff --git a/crates/engine/src/pointmod.rs b/crates/engine/src/pointmod.rs index 74c1ab0835..47f27bc44c 100644 --- a/crates/engine/src/pointmod.rs +++ b/crates/engine/src/pointmod.rs @@ -12,7 +12,7 @@ use cadcraft_doc::{Drawing, Space}; use cadcraft_geom::Vec2; -use crate::prompt::{Accept, Input, Prompt}; +use crate::prompt::{Accept, Input, PointInput, Prompt}; use crate::snap::{SnapHit, mode}; use crate::{Result, Session}; @@ -267,7 +267,10 @@ impl Session { return self.input(input); } match input { - Input::Point(p) => self.modifier_point(p), + Input::Point(pi) => { + let p = pi.point(); + self.modifier_point(p) + } // A deferred tangent/perpendicular picked under a TAN/PER override. Input::Deferred(d) if matches!(self.point_mods.as_slice(), [Frame::Snap { .. }]) => { self.point_mods.clear(); @@ -360,7 +363,7 @@ impl Session { } } self.point_mods.clear(); - self.feed(Some(Input::Point(p))) + self.feed(Some(Input::Point(PointInput::Picked(p)))) } } diff --git a/crates/engine/src/prompt.rs b/crates/engine/src/prompt.rs index b9c45eae79..3c72c94e0b 100644 --- a/crates/engine/src/prompt.rs +++ b/crates/engine/src/prompt.rs @@ -68,16 +68,6 @@ pub struct Prompt { pub picks_one: bool, } -/// Parse `@distance Option<(f64, f64)> { - let body = text.trim().strip_prefix('@')?; // relative form only - let (d, a) = body.split_once('<')?; - let dist = d.trim().parse::().ok()?; - let angle = angles.amount(a.trim())?; - (dist.is_finite() && angle.is_finite()).then_some((dist, angle)) -} - /// A visual chooser for a prompt ([`Prompt::picker`]). #[derive(Clone, Debug, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] @@ -188,11 +178,45 @@ impl Prompt { } } +/// A point the user supplied, and the form they used. +/// +/// Commands that only need the coordinate call [`PointInput::point`]. +/// Commands that can use the semantic (direction, distance, snap type) +/// match on the variant. +#[derive(Clone, Debug, PartialEq, Serialize)] +pub enum PointInput { + /// `x,y` or `x,y,z` typed at the command line. + Absolute(Vec2), + /// `@dx,dy`. + RelativeCartesian { at: Vec2, delta: Vec2 }, + /// `@d Vec2 { + match self { + PointInput::Absolute(p) | PointInput::Picked(p) => *p, + PointInput::RelativeCartesian { at, delta } => *at + *delta, + PointInput::RelativePolar { at, dist, angle } => *at + Vec2::new(angle.cos(), angle.sin()) * *dist, + PointInput::DirectDistance { base, dist, dir } => *base + *dir * *dist, + PointInput::Snapped { at, .. } => *at, + } + } +} + /// An input to the active command. #[derive(Clone, Debug, PartialEq, Serialize)] #[serde(tag = "kind", content = "value", rename_all = "camelCase")] pub enum Input { - Point(Vec2), + Point(PointInput), /// A deferred tangent/perpendicular snap, only sent to prompts that accept it /// (`Prompt.deferred`). Deferred(crate::snap::Deferred), @@ -265,10 +289,9 @@ pub struct Drag { pub fn parse_point(text: &str, last: Vec2) -> Option { parse_point_with(text, last, &crate::units::AngleSettings::default()) } - -/// `parse_point` with polar angles read per `angles` (AUNITS, ANGBASE, ANGDIR); `d< Option { +/// Parse a typed point into its [`PointInput`] form, preserving the semantics +/// the user typed (`@d Option { let t = text.trim(); if t.is_empty() { return None; @@ -283,13 +306,12 @@ pub fn parse_point_with(text: &str, last: Vec2, angles: &crate::units::AngleSett (false, t) }; if rel && body.is_empty() { - return Some(last); + return Some(PointInput::Absolute(last)); } - let p = if let Some((d, a)) = body.split_once('<') { + let pi = if let Some((d, a)) = body.split_once('<') { let dist = crate::units::parse_distance(d)?; - // `d< = body.split(',').collect(); if parts.len() < 2 || parts.len() > 3 { @@ -300,10 +322,15 @@ pub fn parse_point_with(text: &str, last: Vec2, angles: &crate::units::AngleSett if let Some(z) = parts.get(2) { crate::units::parse_distance(z)?; } - Vec2::new(x, y) + let d = Vec2::new(x, y); + if rel { PointInput::RelativeCartesian { at: last, delta: d } } else { PointInput::Absolute(d) } }; - let r = if rel { last + p } else { p }; - r.is_finite().then_some(r) + pi.point().is_finite().then_some(pi) +} +/// `parse_point` with polar angles read per `angles` (AUNITS, ANGBASE, ANGDIR); `d< Option { + parse_point_input(text, last, angles).map(|pi| pi.point()) } #[cfg(test)] diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index 3b38b976f6..fb9f33aaa2 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -7,6 +7,7 @@ mod viewport; pub use viewport::ViewportPoint; +use crate::PointInput; use cadcraft_doc::{Drawing, EntityKind, Insert, MAX_BLOCK_DEPTH, Prim, Space}; use cadcraft_geom::{Bounds2, Circle, EPS, Ellipse, Mat3, PI, Segment, Vec2, intersect_ext}; use serde::Serialize; @@ -69,7 +70,7 @@ impl SnapHit { pub fn input(&self) -> crate::Input { match self.deferred { Some(d) => crate::Input::Deferred(d), - None => crate::Input::Point(self.point), + None => crate::Input::Point(PointInput::Picked(self.point)), } } } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index f205c2ea0f..378af67054 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -188,8 +188,8 @@ fn move_with_pickfirst_and_window_selection() { s.state_mut().unwrap().set_view(View { center: Vec2::new(3.0, 3.0), height: 10.0 }); // Window selection from left to right picks only the first line. s.cmdline("move").unwrap(); - s.input(Input::Point(Vec2::new(-1.0, -1.0))).unwrap(); - s.input(Input::Point(Vec2::new(2.0, 1.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(-1.0, -1.0)))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(2.0, 1.0)))).unwrap(); s.input(Input::Enter).unwrap(); s.cmdline("0,0").unwrap(); s.cmdline("10,0").unwrap(); @@ -695,7 +695,7 @@ fn every_interactive_command_starts_and_cancels() { s.start(c.id).unwrap(); let _ = s.prompt_text(); let _ = s.preview(Vec2::new(1.0, 1.0)); - s.input(Input::Point(Vec2::new(1.0, 2.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(1.0, 2.0)))).unwrap(); let _ = s.preview(Vec2::new(3.0, 1.0)); s.cancel(); assert!(s.running.is_none(), "{} still running", c.id); @@ -985,7 +985,7 @@ fn mleader_and_qdim() { fn snap_click(s: &mut Session, at: Vec2) { let prompt = s.current_prompt().unwrap(); let hit = snap::osnap(s.doc().unwrap(), &cadcraft_doc::Space::Model, at, 0.5, s.settings.osmode, prompt.base, prompt.deferred); - s.input(hit.map_or(Input::Point(at), |h| h.input())).unwrap(); + s.input(hit.map_or(Input::Point(PointInput::Picked(at)), |h| h.input())).unwrap(); } fn line_ends(s: &Session) -> Vec<(Vec2, Vec2)> { @@ -1230,7 +1230,7 @@ fn press_and_drag_selection_window() { s.set_selection(Vec::new()); s.cmdline("erase").unwrap(); assert!(s.begin_window(Vec2::new(-1.0, -1.0))); - s.input(Input::Point(Vec2::new(11.0, 1.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(11.0, 1.0)))).unwrap(); s.input(Input::Enter).unwrap(); assert_eq!(kinds(&s), vec!["Circle"]); // A drawing command never opens one, and neither does a hostile point. diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 983214190c..4586a8a232 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -3,8 +3,8 @@ use cadcraft_color::Rgb; use cadcraft_doc::Handle; -use cadcraft_engine::Input; use cadcraft_engine::snap::{self, SnapHit}; +use cadcraft_engine::{Input, PointInput}; use cadcraft_geom::{Bounds2, Vec2}; use cadcraft_render::{DisplayList, Kind}; use egui::{Color32, Pos2, Rect, Sense, Shape, Stroke, pos2, vec2}; @@ -1555,7 +1555,7 @@ pub fn show(app: &mut CadApp, ui: &mut egui::Ui) { let w = effective_point(app, xf.to_world(*pos), &xf, ui.ctx()); let result = match app.canvas.snap { Some(hit) => app.session.input_snapped(hit), - None => app.session.input(Input::Point(w)), + None => app.session.input(Input::Point(PointInput::Picked(w))), }; if let Err(e) = result { app.session.echo(e.to_string()); @@ -1658,7 +1658,7 @@ pub fn show(app: &mut CadApp, ui: &mut egui::Ui) { // Preserve a snap's viewport origin for DIST, and its deferred curve where needed. let result = match app.canvas.snap { Some(hit) => app.session.input_snapped(hit), - None => app.session.input(Input::Point(p)), + None => app.session.input(Input::Point(PointInput::Picked(p))), }; if let Err(e) = result { app.session.echo(e.to_string()); @@ -1695,7 +1695,11 @@ pub fn show(app: &mut CadApp, ui: &mut egui::Ui) { && let Some(end) = ui.input(|i| i.pointer.interact_pos()) { let end = xf.to_world(end); - let done = if app.session.prompting() { app.session.input(Input::Point(end)) } else { app.session.idle_click(end, mods.shift) }; + let done = if app.session.prompting() { + app.session.input(Input::Point(PointInput::Picked(end))) + } else { + app.session.idle_click(end, mods.shift) + }; if let Err(e) = done { app.session.echo(e.to_string()); } @@ -2045,7 +2049,7 @@ fn edit_text_at(app: &mut CadApp, p: Vec2) -> bool { return false; } app.start("textedit"); - if let Err(e) = app.session.input(Input::Point(p)) { + if let Err(e) = app.session.input(Input::Point(PointInput::Picked(p))) { app.session.echo(e.to_string()); } true @@ -2881,7 +2885,7 @@ pub(crate) mod tests { let ctx = egui::Context::default(); painted_text(&mut app, &ctx, pos2(700.0, 450.0)); app.session.cmdline("line").unwrap(); - app.session.input(Input::Point(Vec2::ZERO)).unwrap(); + app.session.input(Input::Point(PointInput::Picked(Vec2::ZERO))).unwrap(); let at = app.canvas.xf.unwrap().to_screen(Vec2::ZERO) + vec2(130.0, -70.0); painted_text(&mut app, &ctx, at); let text = painted_text(&mut app, &ctx, at); diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index bc6d23ef56..6286a46ae6 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -25,7 +25,7 @@ use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::mpsc::{Receiver, Sender}; use std::time::Duration; -use cadcraft_engine::Input; +use cadcraft_engine::{Input, PointInput}; use cadcraft_geom::Vec2; use serde_json::{Value, json}; @@ -374,7 +374,7 @@ pub fn handle(app: &mut CadApp, ctx: &egui::Context, req: &ControlRequest) -> Ou } let r = match s("button").unwrap_or("left") { "right" => app.session.input(Input::Enter), - _ if app.session.prompting() => app.session.input(Input::Point(wp)), + _ if app.session.prompting() => app.session.input(Input::Point(PointInput::Picked(wp))), _ => app.session.idle_click(wp, p.get("shift").and_then(Value::as_bool).unwrap_or(false)), }; match r { diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 12a7d8d09f..0c2b8501d8 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -446,7 +446,7 @@ mod tests { assert!(app.session.running.as_ref().is_some_and(|r| r.id == "insert")); assert_eq!(app.session.current_prompt().map(|p| p.message), Some("Specify insertion point".to_string())); - app.session.input(Input::Point(Vec2::new(5.0, 6.0))).unwrap(); + app.session.input(Input::Point(PointInput::Picked(Vec2::new(5.0, 6.0)))).unwrap(); // X scale, Y scale and rotation take their defaults. for _ in 0..3 { app.session.input(Input::Enter).unwrap(); diff --git a/crates/ui-egui/src/grip_dyn.rs b/crates/ui-egui/src/grip_dyn.rs index 35714b5c7c..4d1495f1c5 100644 --- a/crates/ui-egui/src/grip_dyn.rs +++ b/crates/ui-egui/src/grip_dyn.rs @@ -11,8 +11,8 @@ //! Enter sends the typed value to the command as a number. use cadcraft_doc::Handle; -use cadcraft_engine::Input; use cadcraft_engine::grip_dims::{GripDim, GripDimKind, grip_dims, resolve}; +use cadcraft_engine::{Input, PointInput}; use cadcraft_geom::Vec2; use egui::{Color32, Pos2, Rect, Shape, Stroke, pos2, vec2}; @@ -129,7 +129,7 @@ pub fn submit(app: &mut CadApp) -> bool { let p = resolve(&dims, &vals, cursor); app.cmd.buffer.clear(); app.canvas.grip_dyn = GripDyn::default(); - if let Err(e) = app.session.input(Input::Point(p)) { + if let Err(e) = app.session.input(Input::Point(PointInput::Picked(p))) { app.session.echo(e.to_string()); } true @@ -297,7 +297,7 @@ mod tests { run_frame(&mut app, &ctx, vec![Event::Text("c".into())]); run_frame(&mut app, &ctx, key(egui::Key::Enter)); assert!(app.session.running.is_some()); - app.session.input(Input::Point(Vec2::new(10.0, 10.0))).unwrap(); + app.session.input(Input::Point(PointInput::Picked(Vec2::new(10.0, 10.0)))).unwrap(); let lines = app.session.doc().unwrap().model.iter().filter(|e| matches!(e.kind, EntityKind::Line(_))).count(); assert_eq!(lines, 2, "Copy mode stretched a copy"); } diff --git a/crates/ui-egui/src/hatchdlg.rs b/crates/ui-egui/src/hatchdlg.rs index 6a0ad2206f..2663bdda35 100644 --- a/crates/ui-egui/src/hatchdlg.rs +++ b/crates/ui-egui/src/hatchdlg.rs @@ -631,7 +631,7 @@ mod tests { assert!(app.session.prompt_text().contains("Pick internal point")); resume(&mut app); assert_eq!(app.ui.dialog, None, "still picking"); - app.session.input(cadcraft_engine::Input::Point(Vec2::new(5.0, 5.0))).unwrap(); + app.session.input(cadcraft_engine::Input::Point(PointInput::Picked(Vec2::new(5.0, 5.0)))).unwrap(); app.session.input(cadcraft_engine::Input::Enter).unwrap(); resume(&mut app); assert_eq!(app.ui.dialog.as_deref(), Some("hatch")); @@ -648,7 +648,7 @@ mod tests { } let before = app.hatch_dlg.clone(); start_pick(&mut app, PickMode::Points); - app.session.input(cadcraft_engine::Input::Point(Vec2::new(5.0, 5.0))).unwrap(); + app.session.input(cadcraft_engine::Input::Point(PointInput::Picked(Vec2::new(5.0, 5.0)))).unwrap(); app.session.cancel(); resume(&mut app); assert_eq!(app.ui.dialog.as_deref(), Some("hatch")); @@ -660,7 +660,7 @@ mod tests { let (mut app, _) = app_with_rect(); open_create(&mut app, false); start_pick(&mut app, PickMode::Points); - app.session.input(cadcraft_engine::Input::Point(Vec2::new(5.0, 5.0))).unwrap(); + app.session.input(cadcraft_engine::Input::Point(PointInput::Picked(Vec2::new(5.0, 5.0)))).unwrap(); app.session.input(cadcraft_engine::Input::Enter).unwrap(); app.session.new_drawing(false); resume(&mut app); diff --git a/crates/ui-egui/src/mtext_editor.rs b/crates/ui-egui/src/mtext_editor.rs index 9e7db5803b..813e8c1337 100644 --- a/crates/ui-egui/src/mtext_editor.rs +++ b/crates/ui-egui/src/mtext_editor.rs @@ -480,8 +480,8 @@ mod tests { assert!(ctx.data_mut(|d| d.get_temp::(state_id())).is_none()); app.start("mtext"); assert!(app.session.editing_mtext().is_none(), "no box yet"); - app.session.input(cadcraft_engine::Input::Point(cadcraft_geom::Vec2::new(1.0, 1.0))).unwrap(); - app.session.input(cadcraft_engine::Input::Point(cadcraft_geom::Vec2::new(6.0, 0.0))).unwrap(); + app.session.input(cadcraft_engine::Input::Point(PointInput::Picked(cadcraft_geom::Vec2::new(1.0, 1.0)))).unwrap(); + app.session.input(cadcraft_engine::Input::Point(PointInput::Picked(cadcraft_geom::Vec2::new(6.0, 0.0)))).unwrap(); let m = app.session.editing_mtext().expect("box known"); assert!((m.width - 5.0).abs() < 1e-9, "{}", m.width); frame(&mut app); From 7b2857ec13e30254cd9a37aea41c6649307db14f Mon Sep 17 00:00:00 2001 From: william-wwh <60587573+william-wwh@users.noreply.github.com> Date: Sun, 18 Oct 2026 19:16:24 +0800 Subject: [PATCH 3/9] fix: handle all PointInput variants in commands and update test suite --- crates/engine/src/cmd/annotate.rs | 6 +++--- crates/engine/src/cmd/annotate_dimedit.rs | 4 ++-- crates/engine/src/cmd/array.rs | 7 ++++--- crates/engine/src/cmd/draw2.rs | 8 ++++---- crates/engine/src/cmd/hatch.rs | 3 ++- crates/engine/src/cmd/machines.rs | 4 ++-- crates/engine/src/cmd/mleader_edit.rs | 5 +++-- crates/engine/src/cmd/modify2_tests.rs | 2 +- crates/engine/src/cmd/plotters.rs | 10 +++++----- crates/engine/src/guard.rs | 4 ++-- crates/engine/src/lisp/tests.rs | 2 +- crates/engine/tests/clipboard.rs | 4 ++-- crates/engine/tests/it/break_join_locked_layers.rs | 10 +++++----- crates/engine/tests/it/dyn_input.rs | 4 ++-- crates/engine/tests/it/dynamic_grips.rs | 4 ++-- crates/engine/tests/it/grip_dim_input.rs | 4 ++-- crates/engine/tests/it/group_selection.rs | 10 +++++----- crates/engine/tests/it/hatch_dialog_helpers.rs | 12 ++++++------ crates/engine/tests/it/measure_distance_snapping.rs | 8 ++++---- crates/engine/tests/it/point_modifiers.rs | 8 ++++---- crates/engine/tests/it/snap_overrides.rs | 4 ++-- crates/ui-egui/src/dialogs.rs | 2 +- crates/ui-egui/src/hatchdlg.rs | 2 +- crates/ui-egui/src/mtext_editor.rs | 2 +- crates/ui-egui/tests/it/context_menu.rs | 4 ++-- 25 files changed, 68 insertions(+), 65 deletions(-) diff --git a/crates/engine/src/cmd/annotate.rs b/crates/engine/src/cmd/annotate.rs index ef5a9153d3..38a10cfafa 100644 --- a/crates/engine/src/cmd/annotate.rs +++ b/crates/engine/src/cmd/annotate.rs @@ -10,7 +10,7 @@ use serde_json::{Value, json}; use super::helpers::v3; use super::machines::{SelOutcome, SelectPhase, SelectRun}; use super::*; -use crate::{Accept, EngineError, Input, Interactive, LeaderOrder, MLeaderOptions, PointInput, Prompt, Result, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, LeaderOrder, MLeaderOptions, Prompt, Result, Session, Step}; pub fn specs() -> Vec { vec![ @@ -1370,8 +1370,8 @@ impl Interactive for ArcLenM { } if let Some(picked) = self.partial.take() { match (i, picked.first().copied(), self.arc) { - (Input::Point(PointInput::Picked(p)), None, _) => self.partial = Some(vec![p]), - (Input::Point(PointInput::Picked(q)), Some(p), Some(g)) => match arc_part(&g, p, q) { + (Input::Point(pi), None, _) => self.partial = Some(vec![pi.point()]), + (Input::Point(pi), Some(p), Some(g)) => match arc_part(&g, p, pi.point()) { Some(part) => self.arc = Some(part), None => s.echo("The two points must be different."), }, diff --git a/crates/engine/src/cmd/annotate_dimedit.rs b/crates/engine/src/cmd/annotate_dimedit.rs index af0f66d4a9..a7af1f32f6 100644 --- a/crates/engine/src/cmd/annotate_dimedit.rs +++ b/crates/engine/src/cmd/annotate_dimedit.rs @@ -7,7 +7,7 @@ use serde_json::{Value, json}; use super::machines::{SelOutcome, SelectPhase}; use super::*; -use crate::{Accept, Input, Interactive, PointInput, Prompt, Result, Session, Step}; +use crate::{Accept, Input, Interactive, Prompt, Result, Session, Step}; /// Most objects DIMBREAK Auto looks at, and most breaks it adds to one dimension. const MAX_BREAK_OBJECTS: usize = 20_000; @@ -329,7 +329,7 @@ impl Interactive for JoggedM { return Ok(Step::Continue); } match (self.circle, self.center, self.at, i) { - (None, _, _, Input::Point(PointInput::Picked(p))) => match pick_at(s, p).and_then(|h| circle_of(s, h)) { + (None, _, _, Input::Point(pi)) => match pick_at(s, pi.point()).and_then(|h| circle_of(s, h)) { Some(t) => self.circle = Some(t), None => s.echo("Object selected is not a circle or arc."), }, diff --git a/crates/engine/src/cmd/array.rs b/crates/engine/src/cmd/array.rs index 82839c598e..3085013139 100644 --- a/crates/engine/src/cmd/array.rs +++ b/crates/engine/src/cmd/array.rs @@ -18,7 +18,7 @@ use super::helpers::{line, v3}; use super::machines::{SelOutcome, SelectPhase, number}; use super::modify::transform_entities; use super::*; -use crate::{Accept, EngineError, Input, Interactive, PointInput, Prompt, Result, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, Prompt, Result, Session, Step}; mod edit; @@ -764,12 +764,13 @@ impl Interactive for RectM { } _ => return Err(other("Requires a number.")), }, - (UnitCell, Input::Point(PointInput::Picked(p))) => match self.corner { + (UnitCell, Input::Point(pi)) => match self.corner { None => { - self.corner = Some(*p); + self.corner = Some(pi.point()); UnitCell } Some(c) => { + let p = pi.point(); let (dx, dy) = (p.x - c.x, p.y - c.y); if dx.abs() <= 1e-12 || dy.abs() <= 1e-12 { return Err(other("The unit cell must have a width and a height.")); diff --git a/crates/engine/src/cmd/draw2.rs b/crates/engine/src/cmd/draw2.rs index 9e58388e3f..9dc77a376b 100644 --- a/crates/engine/src/cmd/draw2.rs +++ b/crates/engine/src/cmd/draw2.rs @@ -10,7 +10,7 @@ use super::curves::{self, Chain, MAX_GEN, TanObj}; use super::helpers::*; use super::machines::number; use super::*; -use crate::{Accept, EngineError, Input, Interactive, PointInput, Prompt, Result, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, Prompt, Result, Session, Step}; pub(crate) mod breakline; pub(crate) mod mline; @@ -379,7 +379,7 @@ impl Interactive for SeqM { } let Some((_, ask)) = self.ask() else { return Ok(Step::Done) }; let val = match (&i, ask) { - (Input::Point(PointInput::Picked(q)), _) => self.value_from_point(ask, *q), + (Input::Point(pi), _) => self.value_from_point(ask, pi.point()), (Input::Text(t), Ask::Angle(_) | Ask::Sweep(..)) => { // The tangent direction is a direction; included angles are sizes. let au = s.angle_settings(); @@ -1119,8 +1119,8 @@ impl Interactive for RevcloudM { return Ok(Step::Continue); } if self.object { - let Input::Point(PointInput::Picked(p)) = i else { return if i == Input::Enter { Ok(Step::Cancel) } else { Ok(Step::Continue) } }; - let h = curves::pick_at(s, p).ok_or_else(|| other("*Invalid selection*"))?; + let Input::Point(pi) = i else { return if i == Input::Enter { Ok(Step::Cancel) } else { Ok(Step::Continue) } }; + let h = curves::pick_at(s, pi.point()).ok_or_else(|| other("*Invalid selection*"))?; let pts = object_outline(s, h)?; let vs = cloud_vertices(&pts, self.arc_len, false, false).ok_or_else(|| other("The object has no area."))?; let nh = s.add_entity(cloud_entity(vs, self.calligraphy, self.arc_len))?; diff --git a/crates/engine/src/cmd/hatch.rs b/crates/engine/src/cmd/hatch.rs index 1a2a4a73c3..c4278f4c75 100644 --- a/crates/engine/src/cmd/hatch.rs +++ b/crates/engine/src/cmd/hatch.rs @@ -11,7 +11,7 @@ use serde_json::{Value, json}; use super::helpers::lwpoly; use super::*; -use crate::{Accept, EngineError, Input, Interactive, Picker, PointInput, Prompt, Result, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, Picker, Prompt, Result, Session, Step}; mod assoc; mod edit; @@ -773,6 +773,7 @@ impl Interactive for BoundaryM { #[cfg(test)] mod tests { + use crate::PointInput; use serde_json::json; use super::*; diff --git a/crates/engine/src/cmd/machines.rs b/crates/engine/src/cmd/machines.rs index 5db2a51fce..d851543077 100644 --- a/crates/engine/src/cmd/machines.rs +++ b/crates/engine/src/cmd/machines.rs @@ -3,7 +3,7 @@ use cadcraft_doc::Handle; use serde_json::{Value, json}; -use crate::{Accept, EngineError, Input, Interactive, PointInput, Prompt, Result, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, Prompt, Result, Session, Step}; /// A "Select objects:" phase. Uses the pickfirst selection when there is one. #[derive(Clone, Debug, Default)] @@ -223,7 +223,7 @@ mod tests { use cadcraft_geom::Vec2; use serde_json::json; - use crate::{Input, Session}; + use crate::{Input, PointInput, Session}; /// Menu/typed invocation of selection commands prompts "Select objects" when nothing is selected /// (#126), and acts on the picked objects in one undo step. diff --git a/crates/engine/src/cmd/mleader_edit.rs b/crates/engine/src/cmd/mleader_edit.rs index b9b3e0292a..120871afc0 100644 --- a/crates/engine/src/cmd/mleader_edit.rs +++ b/crates/engine/src/cmd/mleader_edit.rs @@ -10,7 +10,7 @@ use serde_json::{Value, json}; use super::helpers::v3; use super::machines::{SelOutcome, SelectPhase}; use super::*; -use crate::{Accept, Input, Interactive, PointInput, Prompt, Result, Session, Step}; +use crate::{Accept, Input, Interactive, Prompt, Result, Session, Step}; /// Most arrowheads added by one call, and most multileaders aligned / collected by one call. const MAX_ITEMS: usize = 10_000; @@ -558,7 +558,8 @@ impl Interactive for AlignM { } return Ok(Step::Continue); } - let Input::Point(PointInput::Picked(pt)) = i else { return Ok(Step::Continue) }; + let Input::Point(pi) = i else { return Ok(Step::Continue) }; + let pt = pi.point(); if self.mode() == Spacing::Parallel { return self.finish(s, None); } diff --git a/crates/engine/src/cmd/modify2_tests.rs b/crates/engine/src/cmd/modify2_tests.rs index ad2181c47d..a64ccca336 100644 --- a/crates/engine/src/cmd/modify2_tests.rs +++ b/crates/engine/src/cmd/modify2_tests.rs @@ -2,7 +2,7 @@ use cadcraft_doc::{EntityKind, Handle, Space}; use cadcraft_geom::{Arc, Polyline, Vec2}; use serde_json::{Value, json}; -use crate::Session; +use crate::{PointInput, Session}; fn last(s: &Session) -> EntityKind { s.doc().unwrap().model.last().unwrap().kind.clone() diff --git a/crates/engine/src/cmd/plotters.rs b/crates/engine/src/cmd/plotters.rs index 346ae6c954..671c4353b5 100644 --- a/crates/engine/src/cmd/plotters.rs +++ b/crates/engine/src/cmd/plotters.rs @@ -15,7 +15,7 @@ use cadcraft_geom::{Bounds2, Vec2}; use serde_json::{Value, json}; use super::*; -use crate::{Accept, EngineError, Input, Interactive, PointInput, Prompt, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, Prompt, Session, Step}; /// Where plotter configuration files live. Names are file names ending in /// [`cadcraft_doc::PLOTTER_FILE_EXT`]; the engine never passes paths. @@ -370,12 +370,12 @@ impl Interactive for PlotWindowM { } fn input(&mut self, s: &mut Session, i: Input) -> Result { match (i, self.first) { - (Input::Point(PointInput::Picked(p)), None) => { - self.first = Some(p); + (Input::Point(pi), None) => { + self.first = Some(pi.point()); Ok(Step::Continue) } - (Input::Point(PointInput::Picked(p)), Some(a)) => { - set_plot_window(s, a, p)?; + (Input::Point(pi), Some(a)) => { + set_plot_window(s, a, pi.point())?; Ok(Step::Done) } (Input::Cancel, _) => Ok(Step::Cancel), diff --git a/crates/engine/src/guard.rs b/crates/engine/src/guard.rs index cbf924a1cf..488035fc83 100644 --- a/crates/engine/src/guard.rs +++ b/crates/engine/src/guard.rs @@ -14,7 +14,7 @@ use cadcraft_doc::EntityKind; use cadcraft_geom::Vec2; use crate::cmd::Factory; -use crate::{Accept, EngineError, Input, Interactive, PointInput, Prompt, Result, Session, Step}; +use crate::{Accept, EngineError, Input, Interactive, Prompt, Result, Session, Step}; pub(crate) struct Guarded { inner: Box, @@ -107,7 +107,7 @@ impl Interactive for Guarded { #[cfg(test)] mod tests { use super::*; - use crate::Running; + use crate::{PointInput, Running}; fn dot(p: Vec2) -> EntityKind { EntityKind::Point(cadcraft_doc::Point { p: p.to3(0.0), angle: 0.0 }) diff --git a/crates/engine/src/lisp/tests.rs b/crates/engine/src/lisp/tests.rs index be4f1adafd..14ae626a10 100644 --- a/crates/engine/src/lisp/tests.rs +++ b/crates/engine/src/lisp/tests.rs @@ -1,8 +1,8 @@ #![allow(clippy::unwrap_used)] use super::value::{Value, to_text}; -use crate::Session; use crate::cmd::file::{EntityCodec, set_entity_codec}; +use crate::{PointInput, Session}; fn session() -> Session { set_entity_codec(EntityCodec { groups: cadcraft_io::entity_groups, entity: cadcraft_io::entity_from_groups }); diff --git a/crates/engine/tests/clipboard.rs b/crates/engine/tests/clipboard.rs index 03ec408421..56e85a3dc7 100644 --- a/crates/engine/tests/clipboard.rs +++ b/crates/engine/tests/clipboard.rs @@ -4,12 +4,12 @@ use std::sync::{Arc, Mutex}; -use cadcraft_engine::Session; use cadcraft_engine::cmd::clipboard; use cadcraft_engine::cmd::file::{IoHooks, set_io}; use cadcraft_engine::doc::color::Color; use cadcraft_engine::doc::{Block, Common, Drawing, Entity, EntityKind, Handle, Insert, Layer, Line}; use cadcraft_engine::geom::{Vec2, Vec3}; +use cadcraft_engine::{PointInput, Session}; use serde_json::json; fn line(d: &mut Drawing, layer: &str, a: (f64, f64), b: (f64, f64)) -> Entity { @@ -144,7 +144,7 @@ fn pasteorig_pastes_only_into_another_drawing() { // PASTECLIP asks for the insertion point and places the base point there. s.start("pasteclip").unwrap(); assert!(s.prompt_text().contains("insertion point"), "{}", s.prompt_text()); - s.input(cadcraft_engine::Input::Point(Vec2::new(0.0, 0.0))).unwrap(); + s.input(cadcraft_engine::Input::Point(PointInput::Picked(Vec2::new(0.0, 0.0)))).unwrap(); assert!(s.running.is_none()); let pasted = model(&s); assert_eq!(pasted.len(), 4); diff --git a/crates/engine/tests/it/break_join_locked_layers.rs b/crates/engine/tests/it/break_join_locked_layers.rs index 0a1f6e7073..2e7dc395bd 100644 --- a/crates/engine/tests/it/break_join_locked_layers.rs +++ b/crates/engine/tests/it/break_join_locked_layers.rs @@ -1,7 +1,7 @@ //! BREAK, BREAKATPOINT and JOIN leave objects on locked layers alone (#727). use cadcraft_engine::geom::Vec2; -use cadcraft_engine::{Input, Session}; +use cadcraft_engine::{Input, PointInput, Session}; use serde_json::{Value, json}; fn h(r: &Value) -> String { @@ -116,8 +116,8 @@ fn interactive_break_and_join_refuse_locked_lines() { let before = snapshot(&s); // BREAK: pick the line, then the second break point. s.start("break").unwrap(); - s.input(Input::Point(Vec2::new(3.0, 0.0))).unwrap(); - let _ = s.input(Input::Point(Vec2::new(7.0, 0.0))); + s.input(Input::Point(PointInput::Picked(Vec2::new(3.0, 0.0)))).unwrap(); + let _ = s.input(Input::Point(PointInput::Picked(Vec2::new(7.0, 0.0)))); assert!(s.log.last().is_some_and(|m| m.contains("locked layer")), "{:?}", s.log.last()); assert_eq!(snapshot(&s), before); // JOIN on a preselected pair reports the refusal on the command line. @@ -129,7 +129,7 @@ fn interactive_break_and_join_refuse_locked_lines() { // Unlocked, the interactive commands still edit. set_lock(&mut s, false); s.start("break").unwrap(); - s.input(Input::Point(Vec2::new(3.0, 0.0))).unwrap(); - s.input(Input::Point(Vec2::new(7.0, 0.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(3.0, 0.0)))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(7.0, 0.0)))).unwrap(); assert_ne!(snapshot(&s), before); } diff --git a/crates/engine/tests/it/dyn_input.rs b/crates/engine/tests/it/dyn_input.rs index 1e3f9c9880..997582566a 100644 --- a/crates/engine/tests/it/dyn_input.rs +++ b/crates/engine/tests/it/dyn_input.rs @@ -1,6 +1,6 @@ //! Dynamic Input (#519): DYNPROMPT and the options a prompt offers at the cursor. -use cadcraft_engine::{Input, Session, sysvars}; +use cadcraft_engine::{Input, PointInput, Session, sysvars}; use serde_json::json; #[test] @@ -27,7 +27,7 @@ fn an_option_picked_at_the_cursor_answers_the_prompt() { let three_p = kws.iter().find(|k| k.eq_ignore_ascii_case("3P")).cloned().expect("CIRCLE offers 3P"); s.input(Input::Keyword(three_p)).unwrap(); for p in [[0.0, 0.0], [10.0, 0.0], [5.0, 5.0]] { - s.input(Input::Point(cadcraft_geom::Vec2::new(p[0], p[1]))).unwrap(); + s.input(Input::Point(PointInput::Picked(cadcraft_geom::Vec2::new(p[0], p[1])))).unwrap(); } assert!(s.running.is_none()); let doc = s.doc().unwrap(); diff --git a/crates/engine/tests/it/dynamic_grips.rs b/crates/engine/tests/it/dynamic_grips.rs index 75ed1b787f..a03b779ea0 100644 --- a/crates/engine/tests/it/dynamic_grips.rs +++ b/crates/engine/tests/it/dynamic_grips.rs @@ -5,7 +5,7 @@ use cadcraft_engine::doc::dynblock::GripPart; use cadcraft_engine::doc::{Handle, Space}; use cadcraft_engine::geom::Vec2; -use cadcraft_engine::{Input, Session}; +use cadcraft_engine::{Input, PointInput, Session}; use serde_json::{Value, json}; /// DXF text from lines of `code value`. @@ -82,7 +82,7 @@ fn a_grip_drag_previews_the_reference_and_takes_a_point_or_a_distance() { s.start_dyn_grip(h, 2, GripPart::End).unwrap(); // The preview is the reference re-evaluated at the cursor, and the rubber band. assert!(s.preview(Vec2::new(132.0, 0.0)).len() > 1); - s.input(Input::Point(Vec2::new(132.2, 3.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(132.2, 3.0)))).unwrap(); assert!(s.running.is_none()); assert_eq!(width(&mut s, h), "32.0000"); // A typed distance (snapped to the list). diff --git a/crates/engine/tests/it/grip_dim_input.rs b/crates/engine/tests/it/grip_dim_input.rs index f379f9c00f..e47cda3899 100644 --- a/crates/engine/tests/it/grip_dim_input.rs +++ b/crates/engine/tests/it/grip_dim_input.rs @@ -5,7 +5,7 @@ use cadcraft_engine::Session; use cadcraft_engine::doc::{EntityKind, Handle}; use cadcraft_engine::geom::Vec2; use cadcraft_engine::grip_dims::{GripDimKind, grip_dims, resolve}; -use cadcraft_engine::{Input, sysvars}; +use cadcraft_engine::{Input, PointInput, sysvars}; use serde_json::json; fn handle(r: serde_json::Value) -> Handle { @@ -24,7 +24,7 @@ fn kinds(s: &Session) -> Vec { fn place(s: &mut Session, values: &[(usize, f64)], cursor: Vec2) { let dims = grip_dims(s); let p = resolve(&dims, values, cursor); - s.input(Input::Point(p)).unwrap(); + s.input(Input::Point(PointInput::Picked(p))).unwrap(); } #[test] diff --git a/crates/engine/tests/it/group_selection.rs b/crates/engine/tests/it/group_selection.rs index c7d03a91a2..ecbdd94b14 100644 --- a/crates/engine/tests/it/group_selection.rs +++ b/crates/engine/tests/it/group_selection.rs @@ -3,7 +3,7 @@ use cadcraft_engine::doc::Handle; use cadcraft_engine::geom::Vec2; -use cadcraft_engine::{Input, Session}; +use cadcraft_engine::{Input, PointInput, Session}; use serde_json::json; /// Four horizontal lines at y = 0, 5, 10, 15; their handles. @@ -71,7 +71,7 @@ fn select_objects_prompts_pick_groups() { let (mut s, hs) = lines(); s.execute("group", &json!({ "name": "A", "handles": hex(&hs[..2]) })).unwrap(); s.cmdline("erase").unwrap(); - s.input(Input::Point(on(0))).unwrap(); + s.input(Input::Point(PointInput::Picked(on(0)))).unwrap(); s.cmdline("").unwrap(); assert!(s.running.is_none()); let left: Vec = s.doc().unwrap().model.iter().map(|e| e.handle).collect(); @@ -80,7 +80,7 @@ fn select_objects_prompts_pick_groups() { s.execute("u", &json!({})).unwrap(); // GROUPEDIT picks single members while removing. s.cmdline("groupedit n a r").unwrap(); - s.input(Input::Point(on(1))).unwrap(); + s.input(Input::Point(PointInput::Picked(on(1)))).unwrap(); s.cmdline("").unwrap(); assert_eq!(members(&s, "A"), vec![hs[0]]); } @@ -105,11 +105,11 @@ fn dash_group_options_typed() { assert_eq!(members(&s, "Doors"), vec![hs[2], hs[0], hs[1]]); // Add and Remove pick single objects. s.cmdline("-group a doors").unwrap(); - s.input(Input::Point(on(3))).unwrap(); + s.input(Input::Point(PointInput::Picked(on(3)))).unwrap(); s.cmdline("").unwrap(); assert_eq!(members(&s, "Doors").len(), 4); s.cmdline("-group r doors").unwrap(); - s.input(Input::Point(on(0))).unwrap(); + s.input(Input::Point(PointInput::Picked(on(0)))).unwrap(); s.cmdline("").unwrap(); assert_eq!(members(&s, "Doors"), vec![hs[2], hs[1], hs[3]]); // Selectable: Enter accepts the toggle. diff --git a/crates/engine/tests/it/hatch_dialog_helpers.rs b/crates/engine/tests/it/hatch_dialog_helpers.rs index f622d8de00..f05d3c9cb0 100644 --- a/crates/engine/tests/it/hatch_dialog_helpers.rs +++ b/crates/engine/tests/it/hatch_dialog_helpers.rs @@ -137,7 +137,7 @@ fn hatchedit_refuses_a_bad_gradient_and_changes_nothing() { } use cadcraft_engine::geom::Vec2; -use cadcraft_engine::{Input, PickMode}; +use cadcraft_engine::{Input, PickMode, PointInput}; fn h(hex: &str) -> Handle { Handle::parse_hex(hex).unwrap() @@ -151,12 +151,12 @@ fn hatchpick_keeps_points_inside_boundaries_and_changes_nothing() { s.start("hatchpick").unwrap(); s.input(Input::Keyword("Points".into())).unwrap(); assert!(s.prompt_text().contains("Pick internal point"), "{}", s.prompt_text()); - s.input(Input::Point(Vec2::new(5.0, 5.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(5.0, 5.0)))).unwrap(); assert!(!s.preview(Vec2::new(6.0, 6.0)).is_empty(), "the found boundary is previewed"); // Outside every boundary: reported, not kept. - s.input(Input::Point(Vec2::new(50.0, 50.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(50.0, 50.0)))).unwrap(); assert!(s.log.iter().any(|l| l.contains("Valid hatch boundary not found")), "{:?}", s.log); - s.input(Input::Point(Vec2::new(2.0, 2.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(2.0, 2.0)))).unwrap(); s.input(Input::Keyword("Undo".into())).unwrap(); s.input(Input::Enter).unwrap(); assert!(s.running.is_none()); @@ -187,7 +187,7 @@ fn hatchpick_origin_and_hatch_modes() { let hx = handle(&s.execute("hatch", &json!({ "points": [[5, 5]] })).unwrap()); s.start("hatchpick").unwrap(); s.input(Input::Keyword("oRigin".into())).unwrap(); - s.input(Input::Point(Vec2::new(1.0, 2.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(1.0, 2.0)))).unwrap(); assert!(s.running.is_none()); assert_eq!(s.hatch_picks.clone().unwrap().origin, Some(Vec2::new(1.0, 2.0))); s.hatch_picks = None; @@ -208,7 +208,7 @@ fn hatchpick_typed_mode_and_escape_keeps_nothing() { rect(&mut s, [0.0, 0.0], [10.0, 10.0]); s.cmdline("hatchpick points").unwrap(); assert!(s.prompt_text().contains("Pick internal point"), "{}", s.prompt_text()); - s.input(Input::Point(Vec2::new(5.0, 5.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(5.0, 5.0)))).unwrap(); s.cancel(); assert!(s.running.is_none()); assert!(s.hatch_picks.is_none()); diff --git a/crates/engine/tests/it/measure_distance_snapping.rs b/crates/engine/tests/it/measure_distance_snapping.rs index adb3657743..db99e8287f 100644 --- a/crates/engine/tests/it/measure_distance_snapping.rs +++ b/crates/engine/tests/it/measure_distance_snapping.rs @@ -3,7 +3,7 @@ use cadcraft_engine::doc::{Block, Circle, Common, Drawing, Entity, EntityKind, Handle, Insert, Line, Space, Viewport}; use cadcraft_engine::geom::{Vec2, Vec3}; use cadcraft_engine::snap::{SnapCurve, SnapHit, mode, osnap}; -use cadcraft_engine::{Input, Session}; +use cadcraft_engine::{Input, PointInput, Session}; use serde_json::json; fn drawing() -> (Drawing, Space) { @@ -108,9 +108,9 @@ fn typed_and_programmatic_points_are_measured_in_paper_units() { s.start("dist").unwrap(); if snapped_first { s.input_snapped(pick(&s, Vec2::new(95.0, 50.0), mode::END)).unwrap(); - s.input(Input::Point(Vec2::new(100.0, 50.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(100.0, 50.0)))).unwrap(); } else { - s.input(Input::Point(Vec2::new(95.0, 50.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(95.0, 50.0)))).unwrap(); s.input_snapped(pick(&s, Vec2::new(100.0, 50.0), mode::INT)).unwrap(); } assert!(s.log.iter().any(|l| l.starts_with("Distance = 5.0000,")), "{:?}", s.log); @@ -155,7 +155,7 @@ fn multiple_points_length_and_undo_keep_the_measurement_units() { assert_eq!(s.log.last().unwrap(), "Distance = 25.0000"); assert_eq!(s.current_prompt().unwrap().base, Some(Vec2::new(107.5, 50.0))); s.input(Input::Keyword("Undo".into())).unwrap(); - s.input(Input::Point(Vec2::new(102.0, 52.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(102.0, 52.0)))).unwrap(); s.input(Input::Keyword("Undo".into())).unwrap(); s.input(Input::Enter).unwrap(); assert_eq!(s.log.last().unwrap(), "Distance = 20.0000"); diff --git a/crates/engine/tests/it/point_modifiers.rs b/crates/engine/tests/it/point_modifiers.rs index 8155bffe61..35967eb886 100644 --- a/crates/engine/tests/it/point_modifiers.rs +++ b/crates/engine/tests/it/point_modifiers.rs @@ -2,7 +2,7 @@ //! angle override ` Date: Sun, 18 Oct 2026 19:43:03 +0800 Subject: [PATCH 4/9] fix: guard RelativePolar shortcut to TAN and preserve PointInput under NON --- crates/engine/src/cmd/draw.rs | 2 +- crates/engine/src/pointmod.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/draw.rs b/crates/engine/src/cmd/draw.rs index e407d3dc0c..cb3e36bc86 100644 --- a/crates/engine/src/cmd/draw.rs +++ b/crates/engine/src/cmd/draw.rs @@ -428,7 +428,7 @@ impl Interactive for LineM { && let Some(first) = self.first { match i { - Input::Point(pi @ PointInput::RelativePolar { dist, angle, .. }) => { + Input::Point(pi @ PointInput::RelativePolar { dist, angle, .. }) if first.mode == snap::mode::TAN => { // A deferred TAN first point with a typed `@d { + self.point_mods.clear(); + self.input(input) + } Input::Point(pi) => { let p = pi.point(); self.modifier_point(p) From 732719d4faf3a960e4d61055196af82f39f416e6 Mon Sep 17 00:00:00 2001 From: william-wwh <60587573+william-wwh@users.noreply.github.com> Date: Sun, 18 Oct 2026 20:49:54 +0800 Subject: [PATCH 5/9] feat: use DirectDistance and Snapped variants; add coverage --- crates/engine/src/lib.rs | 4 ++-- crates/engine/src/snap.rs | 15 ++++++++++++++- crates/engine/src/tests.rs | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 9f9d9026b3..3c01fd1c85 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -1581,7 +1581,7 @@ impl Session { if let Some(dist) = units::parse_distance(tt).filter(|_| !prompt.accept.number) && let Some((from, dir)) = self.tracking.last.as_ref().filter(|t| t.point.near(self.cursor, 1e-9)).and_then(|t| t.along()) { - return self.input(Input::Point(PointInput::Picked(from + dir * dist))); + return self.input(Input::Point(PointInput::DirectDistance { base: from, dist, dir })); } // Direct distance entry along the rubber band. if let (Some(base), Some(dist)) = (prompt.base, units::parse_distance(tt)) @@ -1593,7 +1593,7 @@ impl Session { } let dir = (c - base).normalized(); let dir = if dir == Vec2::ZERO { Vec2::X } else { dir }; - return self.input(Input::Point(PointInput::Picked(base + dir * dist))); + return self.input(Input::Point(PointInput::DirectDistance { base, dist, dir })); } } self.input(Input::Text(tt.to_string())) diff --git a/crates/engine/src/snap.rs b/crates/engine/src/snap.rs index fb9f33aaa2..192a5858e6 100644 --- a/crates/engine/src/snap.rs +++ b/crates/engine/src/snap.rs @@ -70,7 +70,7 @@ impl SnapHit { pub fn input(&self) -> crate::Input { match self.deferred { Some(d) => crate::Input::Deferred(d), - None => crate::Input::Point(PointInput::Picked(self.point)), + None => crate::Input::Point(PointInput::Snapped { at: self.point, mode: self.mode }), } } } @@ -1029,6 +1029,19 @@ mod tests { d } + #[test] + fn snap_hit_input_preserves_mode() { + let d = drawing(); + let h = osnap(&d, &Space::Model, Vec2::new(9.8, 0.1), 0.5, mode::END, None, false).unwrap(); + assert!(matches!( + h.input(), + crate::Input::Point(PointInput::Snapped { at, mode }) if at == h.point && mode == h.mode + )); + // A deferred TAN is still a Deferred, not a Snapped point. + let t = osnap(&d, &Space::Model, Vec2::new(20.0, 1.95), 0.5, mode::TAN, None, true).unwrap(); + assert!(matches!(t.input(), crate::Input::Deferred(_))); + } + #[test] fn endpoint_and_mid() { let d = drawing(); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 378af67054..38ad9793f6 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -113,6 +113,30 @@ fn undo_during_a_command_without_undo_keyword_ends_it_and_undoes() { assert_eq!(kinds(&s), vec!["Line"]); } +#[test] +fn line_accepts_direct_distance_point_input() { + // A DirectDistance carries the base, distance and direction the user typed. The command + // must draw exactly there, whether the form came from the rubber band or the tracking path. + let mut s = Session::new(); + s.cmdline("line 1,1").unwrap(); + s.input(Input::Point(PointInput::DirectDistance { base: Vec2::new(1.0, 1.0), dist: 4.0, dir: Vec2::new(1.0, 0.0) })).unwrap(); + s.cmdline("").unwrap(); + let ends: Vec<_> = s.doc().unwrap().model.iter().map(|e| e.kind.grips()).collect(); + assert!(ends[0][2].near(Vec2::new(5.0, 1.0), 1e-9)); +} + +#[test] +fn line_accepts_snapped_point_input() { + // A Snapped point is a plain coordinate with the snap mode attached. The command uses the + // coordinate; the mode is there for the callers that care. + let mut s = Session::new(); + s.cmdline("line 0,0").unwrap(); + s.input(Input::Point(PointInput::Snapped { at: Vec2::new(3.0, 4.0), mode: snap::mode::END })).unwrap(); + s.cmdline("").unwrap(); + let ends: Vec<_> = s.doc().unwrap().model.iter().map(|e| e.kind.grips()).collect(); + assert!(ends[0][2].near(Vec2::new(3.0, 4.0), 1e-9)); +} + #[test] fn polar_and_direct_distance() { let mut s = Session::new(); From bc8c08f9384bd96935eb87af1d3b0708eeb2e6ff Mon Sep 17 00:00:00 2001 From: william-wwh <60587573+william-wwh@users.noreply.github.com> Date: Sun, 18 Oct 2026 21:57:16 +0800 Subject: [PATCH 6/9] docs: document how commands consume PointInput --- crates/engine/src/prompt.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/engine/src/prompt.rs b/crates/engine/src/prompt.rs index 3c72c94e0b..23f78f00d9 100644 --- a/crates/engine/src/prompt.rs +++ b/crates/engine/src/prompt.rs @@ -183,6 +183,29 @@ impl Prompt { /// Commands that only need the coordinate call [`PointInput::point`]. /// Commands that can use the semantic (direction, distance, snap type) /// match on the variant. +/// +/// To use a specific form, a command matches on the variant before +/// falling back to the generic arm: +/// +/// ```ignore +/// match input { +/// // match the variant and use its semantic fields: +/// Input::Point(PointInput::RelativePolar { dist, angle, .. }) => { +/// // use dist and angle +/// } +/// // bind the whole PointInput to use both fields and the coordinate: +/// Input::Point(pi @ PointInput::RelativePolar { dist, angle, .. }) => { +/// let coord = pi.point(); +/// // use dist / angle and coord +/// } +/// // generic fallback for commands that only need the coordinate: +/// Input::Point(pi) => { +/// let p = pi.point(); +/// // use p +/// } +/// _ => {} +/// } +/// ``` #[derive(Clone, Debug, PartialEq, Serialize)] pub enum PointInput { /// `x,y` or `x,y,z` typed at the command line. From 7133afbbf62a818d862792714152b479093a1dac Mon Sep 17 00:00:00 2001 From: william-wwh <60587573+william-wwh@users.noreply.github.com> Date: Mon, 19 Oct 2026 00:28:34 +0800 Subject: [PATCH 7/9] refactor: preserve relative semantics for bare @ and deduplicate point() calls --- crates/engine/src/cmd/hatch/edit.rs | 5 ++++- crates/engine/src/cmd/modify.rs | 5 ++++- crates/engine/src/prompt.rs | 11 ++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/hatch/edit.rs b/crates/engine/src/cmd/hatch/edit.rs index f337888e80..34db9efc22 100644 --- a/crates/engine/src/cmd/hatch/edit.rs +++ b/crates/engine/src/cmd/hatch/edit.rs @@ -663,7 +663,10 @@ impl Interactive for HatchEditM { } self.apply(s, Value::Object(self.props.clone())) } - (Ask::Origin, Input::Point(pi)) => self.apply(s, json!({ "origin": [pi.point().x, pi.point().y], "originMode": "current" })), + (Ask::Origin, Input::Point(pi)) => { + let p = pi.point(); + self.apply(s, json!({ "origin": [p.x, p.y], "originMode": "current" })) + } (Ask::Origin, Input::Enter) => Ok(Step::Done), (Ask::Origin, _) => { let mode = match text.as_deref() { diff --git a/crates/engine/src/cmd/modify.rs b/crates/engine/src/cmd/modify.rs index a427a46249..1990a5d86f 100644 --- a/crates/engine/src/cmd/modify.rs +++ b/crates/engine/src/cmd/modify.rs @@ -518,7 +518,10 @@ impl Interactive for StretchM { } (StretchPhase::Displacement, Input::Point(pi)) => self.apply(s, pi.point()), (StretchPhase::Displacement, Input::Enter) => Ok(Step::Done), - (StretchPhase::Second, Input::Point(pi)) => self.apply(s, pi.point() - self.base.unwrap_or(pi.point())), + (StretchPhase::Second, Input::Point(pi)) => { + let p = pi.point(); + self.apply(s, p - self.base.unwrap_or(p)) + } (StretchPhase::Second, Input::Enter) => self.apply(s, self.base.unwrap_or(Vec2::ZERO)), _ => Ok(Step::Continue), } diff --git a/crates/engine/src/prompt.rs b/crates/engine/src/prompt.rs index 23f78f00d9..a9ce49c907 100644 --- a/crates/engine/src/prompt.rs +++ b/crates/engine/src/prompt.rs @@ -235,6 +235,13 @@ impl PointInput { } } +impl From for PointInput { + /// Wrap a bare coordinate as a pick: the form the UI gives when it hands over a click. + fn from(p: Vec2) -> Self { + PointInput::Picked(p) + } +} + /// An input to the active command. #[derive(Clone, Debug, PartialEq, Serialize)] #[serde(tag = "kind", content = "value", rename_all = "camelCase")] @@ -329,7 +336,9 @@ pub fn parse_point_input(text: &str, last: Vec2, angles: &crate::units::AngleSet (false, t) }; if rel && body.is_empty() { - return Some(PointInput::Absolute(last)); + // `@` alone means "zero offset from the last point". Keep it relative so commands that + // look at the form still see a relative input. + return Some(PointInput::RelativeCartesian { at: last, delta: Vec2::ZERO }); } let pi = if let Some((d, a)) = body.split_once('<') { let dist = crate::units::parse_distance(d)?; From 139a7feda4b1c84ac1f2dfd1ae0fa1c5098eeb23 Mon Sep 17 00:00:00 2001 From: william-wwh <60587573+william-wwh@users.noreply.github.com> Date: Mon, 19 Oct 2026 14:57:11 +0800 Subject: [PATCH 8/9] point_input: From maps to Absolute, add semantic and @-prefix tests --- crates/engine/src/prompt.rs | 5 +- crates/engine/tests/bare_at_prefix.rs | 40 +++++++++++ crates/engine/tests/point_input_semantics.rs | 73 ++++++++++++++++++++ 3 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 crates/engine/tests/bare_at_prefix.rs create mode 100644 crates/engine/tests/point_input_semantics.rs diff --git a/crates/engine/src/prompt.rs b/crates/engine/src/prompt.rs index a9ce49c907..e9d73301ab 100644 --- a/crates/engine/src/prompt.rs +++ b/crates/engine/src/prompt.rs @@ -236,9 +236,10 @@ impl PointInput { } impl From for PointInput { - /// Wrap a bare coordinate as a pick: the form the UI gives when it hands over a click. + /// Wrap a bare coordinate as an absolute point: scripts, the API and tests hand over coordinates, + /// not picks. The UI uses [`PointInput::Picked`] explicitly when the user clicks the canvas. fn from(p: Vec2) -> Self { - PointInput::Picked(p) + PointInput::Absolute(p) } } diff --git a/crates/engine/tests/bare_at_prefix.rs b/crates/engine/tests/bare_at_prefix.rs new file mode 100644 index 0000000000..df6faf1456 --- /dev/null +++ b/crates/engine/tests/bare_at_prefix.rs @@ -0,0 +1,40 @@ +use cadcraft_engine::prompt::parse_point_input; +use cadcraft_engine::PointInput; +use cadcraft_geom::Vec2; + +#[test] +fn bare_at_is_a_relative_zero_offset() { + let last = Vec2::new(3.0, 4.0); + let pi = parse_point_input("@", last, &Default::default()).expect("@ alone must parse"); + match pi { + PointInput::RelativeCartesian { at, delta } => { + assert_eq!(at, last, "@ alone must be relative to the last point"); + assert_eq!(delta, Vec2::ZERO, "@ alone must be a zero offset"); + } + other => panic!("@ alone must stay relative, got {other:?}"), + } +} + +#[test] +fn at_star_is_also_a_relative_zero_offset() { + // `@*` and `*@` are the international forms; the `*` prefix marks a keyword elsewhere. + let last = Vec2::new(-1.0, 2.0); + let pi = parse_point_input("@*", last, &Default::default()).expect("@* must parse"); + assert!(matches!(pi, PointInput::RelativeCartesian { delta, .. } if delta == Vec2::ZERO)); +} + +#[test] +fn at_with_numbers_is_still_a_real_offset() { + let last = Vec2::new(1.0, 1.0); + let pi = parse_point_input("@2,3", last, &Default::default()).unwrap(); + assert_eq!(pi.point(), Vec2::new(3.0, 4.0)); + assert!(matches!(pi, PointInput::RelativeCartesian { delta, .. } if delta == Vec2::new(2.0, 3.0))); +} + +#[test] +fn hash_forces_absolute() { + let last = Vec2::new(9.0, 9.0); + let pi = parse_point_input("#2,3", last, &Default::default()).unwrap(); + assert!(matches!(pi, PointInput::Absolute(_)), "# must force absolute"); + assert_eq!(pi.point(), Vec2::new(2.0, 3.0)); +} diff --git a/crates/engine/tests/point_input_semantics.rs b/crates/engine/tests/point_input_semantics.rs new file mode 100644 index 0000000000..f2a5724215 --- /dev/null +++ b/crates/engine/tests/point_input_semantics.rs @@ -0,0 +1,73 @@ +//! Semantic behavior of `PointInput`: the variants must reach the commands as +//! the user meant them, not collapsed into a bare coordinate. + +use cadcraft_doc::{EntityKind, Space}; +use cadcraft_engine::{Input, PointInput, Session}; +use cadcraft_geom::Vec2; +use std::f64::consts::FRAC_PI_4; + +/// The `b` of the last line drawn in model space. +fn last_line_b(s: &Session) -> Vec2 { + let doc = s.doc().unwrap(); + let store = doc.space(&Space::Model).expect("no model space"); + let line = store + .iter() + .filter_map(|e| match &e.kind { + EntityKind::Line(l) => Some(l), + _ => None, + }) + .last() + .expect("no line drawn"); + Vec2::new(line.b.x, line.b.y) +} + +fn draw_to(s: &mut Session, from: Vec2, to: PointInput) { + s.cmdline("line").unwrap(); + s.input(Input::Point(PointInput::Absolute(from))).unwrap(); + s.input(Input::Point(to)).unwrap(); + s.input(Input::Enter).unwrap(); +} + +#[test] +fn relative_polar_reaches_the_command_as_its_point() { + let mut s = Session::new(); + draw_to(&mut s, Vec2::ZERO, PointInput::RelativePolar { at: Vec2::ZERO, dist: 10.0, angle: FRAC_PI_4 }); + let expected = Vec2::new(10.0 * FRAC_PI_4.cos(), 10.0 * FRAC_PI_4.sin()); + assert!(last_line_b(&s).near(expected, 1e-9), "RelativePolar is not measured from its base"); +} + +#[test] +fn relative_polar_is_measured_from_its_own_base() { + let mut s = Session::new(); + let base = Vec2::new(5.0, 7.0); + draw_to(&mut s, base, PointInput::RelativePolar { at: base, dist: 4.0, angle: 0.0 }); + assert!(last_line_b(&s).near(Vec2::new(9.0, 7.0), 1e-9), "RelativePolar ignored its own base"); +} + +#[test] +fn direct_distance_reaches_the_command_as_its_point() { + let mut s = Session::new(); + draw_to(&mut s, Vec2::ZERO, PointInput::DirectDistance { base: Vec2::ZERO, dist: 5.0, dir: Vec2::Y }); + assert!(last_line_b(&s).near(Vec2::new(0.0, 5.0), 1e-9), "DirectDistance is not measured along its direction"); +} + +#[test] +fn absolute_and_picked_land_where_they_say() { + let mut s = Session::new(); + draw_to(&mut s, Vec2::ZERO, PointInput::Absolute(Vec2::new(2.0, 3.0))); + assert!(last_line_b(&s).near(Vec2::new(2.0, 3.0), 1e-9)); + + draw_to(&mut s, Vec2::ZERO, PointInput::Picked(Vec2::new(-4.0, 1.0))); + assert!(last_line_b(&s).near(Vec2::new(-4.0, 1.0), 1e-9)); +} + +#[test] +fn from_vec2_is_absolute_not_a_pick() { + // The UI passes PointInput::Picked explicitly; scripts, the API and tests hand over + // coordinates, which are absolute points, not clicks on the canvas. + let p = Vec2::new(3.0, 4.0); + let pi: PointInput = p.into(); + assert!(matches!(pi, PointInput::Absolute(_)), "From must not be a pick"); + assert_eq!(pi.point(), p); +} + From f4e827b0e31b18183b33217d15399d128b459a79 Mon Sep 17 00:00:00 2001 From: william-wwh <60587573+william-wwh@users.noreply.github.com> Date: Sat, 24 Oct 2026 11:04:58 +0800 Subject: [PATCH 9/9] fix: adapt upstream commands and tests to PointInput --- crates/engine/src/cmd/constraints_tests.rs | 4 ++-- crates/engine/src/cmd/draw2/breakline.rs | 7 ++++--- crates/engine/src/cmd/hatch/edit.rs | 5 ++++- crates/engine/src/cmd/modify.rs | 4 ++-- crates/engine/src/cmd/modify2/mocoro.rs | 16 ++++++++-------- crates/engine/src/cmd/utility.rs | 4 ++-- crates/engine/tests/bare_at_prefix.rs | 2 +- crates/engine/tests/it/arc_ctrl_direction.rs | 14 +++++++------- crates/engine/tests/it/mocoro.rs | 4 ++-- crates/engine/tests/it/rectang_ortho.rs | 6 +++--- crates/engine/tests/point_input_semantics.rs | 1 - crates/ui-egui/src/grip_dyn.rs | 2 +- crates/ui-egui/tests/it/status_bar_toggles.rs | 6 +++--- 13 files changed, 39 insertions(+), 36 deletions(-) diff --git a/crates/engine/src/cmd/constraints_tests.rs b/crates/engine/src/cmd/constraints_tests.rs index 2bb17ec755..5c5556d0ef 100644 --- a/crates/engine/src/cmd/constraints_tests.rs +++ b/crates/engine/src/cmd/constraints_tests.rs @@ -291,8 +291,8 @@ fn dcangular_constrains_the_drawn_angle_whichever_way_the_lines_run() { let a = line(&mut s, [0.0, 0.0], [10.0, 0.0]); let b = line(&mut s, b_pts[0], b_pts[1]); s.cmdline("dcangular").unwrap(); - s.input(Input::Point(Vec2::new(3.0, 0.0))).unwrap(); - s.input(Input::Point(Vec2::new(0.6, 3.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(3.0, 0.0)))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(0.6, 3.0)))).unwrap(); assert!(s.prompt_text().contains("78.69"), "{b_pts:?}: {}", s.prompt_text()); s.cmdline("100").unwrap(); assert!(s.running.is_none()); diff --git a/crates/engine/src/cmd/draw2/breakline.rs b/crates/engine/src/cmd/draw2/breakline.rs index 37e20a4928..511bd12ec6 100644 --- a/crates/engine/src/cmd/draw2/breakline.rs +++ b/crates/engine/src/cmd/draw2/breakline.rs @@ -269,9 +269,10 @@ impl Interactive for BreaklineM { _ => Ask::Points, }; } - (Ask::Points, Input::Point(p)) => match (self.p1, self.p2) { - (None, _) => self.p1 = Some(p), + (Ask::Points, Input::Point(pi)) => match (self.p1, self.p2) { + (None, _) => self.p1 = Some(pi.point()), (Some(a), None) => { + let p = pi.point(); let span = symbol(s, &self.opts.block)?.span() * self.opts.size * dimscale(s); let len = a.dist(p); if len.is_nan() || len < span { @@ -279,7 +280,7 @@ impl Interactive for BreaklineM { } self.p2 = Some(p); } - (Some(_), Some(_)) => return self.finish(s, Some(p)), + (Some(_), Some(_)) => return self.finish(s, Some(pi.point())), }, (Ask::Points, Input::Enter) if self.p2.is_some() => return self.finish(s, None), (Ask::Points, Input::Enter) => return Ok(Step::Cancel), diff --git a/crates/engine/src/cmd/hatch/edit.rs b/crates/engine/src/cmd/hatch/edit.rs index 34db9efc22..b19c9be64e 100644 --- a/crates/engine/src/cmd/hatch/edit.rs +++ b/crates/engine/src/cmd/hatch/edit.rs @@ -609,7 +609,10 @@ impl Interactive for HatchEditM { } Ok(Step::Continue) } - (Ask::AddPoint, Input::Point(p)) => self.apply(s, json!({ "addPoints": [[p.x, p.y]] })), + (Ask::AddPoint, Input::Point(pi)) => { + let p = pi.point(); + self.apply(s, json!({ "addPoints": [[p.x, p.y]] })) + } (Ask::AddObject, Input::Pick(hs)) => self.apply(s, json!({ "addBoundary": hs.iter().map(|h| h.hex()).collect::>() })), (Ask::AddPoint | Ask::AddObject, Input::Enter) => Ok(Step::Done), (Ask::AddPoint | Ask::AddObject, _) => Ok(Step::Continue), diff --git a/crates/engine/src/cmd/modify.rs b/crates/engine/src/cmd/modify.rs index 1990a5d86f..df36a545bc 100644 --- a/crates/engine/src/cmd/modify.rs +++ b/crates/engine/src/cmd/modify.rs @@ -1786,8 +1786,8 @@ impl SelectThen { s.echo(if ellipse { "The elliptical arc is now an ellipse." } else { "The arc is now a circle." }); Ok(Step::Done) } - Input::Point(p) => { - if let Some(h) = super::curves::pick_at(s, p) + Input::Point(pi) => { + if let Some(h) = super::curves::pick_at(s, pi.point()) && !self.objs.contains(&h) { self.objs.push(h); diff --git a/crates/engine/src/cmd/modify2/mocoro.rs b/crates/engine/src/cmd/modify2/mocoro.rs index c701e24aee..8a1c995f95 100644 --- a/crates/engine/src/cmd/modify2/mocoro.rs +++ b/crates/engine/src/cmd/modify2/mocoro.rs @@ -217,8 +217,8 @@ impl Interactive for MocoroM { Ok(Step::Continue) } }, - (Mode::BasePoint, Input::Point(p)) => { - self.base = p; + (Mode::BasePoint, Input::Point(pi)) => { + self.base = pi.point(); self.mode = Mode::Options; Ok(Step::Continue) } @@ -251,16 +251,16 @@ impl Interactive for MocoroM { self.mode = Mode::Options; Ok(Step::Continue) } - (Mode::Move, Input::Point(p)) => self.run(s, Op::Move(p)), - (Mode::Copy, Input::Point(p)) => self.run(s, Op::Copy(p)), - (Mode::Base, Input::Point(p)) => self.run(s, Op::Base(p)), - (Mode::Rotate, Input::Point(p)) => self.run(s, Op::Rotate(self.base.angle_to(p))), + (Mode::Move, Input::Point(pi)) => self.run(s, Op::Move(pi.point())), + (Mode::Copy, Input::Point(pi)) => self.run(s, Op::Copy(pi.point())), + (Mode::Base, Input::Point(pi)) => self.run(s, Op::Base(pi.point())), + (Mode::Rotate, Input::Point(pi)) => self.run(s, Op::Rotate(self.base.angle_to(pi.point()))), (Mode::Rotate, Input::Text(t)) => { let a = s.angle_settings().rotation(&t).filter(|a| a.is_finite()).ok_or_else(|| other("Requires an angle or point."))?; self.run(s, Op::Rotate(a)) } - (Mode::Scale, Input::Point(p)) => { - let f = positive_factor(self.base.dist(p)).ok_or_else(|| other("Requires a positive number."))?; + (Mode::Scale, Input::Point(pi)) => { + let f = positive_factor(self.base.dist(pi.point())).ok_or_else(|| other("Requires a positive number."))?; self.run(s, Op::Scale(f)) } (Mode::Scale, Input::Text(t)) => { diff --git a/crates/engine/src/cmd/utility.rs b/crates/engine/src/cmd/utility.rs index a5b4ed3551..a809c8240e 100644 --- a/crates/engine/src/cmd/utility.rs +++ b/crates/engine/src/cmd/utility.rs @@ -349,8 +349,8 @@ impl Interactive for MeasureM { return m.input(s, i); } if self.radius { - let Input::Point(p) = i else { return Ok(Step::Done) }; - let Some(h) = super::curves::pick_at(s, p) else { return Ok(Step::Continue) }; + let Input::Point(pi) = i else { return Ok(Step::Done) }; + let Some(h) = super::curves::pick_at(s, pi.point()) else { return Ok(Step::Continue) }; match run_radius(s, &json!({ "handle": h.0 })) { Ok(r) => { for l in r["message"].as_str().unwrap_or_default().lines() { diff --git a/crates/engine/tests/bare_at_prefix.rs b/crates/engine/tests/bare_at_prefix.rs index df6faf1456..39baf3eda2 100644 --- a/crates/engine/tests/bare_at_prefix.rs +++ b/crates/engine/tests/bare_at_prefix.rs @@ -1,5 +1,5 @@ -use cadcraft_engine::prompt::parse_point_input; use cadcraft_engine::PointInput; +use cadcraft_engine::prompt::parse_point_input; use cadcraft_geom::Vec2; #[test] diff --git a/crates/engine/tests/it/arc_ctrl_direction.rs b/crates/engine/tests/it/arc_ctrl_direction.rs index 1dcb4d75ef..fb25838827 100644 --- a/crates/engine/tests/it/arc_ctrl_direction.rs +++ b/crates/engine/tests/it/arc_ctrl_direction.rs @@ -11,7 +11,7 @@ use cadcraft_engine::doc::EntityKind; use cadcraft_engine::geom::Vec2; -use cadcraft_engine::{Input, Session}; +use cadcraft_engine::{Input, PointInput, Session}; /// `(center, radius, start angle, end angle)` of the last arc in the model. fn last_arc(s: &Session) -> (Vec2, f64, f64, f64) { @@ -35,15 +35,15 @@ fn sweep(start: f64, end: f64) -> f64 { fn run_continue(ctrl: bool) -> (Vec2, f64, f64, f64) { let mut s = Session::new(); s.cmdline("line").unwrap(); - s.input(Input::Point(Vec2::new(0.0, 0.0))).unwrap(); - s.input(Input::Point(Vec2::new(10.0, 0.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(0.0, 0.0)))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(10.0, 0.0)))).unwrap(); s.input(Input::Enter).unwrap(); s.cmdline("arc").unwrap(); // Enter at the first point prompt continues the last curve. s.input(Input::Enter).unwrap(); assert!(s.prompt_text().contains("hold Ctrl"), "Continue prompt should advertise Ctrl: {}", s.prompt_text()); s.ctrl_down = ctrl; - s.input(Input::Point(Vec2::new(20.0, 5.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(20.0, 5.0)))).unwrap(); last_arc(&s) } @@ -51,11 +51,11 @@ fn run_continue(ctrl: bool) -> (Vec2, f64, f64, f64) { fn run_cse(ctrl: bool) -> (Vec2, f64, f64, f64) { let mut s = Session::new(); s.cmdline("arc c").unwrap(); - s.input(Input::Point(Vec2::new(0.0, 0.0))).unwrap(); - s.input(Input::Point(Vec2::new(5.0, 0.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(0.0, 0.0)))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(5.0, 0.0)))).unwrap(); assert!(s.prompt_text().contains("hold Ctrl"), "Cse end-point prompt should advertise Ctrl: {}", s.prompt_text()); s.ctrl_down = ctrl; - s.input(Input::Point(Vec2::new(0.0, 5.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(0.0, 5.0)))).unwrap(); last_arc(&s) } diff --git a/crates/engine/tests/it/mocoro.rs b/crates/engine/tests/it/mocoro.rs index 88fb8c4ee9..b57a25a6b7 100644 --- a/crates/engine/tests/it/mocoro.rs +++ b/crates/engine/tests/it/mocoro.rs @@ -3,7 +3,7 @@ use cadcraft_engine::doc::{EntityKind, Handle}; use cadcraft_engine::geom::Vec2; -use cadcraft_engine::{Input, Session}; +use cadcraft_engine::{Input, PointInput, Session}; use serde_json::{Value, json}; fn line(s: &mut Session, a: [f64; 2], b: [f64; 2]) -> String { @@ -140,7 +140,7 @@ fn a_point_at_the_option_prompt_is_not_an_option() { let l = line(&mut s, [0.0, 0.0], [10.0, 0.0]); let undo = undo_len(&s); s.script("MOCORO ALL 0,0\n").unwrap(); - s.input(Input::Point(Vec2::new(5.0, 5.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(5.0, 5.0)))).unwrap(); assert!(s.log.iter().any(|m| m.contains("Invalid option keyword")), "{:?}", s.log); assert!(s.running.is_some()); assert!(near(ends(&s, &l), ((0.0, 0.0), (10.0, 0.0)))); diff --git a/crates/engine/tests/it/rectang_ortho.rs b/crates/engine/tests/it/rectang_ortho.rs index 6b6b78cb41..b44a01babb 100644 --- a/crates/engine/tests/it/rectang_ortho.rs +++ b/crates/engine/tests/it/rectang_ortho.rs @@ -2,7 +2,7 @@ //! its area (#1113). use cadcraft_engine::snap::tracking::CursorQuery; -use cadcraft_engine::{Input, Session}; +use cadcraft_engine::{Input, PointInput, Session}; use cadcraft_geom::Vec2; use serde_json::json; @@ -27,7 +27,7 @@ fn click_rectangle(ortho: bool) -> ((Vec2, Vec2), (Vec2, Vec2)) { for e in s.preview(c) { pv = pv.union(&cadcraft_doc::entity_bounds(s.doc().unwrap(), &e, 0)); } - s.input(Input::Point(c)).unwrap(); + s.input(Input::Point(PointInput::Picked(c))).unwrap(); assert!(s.current_prompt().is_none(), "RECTANG is done, still at {:?}", s.current_prompt().map(|p| p.message)); let b = s.doc().unwrap().extents(&s.space()); ((b.min, b.max), (pv.min, pv.max)) @@ -53,7 +53,7 @@ fn click_unit_cell(ortho: bool) -> (Vec2, Vec2) { } assert_eq!(s.current_prompt().unwrap().message, "Specify other corner"); let c = hover(&mut s, Vec2::new(4.0, 2.0)); - s.input(Input::Point(c)).unwrap(); + s.input(Input::Point(PointInput::Picked(c))).unwrap(); s.cmdline("x").unwrap(); assert!(s.current_prompt().is_none(), "ARRAYRECT is done, still at {:?}", s.current_prompt().map(|p| p.message)); let b = s.doc().unwrap().extents(&s.space()); diff --git a/crates/engine/tests/point_input_semantics.rs b/crates/engine/tests/point_input_semantics.rs index f2a5724215..dd6afdeae9 100644 --- a/crates/engine/tests/point_input_semantics.rs +++ b/crates/engine/tests/point_input_semantics.rs @@ -70,4 +70,3 @@ fn from_vec2_is_absolute_not_a_pick() { assert!(matches!(pi, PointInput::Absolute(_)), "From must not be a pick"); assert_eq!(pi.point(), p); } - diff --git a/crates/ui-egui/src/grip_dyn.rs b/crates/ui-egui/src/grip_dyn.rs index 4d1495f1c5..16ffbe7335 100644 --- a/crates/ui-egui/src/grip_dyn.rs +++ b/crates/ui-egui/src/grip_dyn.rs @@ -321,7 +321,7 @@ mod tests { let text = crate::canvas::tests::painted_text(&mut app, &ctx, at); assert_eq!(labels(&text), ["X", "Y"], "the centre is a point:\n{text}"); - app.session.input(Input::Point(Vec2::ZERO)).unwrap(); + app.session.input(Input::Point(PointInput::Picked(Vec2::ZERO))).unwrap(); crate::canvas::tests::painted_text(&mut app, &ctx, at); let text = crate::canvas::tests::painted_text(&mut app, &ctx, at); assert!(labels(&text).is_empty(), "pointer boxes at the radius prompt (DYNPIFORMAT {cartesian}):\n{text}"); diff --git a/crates/ui-egui/tests/it/status_bar_toggles.rs b/crates/ui-egui/tests/it/status_bar_toggles.rs index a9c52cdb29..90436dcd81 100644 --- a/crates/ui-egui/tests/it/status_bar_toggles.rs +++ b/crates/ui-egui/tests/it/status_bar_toggles.rs @@ -3,7 +3,7 @@ use cadcraft_engine::doc::{Drawing, EntityKind, Space}; use cadcraft_engine::geom::Vec2; -use cadcraft_engine::{Input, Session}; +use cadcraft_engine::{Input, PointInput, Session}; use cadcraft_ui_egui::{CadApp, Services}; use egui::vec2; use egui_kittest::Harness; @@ -35,7 +35,7 @@ fn clicking_grid_and_snap_on_the_status_bar_keeps_line_running() { { let s = &mut h.state_mut().session; s.start("line").unwrap(); - s.input(Input::Point(Vec2::new(0.0, 0.0))).unwrap(); + s.input(Input::Point(PointInput::Picked(Vec2::new(0.0, 0.0)))).unwrap(); } h.run_steps(2); h.get_by_label("Grid (F7)").click(); @@ -45,7 +45,7 @@ fn clicking_grid_and_snap_on_the_status_bar_keeps_line_running() { assert_eq!(h.state().session.settings.gridmode, !grid); assert_eq!(h.state().session.settings.snapmode, !snap); assert_eq!(running(&h).as_deref(), Some("line")); - h.state_mut().session.input(Input::Point(Vec2::new(10.0, 0.0))).unwrap(); + h.state_mut().session.input(Input::Point(PointInput::Picked(Vec2::new(10.0, 0.0)))).unwrap(); let lines: Vec<_> = h .state() .session