mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-08 20:01:37 +00:00
Shape tools: review follow-ups from CodeRabbit
- The 45° move assertion compares dx and dy with a small tolerance instead of exact equality (the matrix's floats are rounded), keeping the non-zero check and the message. - The engine test helpers say what they do, so the docstring coverage of the functions this pull request touches is complete.
This commit is contained in:
committed by
bflatastic
parent
10724077bc
commit
1c271c776c
@@ -9,22 +9,26 @@ use vectorcraft_tools::{Mods, PointerEvent, PointerKind, ToolKey};
|
||||
|
||||
use crate::*;
|
||||
|
||||
/// A new 400 × 400 pt document.
|
||||
fn new_doc() -> Session {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 400, "height": 400})).unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
/// The view the gestures run in: page coordinates, with Smart Guides off so nothing snaps.
|
||||
fn view() -> ViewInfo {
|
||||
ViewInfo { smart_guides: false, ..ViewInfo::default() }
|
||||
}
|
||||
|
||||
/// Feed the pointer events `(kind, x, y)`, all with `mods` held, to the active tool.
|
||||
fn gesture(s: &mut Session, mods: Mods, events: &[(PointerKind, f64, f64)]) {
|
||||
for (k, x, y) in events {
|
||||
s.pointer(&PointerEvent::new(*k, *x, *y).with_mods(mods), view()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// No modifier held.
|
||||
const NONE: Mods = Mods { shift: false, alt: false, cmd: false, ctrl: false, space: false };
|
||||
|
||||
/// A 100 × 80 pt rectangle drawn from (100, 100) to (200, 180) with the Rectangle tool, still
|
||||
@@ -35,14 +39,17 @@ fn drawn_rect(s: &mut Session) -> NodeId {
|
||||
*s.doc().unwrap().selection.objects.first().expect("the drawn rectangle is selected")
|
||||
}
|
||||
|
||||
/// The geometric bounds of `id`.
|
||||
fn bounds(s: &Session, id: NodeId) -> Rect {
|
||||
s.doc().unwrap().doc.bounds_of(&[id], false).expect("bounds")
|
||||
}
|
||||
|
||||
/// The angle of `id`'s bounding box, in degrees counter-clockwise: 0 for art square to the page.
|
||||
fn angle(s: &Session, id: NodeId) -> f64 {
|
||||
s.doc().unwrap().doc.oriented_bounds(&[id], false).map_or(0.0, |b| b.angle)
|
||||
}
|
||||
|
||||
/// How many undo steps the active document's history holds.
|
||||
fn undo_steps(s: &Session) -> usize {
|
||||
s.doc().unwrap().history.undo.len()
|
||||
}
|
||||
|
||||
@@ -2191,7 +2191,8 @@ fn a_shift_press_on_the_centre_point_moves_or_deselects() {
|
||||
let Some(Action::Preview(cmd, v)) = a.last().filter(|a| matches!(a, Action::Preview(c, _) if c == "object.transform")) else { panic!("{a:?}") };
|
||||
assert_eq!(cmd, "object.transform");
|
||||
let [_, _, _, _, dx, dy] = [0, 1, 2, 3, 4, 5].map(|i| v["matrix"][i].as_f64().unwrap_or_default());
|
||||
assert!(dx != 0.0 && dx == dy, "held to 45°: {dx} {dy}");
|
||||
// A 45° move, within the rounding of the matrix's own floats.
|
||||
assert!(dx != 0.0 && (dx - dy).abs() < 1e-9, "held to 45°: {dx} {dy}");
|
||||
assert_eq!(t.pointer(&c, &ev(PointerKind::Up, 170.0, 160.0).with_mods(shift)), vec![Action::Commit]);
|
||||
// A Shift-click there takes the object out of the selection on release.
|
||||
let mut t = SelectionTool::default();
|
||||
|
||||
Reference in New Issue
Block a user