Merge pull request #8476 from dotCooCoo/feat/reflect-tool-two-click-axis

Reflect tool: a second click reflects across the line through both points
This commit is contained in:
BFlat
2026-11-19 14:59:20 +07:00
committed by GitHub
5 changed files with 524 additions and 8 deletions
+35
View File
@@ -480,6 +480,41 @@ 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)));
// The copy is selected and reflected across y = 300.
let copy = s.doc().unwrap().selection.objects.clone();
assert!(copy.len() == 1 && copy[0] != a, "{copy:?}");
assert!(close(bounds(&s, copy[0]), Rect::new(100.0, 450.0, 200.0, 500.0)), "{:?}", bounds(&s, copy[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, naming it (both also take an
/// angle, Shear's from -359° to 359°): 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.
+482 -8
View File
@@ -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;
@@ -82,6 +87,9 @@ struct Drag {
pointer: Point,
shift: bool,
last: Affine,
/// The document revision at the press: a press whose document or selection changes before it
/// becomes a drag is dropped, so its reference point is never applied to other objects.
revision: (u64, u64),
}
impl Drag {
@@ -92,10 +100,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<NodeId>,
anchors: BTreeMap<NodeId, BTreeSet<AnchorRef>>,
revision: (u64, u64),
}
pub struct TransformTool {
kind: TransformKind,
/// Custom reference point and the selection it was set for.
origin: Option<(Point, Vec<NodeId>)>,
/// Reflect: the axis whose second point the next click sets.
axis: Option<Axis>,
/// The snapped pointer while hovering with an axis waiting, where its dashed line ends.
axis_to: Option<Point>,
drag: Option<Drag>,
measure: Option<(Point, String)>,
/// What the Info panel shows for the drag in progress.
@@ -128,7 +150,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<Point> {
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 +335,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 {
@@ -313,6 +353,7 @@ impl Tool for TransformTool {
pointer: p,
shift: false,
last: Affine::IDENTITY,
revision: cx.revision,
});
vec![]
}
@@ -323,6 +364,12 @@ impl Tool for TransformTool {
if p.distance(d.start) < cx.tol(3.0) {
return out;
}
// The document or the selection changed since the press: its reference point
// (or Reflect axis) belongs to the selection as it was, so the press is dropped.
if d.revision != cx.revision {
self.end_drag();
return out;
}
d.began = true;
// The selection moves, so only the other objects are targets. The Scale tool's
// drag scales; the others move the art about the reference point.
@@ -352,15 +399,49 @@ 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 d.revision != cx.revision {
// The document or the selection changed since the press, as for a drag: the
// release sets no reference point or Reflect axis.
vec![]
} 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 +450,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![]
}
@@ -378,15 +461,40 @@ impl Tool for TransformTool {
fn key(&mut self, cx: &ToolContext, key: ToolKey, _mods: Mods) -> Vec<Action> {
match key {
// Escape cancels a drag, and drops the Reflect axis the drag was drawing from too.
ToolKey::Escape if self.busy() => {
self.end_drag();
self.drop_axis();
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, and a press not yet
// released with it, so the release sets no point; the reference point stays.
ToolKey::Escape if self.axis.is_some() => {
self.end_drag();
self.drop_axis();
vec![]
}
// Enter opens the dialog. A press not yet a drag ends with it, so its release sets no
// reference point or Reflect axis behind the dialog.
ToolKey::Enter => {
if !self.busy() {
self.end_drag();
}
self.drop_axis();
self.reference_point(cx).map(|o| vec![self.dialog(o)]).unwrap_or_default()
}
_ => vec![],
}
}
/// A dropped press ends whether or not it became a drag, so the release the engine sends after
/// it sets no reference point or Reflect axis; a Reflect axis waiting for its second point is
/// dropped too, as with Escape.
fn drop_press(&mut self, _cx: &ToolContext) -> Vec<Action> {
self.drop_axis();
if self.end_drag().is_some_and(|d| d.began) { vec![Action::Cancel] } else { vec![] }
}
fn overlays(&self, cx: &ToolContext) -> Vec<Overlay> {
let mut o = vec![];
let reference = match self.drag {
@@ -403,6 +511,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,9 +544,20 @@ 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();
}
/// `origin` is `[x, y]`, or null to clear it.
fn check_option(&self, key: &str, value: &Value) -> Result<(), String> {
if key != "origin" {
@@ -442,6 +568,7 @@ impl Tool for TransformTool {
}
fn deactivate(&mut self, _cx: &ToolContext) -> Vec<Action> {
self.drop_axis();
if self.end_drag().is_some_and(|d| d.began) { vec![Action::Cancel] } else { vec![] }
}
}
@@ -674,6 +801,353 @@ 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<Action> {
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:?}");
}
}
/// Escape pressed between the press and the release of the second click drops the axis and the
/// press with it: the release starts no new axis and moves no reference point, so the click
/// after it starts an axis and reflects nothing. Escape during a drag from the first point
/// cancels the drag and drops the axis too.
#[test]
fn escape_during_the_second_reflect_click_cancels_that_click() {
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!(t.pointer(&c, &ev(PointerKind::Down, 200.0, 200.0)).is_empty());
assert!(t.key(&c, ToolKey::Escape, none).is_empty());
assert!(t.pointer(&c, &ev(PointerKind::Up, 200.0, 200.0)).is_empty());
assert!(!t.ends_on_escape(&c));
assert_eq!(t.reference_point(&c), Some(Point::new(100.0, 100.0)));
assert!(click(&mut t, &c, 150.0, 300.0, none).is_empty());
assert!(t.ends_on_escape(&c));
// A drag from the first point, then Escape.
assert!(t.pointer(&c, &ev(PointerKind::Down, 300.0, 300.0)).is_empty());
assert_eq!(t.pointer(&c, &ev(PointerKind::Drag, 100.0, 250.0))[0], Action::Begin("Reflect".into()));
assert_eq!(t.key(&c, ToolKey::Escape, none), vec![Action::Cancel]);
assert!(!t.ends_on_escape(&c));
assert!(t.pointer(&c, &ev(PointerKind::Up, 100.0, 250.0)).is_empty());
assert!(click(&mut t, &c, 200.0, 200.0, none).is_empty());
}
/// Enter between the press and the release of the second click opens the dialog at the first
/// point and ends the press: the release sets no point and starts no axis. A press the engine
/// drops ends the same way, with or without an axis waiting, and a dropped drag is canceled. A
/// press whose document or selection changes before it becomes a drag is dropped.
#[test]
fn enter_or_a_dropped_press_during_a_reflect_click_ends_that_press() {
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 first = Point::new(100.0, 100.0);
let mut t = TransformTool::new(TransformKind::Reflect);
assert!(click(&mut t, &c, 100.0, 100.0, none).is_empty());
assert!(t.pointer(&c, &ev(PointerKind::Down, 200.0, 200.0)).is_empty());
assert_eq!(t.key(&c, ToolKey::Enter, none), vec![Action::Dialog("reflect".into(), json!({"axis": "vertical", "origin": [100.0, 100.0]}))]);
assert!(t.pointer(&c, &ev(PointerKind::Up, 200.0, 200.0)).is_empty());
assert!(!t.ends_on_escape(&c));
assert_eq!(t.reference_point(&c), Some(first));
// A dropped first press: its release sets no point and starts no axis.
assert!(t.pointer(&c, &ev(PointerKind::Down, 200.0, 200.0)).is_empty());
assert!(t.drop_press(&c).is_empty());
assert!(t.pointer(&c, &ev(PointerKind::Up, 200.0, 200.0)).is_empty());
assert!(!t.ends_on_escape(&c));
assert_eq!(t.reference_point(&c), Some(first));
// A dropped second press drops the axis too, so the next click is a first click.
assert!(click(&mut t, &c, 100.0, 100.0, none).is_empty());
assert!(t.pointer(&c, &ev(PointerKind::Down, 200.0, 200.0)).is_empty());
assert!(t.drop_press(&c).is_empty());
assert!(t.pointer(&c, &ev(PointerKind::Up, 200.0, 200.0)).is_empty());
assert!(!t.ends_on_escape(&c));
assert!(click(&mut t, &c, 150.0, 300.0, none).is_empty());
// A dropped drag is canceled, and its release commits nothing.
assert!(t.pointer(&c, &ev(PointerKind::Down, 300.0, 300.0)).is_empty());
assert_eq!(t.pointer(&c, &ev(PointerKind::Drag, 100.0, 250.0))[0], Action::Begin("Reflect".into()));
assert_eq!(t.drop_press(&c), vec![Action::Cancel]);
assert!(t.pointer(&c, &ev(PointerKind::Up, 100.0, 250.0)).is_empty());
assert!(!t.ends_on_escape(&c));
// The selection changes between the press and the first drag event: the press is dropped,
// and neither the drag nor its release transforms anything.
assert!(click(&mut t, &c, 100.0, 100.0, none).is_empty());
assert!(t.pointer(&c, &ev(PointerKind::Down, 200.0, 200.0)).is_empty());
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.pointer(&moved, &ev(PointerKind::Drag, 100.0, 250.0)).is_empty());
assert!(!t.busy());
assert!(t.pointer(&moved, &ev(PointerKind::Up, 100.0, 250.0)).is_empty());
}
/// A press whose document or selection changes before a release that is not a drag sets no
/// reference point and starts no Reflect axis, so the next click is a first click.
#[test]
fn a_reflect_press_released_after_the_document_changed_sets_nothing() {
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 moved = cx(&d, &s, &p);
(moved.smart_guides, moved.snap_to_point) = (false, false);
moved.revision = (c.revision.0, c.revision.1 + 1);
let mut t = TransformTool::new(TransformKind::Reflect);
assert!(t.pointer(&c, &ev(PointerKind::Down, 200.0, 200.0)).is_empty());
assert!(t.pointer(&moved, &ev(PointerKind::Up, 200.0, 200.0)).is_empty());
assert!(!t.ends_on_escape(&moved));
assert_ne!(t.reference_point(&moved), Some(Point::new(200.0, 200.0)));
assert!(click(&mut t, &moved, 150.0, 300.0, none).is_empty());
// The other transform tools set no reference point either.
let mut t = TransformTool::new(TransformKind::Rotate);
assert!(t.pointer(&c, &ev(PointerKind::Down, 200.0, 200.0)).is_empty());
assert!(t.pointer(&moved, &ev(PointerKind::Up, 200.0, 200.0)).is_empty());
assert_ne!(t.reference_point(&moved), Some(Point::new(200.0, 200.0)));
}
/// 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);
+5
View File
@@ -7044,6 +7044,11 @@ 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 plain click (a `pointer_gesture` `down` and `up` without Alt) 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. An
Alt-click opens the Reflect dialog and sets no axis, so the plain click after it sets a first point. With
Alt held when the second click is released, the transform has `copy: true` and reflects a copy. A second click whose snapped
point is within 3 screen pixels of the first point's snapped point does nothing.
```json
{"name":"run_command","arguments":{"command":"object.scale","params":{"sx":200,"sy":100}}}
+1
View File
@@ -1133,6 +1133,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- Object › Transform › Rotate Bounding Box… turns the selection's bounding box by the angle typed in its dialog without moving the art (`object.rotateBoundingBox`, `absolute: true` to set the angle). Objects with different angles get one shared angle, and the objects inside a group and the art of a linked opacity mask turn with it. A path of a compound path selected on its own turns only its own box, and Reset Bounding Box squares only that path's box too (VectorCraft's own behavior; `bboxrotate::rotate_bounding_box_turns_the_box_and_leaves_the_art`, `rotate_bounding_box_back_to_zero_stores_zero`, `rotate_bounding_box_gives_a_mixed_selection_one_angle`, `rotate_bounding_box_turns_the_objects_inside_a_group_with_it`, `rotate_bounding_box_turns_a_linked_masks_art_only`, `reset_bounding_box_squares_every_box_rotate_bounding_box_turned`, `rotate_bounding_box_refuses_bad_params`, `tests::rotate_bounding_box_of_a_compound_paths_member_turns_only_that_path`, ui-egui `panels::transform::tests::rotate_bounding_box_menu_item_turns_the_box_by_the_dialog_angle`).
- 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: an Alt-click opens the dialog and sets no axis; a second click whose snapped point is within 3 screen pixels of the first point's snapped point does nothing and the axis keeps waiting; Shift does not constrain a plain second click; Escape, Enter, a changed selection, an edit made outside the tool or another tool drops the waiting axis. A double-click arrives as two clicks: its first click is the second point, so a double-click away from the first point reflects the selection, and the double-click then opens the dialog with no axis waiting (tools `xform::transform::tests::a_second_reflect_click_reflects_across_the_line_through_both_points` and the four 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`).
- With Smart Guides › Transform Tools on, a Free Transform shear (Cmd/Ctrl on a side handle) shows its angle next to the pointer, as the Shear tool does, and a handle drag that turns from a scale into a shear and back shows only the current operation's value ([the help page](https://helpx.adobe.com/illustrator/desktop/measure-and-align/grids-and-guides/smart-guides-options.html)). The angle's sign and its one decimal place are VectorCraft's own rule, the same as the Shear tool's label (tools `xform::free::tests::shear_drag_shows_its_angle_with_transform_tools_guides`, `a_handle_drag_that_changes_operation_relabels_it`).
+1
View File
@@ -309,6 +309,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 whose snapped point is within 3 screen pixels of the first one's, 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. |