diff --git a/crates/engine/src/tests/xform.rs b/crates/engine/src/tests/xform.rs index 4e13e5fe02..764b1975b8 100644 --- a/crates/engine/src/tests/xform.rs +++ b/crates/engine/src/tests/xform.rs @@ -480,6 +480,37 @@ fn reflect_and_shear_tools() { assert!((b.width() - 150.0).abs() < 1e-6, "{b:?}"); } +/// Two clicks with the Reflect tool reflect the selection across the line through both points as +/// one undo step; with Alt on the second click, a copy is reflected and Undo removes it. +#[test] +fn two_reflect_clicks_reflect_across_their_line_as_one_undo_step() { + let mut s = session(); + let a = rect(&mut s, 100.0, 100.0, 100.0, 50.0); + s.select_tool("reflect", ViewInfo::default()).unwrap(); + let click = |s: &mut Session, x: f64, y: f64, alt: bool| { + drag_at(s, PointerKind::Down, (x, y), alt); + drag_at(s, PointerKind::Up, (x, y), alt); + }; + let n = undo_len(&s); + click(&mut s, 300.0, 50.0, false); + assert_eq!(undo_len(&s), n); + assert!(close(bounds(&s, a), Rect::new(100.0, 100.0, 200.0, 150.0))); + click(&mut s, 300.0, 250.0, false); + assert!(close(bounds(&s, a), Rect::new(400.0, 100.0, 500.0, 150.0)), "{:?}", bounds(&s, a)); + assert_eq!(undo_len(&s), n + 1); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(close(bounds(&s, a), Rect::new(100.0, 100.0, 200.0, 150.0))); + + let children = |s: &Session| s.doc().unwrap().doc.layers[0].children().unwrap().len(); + click(&mut s, 50.0, 300.0, false); + click(&mut s, 350.0, 300.0, true); + assert_eq!(children(&s), 2); + assert!(close(bounds(&s, a), Rect::new(100.0, 100.0, 200.0, 150.0))); + assert_eq!(undo_len(&s), n + 1); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(children(&s), 1); +} + /// Reflect and Shear return an error for an `axis` they don't take (Reflect's names it and also /// takes an angle): nothing moves and no undo step is recorded. A null `axis` counts as not given: Reflect /// then reflects across the vertical axis and Shear shears along the horizontal one. diff --git a/crates/tools/src/xform/transform.rs b/crates/tools/src/xform/transform.rs index 16a1b93a8a..94b36f96d4 100644 --- a/crates/tools/src/xform/transform.rs +++ b/crates/tools/src/xform/transform.rs @@ -11,9 +11,14 @@ //! onto another object's anchor scales exactly onto it. Scale stretches along the bounding box's //! own width and height, turned with rotated objects until Reset Bounding Box; Reflect's default //! axis is the box's vertical one, and Shift constrains a drawn axis to 45° steps from the box. +//! With the Reflect tool, a click also sets the first point of an axis, and a second click +//! reflects the selection across the line through both points (Alt on it reflects a copy); a +//! drag from there draws the axis from that first point. + +use std::collections::{BTreeMap, BTreeSet}; use serde_json::{Value, json}; -use vectorcraft_doc::{NodeId, OrientedBox}; +use vectorcraft_doc::{AnchorRef, NodeId, OrientedBox}; use vectorcraft_geom::{Affine, Point, Rect, Vec2}; use super::target_overlays; @@ -92,10 +97,24 @@ impl Drag { } } +/// The first point of a Reflect axis set by a click, waiting for the second point, with the +/// selection and the document revision it was set for. +#[derive(Clone, Debug)] +struct Axis { + first: Point, + objects: Vec, + anchors: BTreeMap>, + revision: (u64, u64), +} + pub struct TransformTool { kind: TransformKind, /// Custom reference point and the selection it was set for. origin: Option<(Point, Vec)>, + /// Reflect: the axis whose second point the next click sets. + axis: Option, + /// The snapped pointer while hovering with an axis waiting, where its dashed line ends. + axis_to: Option, drag: Option, measure: Option<(Point, String)>, /// What the Info panel shows for the drag in progress. @@ -128,7 +147,23 @@ pub fn reflect_matrix(o: Point, theta: f64) -> Affine { impl TransformTool { pub fn new(kind: TransformKind) -> Self { - Self { kind, origin: None, drag: None, measure: None, readout: None, hover: vec![], snap: None } + Self { kind, origin: None, axis: None, axis_to: None, drag: None, measure: None, readout: None, hover: vec![], snap: None } + } + + /// The first point of the Reflect axis waiting for its second point, when it was set for the + /// current selection (objects and anchors) and nothing in the document or the selection has + /// changed since, so a selection changed and then changed back does not bring it back. + fn axis_first(&self, cx: &ToolContext) -> Option { + self.axis + .as_ref() + .filter(|a| !a.objects.is_empty() && a.revision == cx.revision && a.objects == cx.selection.objects && a.anchors == cx.selection.anchors) + .map(|a| a.first) + } + + /// Drops the Reflect axis waiting for its second point. + fn drop_axis(&mut self) { + self.axis = None; + self.axis_to = None; } /// The effective reference point: the custom one if it belongs to the current selection, @@ -297,8 +332,10 @@ impl Tool for TransformTool { self.hover.clear(); let (pick, _) = snap_pick(cx, p); // Alt: decided on release. A click sets the point and opens the dialog; a drag - // transforms a copy about the reference point as it was. - let origin = self.reference_point(cx).unwrap_or(bounds.center()); + // transforms a copy about the reference point as it was. With a Reflect axis waiting + // for its second point, a drag draws the axis from its first point. + self.axis_to = None; + let origin = self.axis_first(cx).or_else(|| self.reference_point(cx)).unwrap_or(bounds.center()); let anchors = vectorcraft_effects::preview::anchor_bounds_with(cx.selection, cx.doc, cx.bounds_measure()).is_some(); let angle = selection_box(cx).map_or(0.0, |b| b.angle); self.drag = Some(Drag { @@ -352,15 +389,45 @@ impl Tool for TransformTool { } else { d.last }; + // A drag draws a Reflect axis to its end, so it uses up an axis waiting for + // its second point. + self.drop_axis(); vec![preview(m, ev.mods.alt, ev.backquote), Action::Commit] + } else if let (TransformKind::Reflect, Some(first)) = (self.kind, self.axis_first(cx)) { + // The second point of a Reflect axis: the selection (with Alt at the release, as + // for a drag, a copy) reflects across the line through both points, as one undo + // step. A click on the first point does not define a line, so the axis keeps + // waiting. + if d.pick.distance(first) < cx.tol(3.0) { + return vec![]; + } + self.drop_axis(); + let copy = ev.mods.alt; + let (m, _, _) = self.solve(d.angle_for(copy, ev.backquote), first, first, d.pick, false, d.bounds); + vec![Action::Begin(self.kind.label().into()), preview(m, copy, ev.backquote), Action::Commit] } else { - // A click sets the reference point; with Alt, it opens the dialog too. + // A click sets the reference point; with Alt, it opens the dialog too. With the + // Reflect tool, a plain click also sets the first point of an axis. self.origin = Some((d.pick, cx.selection.objects.clone())); - if d.alt { vec![self.dialog(d.pick)] } else { vec![] } + self.drop_axis(); + if d.alt { + vec![self.dialog(d.pick)] + } else { + if self.kind == TransformKind::Reflect { + self.axis = Some(Axis { + first: d.pick, + objects: cx.selection.objects.clone(), + anchors: cx.selection.anchors.clone(), + revision: cx.revision, + }); + } + vec![] + } } } PointerKind::DoubleClick => { self.end_drag(); + self.drop_axis(); match self.reference_point(cx) { Some(o) => vec![self.dialog(o)], None => vec![], @@ -369,7 +436,9 @@ impl Tool for TransformTool { PointerKind::TripleClick => vec![], PointerKind::Move => { if self.drag.is_none() { - self.hover = if cx.selection.is_empty() { vec![] } else { snap_pick(cx, p).1 }; + let (pick, hover) = if cx.selection.is_empty() { (p, vec![]) } else { snap_pick(cx, p) }; + self.hover = hover; + self.axis_to = self.axis_first(cx).map(|_| pick); } vec![] } @@ -382,7 +451,15 @@ impl Tool for TransformTool { self.end_drag(); vec![Action::Cancel] } - ToolKey::Enter => self.reference_point(cx).map(|o| vec![self.dialog(o)]).unwrap_or_default(), + // Escape drops a Reflect axis waiting for its second point; the reference point stays. + ToolKey::Escape if self.axis.is_some() => { + self.drop_axis(); + vec![] + } + ToolKey::Enter => { + self.drop_axis(); + self.reference_point(cx).map(|o| vec![self.dialog(o)]).unwrap_or_default() + } _ => vec![], } } @@ -403,6 +480,13 @@ impl Tool for TransformTool { { o.push(Overlay::Line { a: d.origin, b: *p, color: super::CYAN, dashed: true }); } + // A Reflect axis waiting for its second point: a dashed line from its first point to the + // pointer. + if self.drag.is_none() + && let (Some(a), Some(b)) = (self.axis_first(cx), self.axis_to) + { + o.push(Overlay::Line { a, b, color: super::CYAN, dashed: true }); + } if let (Some((p, t)), true) = (&self.measure, cx.transform_tools_guides) { o.push(Overlay::Measure { p: *p + Vec2::new(cx.tol(12.0), cx.tol(12.0)), text: t.clone() }); } @@ -429,10 +513,22 @@ impl Tool for TransformTool { fn set_option(&mut self, key: &str, value: &Value) { if key == "origin" { self.origin = value.as_array().and_then(|a| Some((Point::new(a.first()?.as_f64()?, a.get(1)?.as_f64()?), vec![]))); + self.drop_axis(); } } + fn ends_on_escape(&self, cx: &ToolContext) -> bool { + self.axis_first(cx).is_some() + } + + /// An edit, Undo or Redo made outside the tool, or another document, drops a Reflect axis + /// waiting for its second point. + fn history_moved(&mut self) { + self.drop_axis(); + } + fn deactivate(&mut self, _cx: &ToolContext) -> Vec { + self.drop_axis(); if self.end_drag().is_some_and(|d| d.began) { vec![Action::Cancel] } else { vec![] } } } @@ -665,6 +761,241 @@ mod tests { assert!((matrix(&a[1]) * Point::new(200.0, 200.0)).distance(Point::new(302.0, 262.0)) < 1e-9); } + /// Sends a click (a press and a release, with `mods`) at `(x, y)` and returns the release's actions. + fn click(t: &mut TransformTool, cx: &ToolContext, x: f64, y: f64, mods: Mods) -> Vec { + assert!(t.pointer(cx, &ev(PointerKind::Down, x, y).with_mods(mods)).is_empty()); + t.pointer(cx, &ev(PointerKind::Up, x, y).with_mods(mods)) + } + + /// Returns the matrix of a two-click reflection: a Begin, one `object.transform` preview with + /// `copy`, and a Commit. + fn reflected(a: &[Action], copy: bool) -> Affine { + assert!( + matches!(a, [Action::Begin(l), Action::Preview(c, v), Action::Commit] if l == "Reflect" && c == "object.transform" && v["copy"] == copy), + "{a:?}" + ); + matrix(&a[1]) + } + + /// The Reflect tool: a click sets the first point of an axis, and a second click reflects the + /// selection across the line through both points, as one interaction. The next click starts a + /// new axis. + #[test] + fn a_second_reflect_click_reflects_across_the_line_through_both_points() { + let (d, id) = doc_with_rect(); + let mut s = Selection::default(); + s.add(id); + let p = paint(); + let mut c = cx(&d, &s, &p); + (c.smart_guides, c.snap_to_point) = (false, false); + let none = Mods::default(); + let mut t = TransformTool::new(TransformKind::Reflect); + assert!(click(&mut t, &c, 100.0, 100.0, none).is_empty()); + assert_eq!(t.reference_point(&c), Some(Point::new(100.0, 100.0))); + assert!(t.ends_on_escape(&c)); + // Hovering draws the axis from the first point to the pointer. + t.pointer(&c, &ev(PointerKind::Move, 200.0, 260.0)); + let line = Overlay::Line { a: Point::new(100.0, 100.0), b: Point::new(200.0, 260.0), color: super::super::CYAN, dashed: true }; + assert!(t.overlays(&c).contains(&line), "{:?}", t.overlays(&c)); + let m = reflected(&click(&mut t, &c, 200.0, 200.0, none), false); + for fixed in [Point::new(100.0, 100.0), Point::new(200.0, 200.0), Point::new(300.0, 300.0)] { + assert!((m * fixed).distance(fixed) < 1e-9, "{m:?}"); + } + assert!((m * Point::new(200.0, 100.0)).distance(Point::new(100.0, 200.0)) < 1e-9, "{m:?}"); + // The axis is used up; the first point stays the reference point. + assert!(!t.ends_on_escape(&c)); + assert!(!t.overlays(&c).contains(&line)); + assert_eq!(t.reference_point(&c), Some(Point::new(100.0, 100.0))); + // The next click starts a new axis, and the one after it reflects across a vertical line. + assert!(click(&mut t, &c, 120.0, 50.0, none).is_empty()); + let m = reflected(&click(&mut t, &c, 120.0, 250.0, none), false); + assert!((m * Point::new(150.0, 130.0)).distance(Point::new(90.0, 130.0)) < 1e-9, "{m:?}"); + // Shift on a plain second click does not constrain the line. + assert!(click(&mut t, &c, 100.0, 100.0, none).is_empty()); + let shift = Mods { shift: true, ..Default::default() }; + let m = reflected(&click(&mut t, &c, 210.0, 190.0, shift), false); + assert!((m * Point::new(210.0, 190.0)).distance(Point::new(210.0, 190.0)) < 1e-9, "{m:?}"); + } + + /// Alt on the second click reflects a copy and opens no dialog; Alt on a first click still opens + /// the dialog and starts no axis. + #[test] + fn alt_on_the_second_reflect_click_reflects_a_copy() { + let (d, id) = doc_with_rect(); + let mut s = Selection::default(); + s.add(id); + let p = paint(); + let mut c = cx(&d, &s, &p); + (c.smart_guides, c.snap_to_point) = (false, false); + let mut t = TransformTool::new(TransformKind::Reflect); + assert!(click(&mut t, &c, 250.0, 100.0, Mods::default()).is_empty()); + let m = reflected(&click(&mut t, &c, 250.0, 200.0, alt()), true); + assert!((m * Point::new(150.0, 150.0)).distance(Point::new(350.0, 150.0)) < 1e-9, "{m:?}"); + // As for a drag, Alt at the release decides: held only at the press, the original reflects; + // pressed during the click, a copy does. + for (press, release) in [(alt(), Mods::default()), (Mods::default(), alt())] { + assert!(click(&mut t, &c, 250.0, 100.0, Mods::default()).is_empty()); + assert!(t.pointer(&c, &ev(PointerKind::Down, 250.0, 200.0).with_mods(press)).is_empty()); + reflected(&t.pointer(&c, &ev(PointerKind::Up, 250.0, 200.0).with_mods(release)), release.alt); + } + // Alt on a first click: the dialog, and the click after it is a first click again. + assert_eq!( + click(&mut t, &c, 120.0, 130.0, alt()), + vec![Action::Dialog("reflect".into(), json!({"axis": "vertical", "origin": [120.0, 130.0]}))] + ); + assert!(!t.ends_on_escape(&c)); + assert!(click(&mut t, &c, 130.0, 160.0, Mods::default()).is_empty()); + assert!(t.ends_on_escape(&c)); + } + + /// A second click on the first point does not define a line: nothing happens and the axis keeps + /// waiting. Escape, Enter, a double-click, a changed selection, an edit made outside the tool, + /// a new reference point and switching tools drop the axis, so the next click starts a new one. + #[test] + fn a_reflect_axis_waits_through_a_click_on_its_first_point_and_drops_on_escape_or_a_new_selection() { + let (mut d, id) = doc_with_rect(); + let l = d.layers[0].id; + let other = d.alloc_id(); + d.insert( + Some(l), + 1, + vectorcraft_doc::Node::path( + other, + vectorcraft_geom::shapes::rectangle(Rect::new(300.0, 300.0, 340.0, 340.0)), + vectorcraft_doc::Appearance::default_art(), + ), + ) + .unwrap(); + let mut s = Selection::default(); + s.add(id); + let p = paint(); + let mut c = cx(&d, &s, &p); + (c.smart_guides, c.snap_to_point) = (false, false); + let none = Mods::default(); + let mut t = TransformTool::new(TransformKind::Reflect); + click(&mut t, &c, 100.0, 100.0, none); + assert!(click(&mut t, &c, 100.0, 100.0, none).is_empty()); + assert!(click(&mut t, &c, 101.0, 102.0, none).is_empty()); + assert!(t.ends_on_escape(&c)); + reflected(&click(&mut t, &c, 100.0, 200.0, none), false); + + // Each way of dropping the axis, then a click that only starts a new one. + type DropAxis = fn(&mut TransformTool, &ToolContext); + let drops: [(&str, DropAxis); 6] = [ + ("escape", |t, c| assert!(t.key(c, ToolKey::Escape, Mods::default()).is_empty())), + ("enter", |t, c| assert!(matches!(t.key(c, ToolKey::Enter, Mods::default()).as_slice(), [Action::Dialog(..)]))), + ("double-click", |t, c| assert!(matches!(t.pointer(c, &ev(PointerKind::DoubleClick, 100.0, 100.0)).as_slice(), [Action::Dialog(..)]))), + ("history", |t, _| t.history_moved()), + ("origin", |t, _| t.set_option("origin", &json!([10.0, 10.0]))), + ("deactivate", |t, c| assert!(t.deactivate(c).is_empty())), + ]; + for (name, drop) in drops { + click(&mut t, &c, 100.0, 100.0, none); + assert!(t.ends_on_escape(&c), "{name}"); + drop(&mut t, &c); + assert!(!t.ends_on_escape(&c), "{name}"); + assert!(click(&mut t, &c, 100.0, 200.0, none).is_empty(), "{name}"); + assert!(t.ends_on_escape(&c), "{name}"); + t.key(&c, ToolKey::Escape, Mods::default()); + } + + // A double-click elsewhere arrives as two clicks and then the double-click: its first click + // sets the second point and reflects, its second click starts a new axis, and the + // double-click drops that axis and opens the dialog there. + click(&mut t, &c, 100.0, 100.0, none); + reflected(&click(&mut t, &c, 100.0, 200.0, none), false); + assert!(click(&mut t, &c, 100.0, 200.0, none).is_empty()); + let a = t.pointer(&c, &ev(PointerKind::DoubleClick, 100.0, 200.0)); + assert_eq!(a, vec![Action::Dialog("reflect".into(), json!({"axis": "vertical", "origin": [100.0, 200.0]}))]); + assert!(!t.ends_on_escape(&c)); + + // The selection changed and changed back (or the document edited) moves the revision: the + // axis set before it does not come back. + click(&mut t, &c, 100.0, 100.0, none); + let mut moved = cx(&d, &s, &p); + (moved.smart_guides, moved.snap_to_point) = (false, false); + moved.revision = (c.revision.0, c.revision.1 + 1); + assert!(!t.ends_on_escape(&moved)); + assert!(click(&mut t, &moved, 100.0, 200.0, none).is_empty()); + reflected(&click(&mut t, &moved, 200.0, 200.0, none), false); + + // Another object selected, then nothing selected: the axis set for the first selection + // does not reflect them. + click(&mut t, &c, 100.0, 100.0, none); + let mut s2 = Selection::default(); + s2.add(other); + let mut c2 = cx(&d, &s2, &p); + (c2.smart_guides, c2.snap_to_point) = (false, false); + assert!(!t.ends_on_escape(&c2)); + assert!(click(&mut t, &c2, 100.0, 200.0, none).is_empty()); + let empty = Selection::default(); + let c3 = cx(&d, &empty, &p); + assert!(t.pointer(&c3, &ev(PointerKind::Down, 100.0, 300.0)).is_empty()); + assert!(t.pointer(&c3, &ev(PointerKind::Up, 100.0, 300.0)).is_empty()); + // Anchors selected with Direct Selection make a different selection too. + let mut s4 = s.clone(); + s4.anchors.insert(id, [(0, 0), (0, 1)].into()); + let mut c4 = cx(&d, &s4, &p); + (c4.smart_guides, c4.snap_to_point) = (false, false); + click(&mut t, &c, 100.0, 100.0, none); + assert!(!t.ends_on_escape(&c4)); + assert!(click(&mut t, &c4, 100.0, 200.0, none).is_empty()); + // With those anchors selected, the second click reflects them, across the line y = 200. + let m = reflected(&click(&mut t, &c4, 200.0, 200.0, none), false); + assert!((m * Point::new(150.0, 150.0)).distance(Point::new(150.0, 250.0)) < 1e-9, "{m:?}"); + + // The other transform tools only move the reference point on a second click. + for kind in [TransformKind::Rotate, TransformKind::Scale, TransformKind::Shear] { + let mut t = TransformTool::new(kind); + assert!(click(&mut t, &c, 100.0, 100.0, none).is_empty(), "{kind:?}"); + assert!(click(&mut t, &c, 100.0, 200.0, none).is_empty(), "{kind:?}"); + assert!(!t.ends_on_escape(&c), "{kind:?}"); + assert_eq!(t.reference_point(&c), Some(Point::new(100.0, 200.0)), "{kind:?}"); + } + } + + /// After a click sets the first point, a drag draws the axis from it (Shift in 45° steps from a + /// turned box), and its release uses the axis up. With the selection turned, two clicks still + /// reflect across the line through the clicked points on the page. + #[test] + fn a_drag_after_a_reflect_click_draws_the_axis_from_the_first_point() { + let (mut d, id) = doc_with_rect(); + let c0 = Point::new(150.0, 150.0); + d.node_mut(id).unwrap().transform(about(c0, Affine::rotate(-30f64.to_radians())), false); + let mut s = Selection::default(); + s.add(id); + let p = paint(); + let mut c = cx(&d, &s, &p); + (c.smart_guides, c.snap_to_point) = (false, false); + let none = Mods::default(); + let mut t = TransformTool::new(TransformKind::Reflect); + click(&mut t, &c, 100.0, 100.0, none); + t.pointer(&c, &ev(PointerKind::Down, 300.0, 300.0)); + let a = t.pointer(&c, &ev(PointerKind::Drag, 100.0, 250.0)); + assert_eq!(a[0], Action::Begin("Reflect".into())); + let m = matrix(&a[1]); + assert!((m * Point::new(100.0, 180.0)).distance(Point::new(100.0, 180.0)) < 1e-9, "{m:?}"); + assert!((m * Point::new(150.0, 150.0)).distance(Point::new(50.0, 150.0)) < 1e-9, "{m:?}"); + // Shift: a pointer a few degrees off the box's vertical axis steps onto it. + let frame = OrientedBox { angle: 30.0, rect: Rect::ZERO }; + let along = |x: f64, y: f64| Point::new(100.0, 100.0) + (frame.to_doc() * Point::new(x, y)).to_vec2(); + let to = along(3.0, 50.0); + let a = t.pointer(&c, &ev(PointerKind::Drag, to.x, to.y).with_mods(Mods { shift: true, ..Default::default() })); + assert!((matrix(&a[0]) * along(0.0, 50.0)).distance(along(0.0, 50.0)) < 1e-9, "{a:?}"); + let up = t.pointer(&c, &ev(PointerKind::Up, to.x, to.y)); + assert_eq!(up.last(), Some(&Action::Commit)); + assert!(!t.ends_on_escape(&c)); + assert!(click(&mut t, &c, 100.0, 300.0, none).is_empty()); + // Two clicks with the box turned: the line through the clicked points on the page. + let m = reflected(&click(&mut t, &c, 300.0, 300.0, none), false); + assert!((m * Point::new(200.0, 250.0)).distance(Point::new(200.0, 350.0)) < 1e-9, "{m:?}"); + // A drag with no axis waiting still draws it from the reference point. + let mut t = TransformTool::new(TransformKind::Reflect); + t.pointer(&c, &ev(PointerKind::Down, 150.0, 50.0)); + let a = t.pointer(&c, &ev(PointerKind::Drag, 150.0, 20.0)); + assert!((matrix(&a[1]) * Point::new(100.0, 120.0)).distance(Point::new(200.0, 120.0)) < 1e-9); + } + #[test] fn reflect_vertical_axis_mirrors_x() { let t = TransformTool::new(TransformKind::Reflect); diff --git a/docs/mcp.md b/docs/mcp.md index 4c1b661f42..4927ec9a0c 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -6341,6 +6341,10 @@ records the `basis` used, so a recorded action replays in the same frame; a save journal entry recorded before it) plays along the page's axes, as it did when it was recorded. `object.transformAgain` repeats the transform's page matrix, also after Reset Bounding Box. The Scale and Reflect dialogs, the Transform and Properties panels' flips, the Scale tool and the Reflect tool's default axis and Shift steps follow the box the same way; a Reflect axis drawn with the tool is the line drawn on the page. +With the Reflect tool, a click (a `pointer_gesture` `down` and `up`) sets the first point of an axis, and a second +click reflects the selection across the line through both points as one `object.transform` and one undo step. With +Alt held when the second click is released, the transform has `copy: true` and reflects a copy. A second click within 3 px of the +first point does nothing. ```json {"name":"run_command","arguments":{"command":"object.scale","params":{"sx":200,"sy":100}}} diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index ef83de54ad..b30e5b8829 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1053,6 +1053,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Object › Transform › Reset Bounding Box squares the box of every object inside the selected ones as well: the children of groups, compound paths, clip groups, blends, envelopes, repeats and intertwines, and the art of linked opacity masks. Ungroup and the release commands then bring back boxes square to the page (VectorCraft's own behavior; `bboxrotate::reset_bounding_box_squares_the_objects_inside_a_group`, `reset_bounding_box_squares_the_turned_members_of_a_square_group`, `reset_bounding_box_then_release_clipping_mask` and the other `reset_bounding_box_then_*` tests, `reset_bounding_box_leaves_the_art_of_an_unlinked_opacity_mask`). - After a rotation the Free Transform tool shows and drags the same turned bounding box as the Selection tool: its handles, their cursors and its rotate zone sit on the selection's own sides, a handle scales along those sides from the opposite handle ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/scale-objects.html)), Cmd/Ctrl on a side handle shears along that side, and Perspective Distort and Free Distort start from the turned box's corners (`object.distort` takes `angle` with `from`) (`bboxrotate::free_transform_handles_turn_with_the_object_and_scale_along_its_axes`, `free_transform_shears_along_the_turned_side`, `free_transform_distort_starts_from_the_turned_box`, `xform::distort_reads_from_in_a_turned_frame_and_rejects_a_bad_angle`, tools `xform::free::tests::the_box_and_its_handles_turn_with_the_selection`). - After a rotation the Scale and Reflect tools, the Scale and Reflect dialogs, `object.scale`, `object.reflect` with a named axis and the Transform and Properties panels' flips act along the selection's turned bounding box until Reset Bounding Box: the horizontal and vertical scale stretch along its own width and height, and the vertical and horizontal reflection axes are its own. The Reflect tool's default axis and its Shift steps start from the box's axes, and an axis drawn with the tool is the line drawn on the page. `basis: "page"` keeps the page's axes (VectorCraft's own rules; `bboxrotate::scale_and_reflect_follow_the_turned_box`, tools `xform::transform::tests::scale_and_reflect_drags_follow_a_turned_bounding_box`). + - The Reflect tool sets an axis with two clicks: a click sets the first point (and the reference point), and a second click reflects the selection across the line through both points as one undo step; Alt/Option on the second click reflects a copy, and a drag after the first click draws the axis from it ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-objects/arrange-objects/reflect-or-flip-objects.html)). A dashed line runs from the first point to the pointer until the second click. VectorCraft's own rules: a second click within 3 px of the first point does nothing and the axis keeps waiting; Shift does not constrain a plain second click; Escape, Enter, a double-click, a changed selection, an edit made outside the tool or another tool drops the waiting axis (tools `xform::transform::tests::a_second_reflect_click_reflects_across_the_line_through_both_points` and the three tests after it; engine `xform::two_reflect_clicks_reflect_across_their_line_as_one_undo_step`). - Perspective Distort and Free Distort (`object.distort`) turn each warped object's bounding box as the warp turns the object at its own center, the objects inside groups, compound paths and clip groups and the art of linked opacity masks included, so the next Selection or Free Transform drag uses the tilted box; Object › Transform › Reset Bounding Box squares it again, and corners left where they are add no undo step (VectorCraft's own rule; `bboxrotate::distort_turns_an_upright_box_with_the_warp_at_its_center`, `distort_turns_each_member_and_linked_mask_by_its_own_warp`, `mirrored_and_collapsing_distorts_keep_valid_angles`, `distort_angles_undo_redo_and_reopen_together`, `xform::unchanged_distort_records_no_history`). - The Free Transform widget's Constrain works in Free Distort as well as in Free Transform ([the help page](https://helpx.adobe.com/illustrator/using/tool-techniques/free-transform-tool.html)). With Constrain on, or Shift held, a corner dragged in Free Distort moves only along the line through the opposite corner, in the box's own proportions, and the other three corners stay in place; on a turned box the line runs through the box's own corners. The line is VectorCraft's own rule. Cmd/Ctrl+Alt+Shift on a corner still drags in Perspective Distort, where Constrain stays unavailable (tools `xform::free::tests::free_distort_corner_keeps_to_its_diagonal_with_shift_or_constrain`, `shift_pressed_during_a_free_distort_drag_constrains_it`, `a_turned_box_is_constrained_along_its_own_diagonal`, `along_diagonal_of_a_degenerate_box`; engine `xform::free_transform_constrained_distort_keeps_the_corner_on_its_diagonal`; ui-egui `free_transform::tests::the_widget_sets_the_mode_and_a_corner_drag_then_distorts`). - Native macOS menu bar, vector tool cursors, a command palette (Help › Search Commands…), middle-button panning with any tool. Native menus explicitly end tracking on command selection, outside window presses and Escape; menu updates wait until tracking ends, and a dismissing press never starts a canvas gesture (M14.8). diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 4182189c4a..fcc6b16da1 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -285,6 +285,7 @@ tools, never checked side by side) isn't captured row by row. | Free Transform, Scale and Reflect along a rotated box | done | The Scale and Reflect tools, dialogs and commands and the Transform and Properties panels' flips act along the turned box until Reset Bounding Box; `basis: "page"` keeps the page's axes | | Free Transform widget: constrain, free distort, perspective distort; the key-held variants | done | | | Transform tools: click sets the reference point (snaps to anchors/centres), Alt-click opens the dialog, Alt-release copies | done | with anchors selected with Direct Selection, the tools, the dialogs and Move transform those anchors alone, about the centre of their box by default (#1408; the default point and whole-object copies are our choices) | +| Reflect tool: a second click reflects across the line through both clicked points; Alt on it reflects a copy | done | [the help page](https://helpx.adobe.com/illustrator/desktop/manage-objects/arrange-objects/reflect-or-flip-objects.html); one undo step; a second click within 3 px of the first, Escape or a changed selection leaves nothing reflected (our choices) | | Move, Rotate, Scale, Reflect and Shear dialogs: live Preview; Up/Down step angles and percentages by 1, Shift by 10 | done | #1412; Preview starts off (our choice: the public documentation gives no default), Move's as it was last confirmed; OK is one undo step and Transform Again repeats it | | Transform Again, Transform Each, Scale Strokes & Effects, Scale Corners | done | | | The Transform effect dialog previews valid typed scale, move, rotation, and Copies values while fields remain focused. Preview off defers the artwork change until OK; Cancel restores the original artwork. | done | `crates/ui-egui/src/panels/tests_appearance.rs` covers numeric input, sliders, artwork targets, preview, and undo. |