mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 22:27:08 +00:00
Shapes: a Circle tool release near the press keeps the press's point from a center too
A second press from a center let go within 2 screen points of the press showed the circle through the pointer but drew it through the press, and the tests for a drag brought back near its press asked for the opposite of the click rule on main. The preview of such a press now shows the pressed point until it has been dragged, and the tests follow the rule that a first press let go near its press places the first point.
This commit is contained in:
@@ -165,8 +165,9 @@ impl CircleTool {
|
||||
Some(Press::First { .. }) | None => out.extend(self.pointer.filter(|_| self.first.is_some())),
|
||||
// A press on the first point adds no point: a drag from it drags out a diameter.
|
||||
Some(Press::Second { on_first: true, dragged, .. }) => out.extend(self.pointer.filter(|_| dragged)),
|
||||
// From a center, the second point follows the pointer.
|
||||
Some(Press::Second { .. }) if self.centered => out.extend(self.pointer),
|
||||
// From a center, the second point follows the pointer once the press has been dragged;
|
||||
// until then it is the pressed point, which a release within DRAG_PX draws through.
|
||||
Some(Press::Second { dragged: true, .. }) if self.centered => out.extend(self.pointer),
|
||||
Some(Press::Second { at, dragged: false, .. }) => out.push(at),
|
||||
Some(Press::Second { snapped, dragged: true, .. }) => {
|
||||
out.push(snapped);
|
||||
@@ -296,9 +297,8 @@ impl Tool for CircleTool {
|
||||
vec![]
|
||||
}
|
||||
PointerKind::Up => match (self.press.take(), self.first, self.pointer) {
|
||||
// Once the press has moved DRAG_PX, the release draws the circle the tool shows, also
|
||||
// where the pointer came back nearer the press; where it shows none, the release
|
||||
// draws nothing and starts afresh.
|
||||
// A release DRAG_PX or more from the press draws the circle the tool shows; where it
|
||||
// shows none, the release draws nothing and starts afresh.
|
||||
(Some(Press::First { at, dragged: true, .. }), _, Some(b))
|
||||
if b.distance(at) >= cx.tol(DRAG_PX) || circle_for(&[at, b], self.centered).is_some() =>
|
||||
{
|
||||
@@ -315,7 +315,7 @@ impl Tool for CircleTool {
|
||||
(Some(Press::Second { on_first: true, dragged: false, .. }), ..) => vec![],
|
||||
(Some(Press::Second { on_first: true, dragged: true, .. }), Some(a), Some(c)) => self.draw(&[a, c]),
|
||||
// From a center: the outline passes through the point the tool shows it on, where
|
||||
// the drag ends or, within DRAG_PX of the press, where the pointer last was.
|
||||
// the drag ends or, within DRAG_PX of the press, the pressed point.
|
||||
(Some(Press::Second { .. }), Some(a), Some(c)) if self.centered => self.draw(&[a, c]),
|
||||
(Some(Press::Second { at, dragged: false, .. }), Some(a), _) => self.draw(&[a, at]),
|
||||
// Three points: Alt's rounding of the diameter does not apply.
|
||||
|
||||
@@ -473,8 +473,8 @@ fn from_center_two_clicks_draw_the_circle_through_the_second() {
|
||||
}
|
||||
|
||||
/// With From Center, the release draws the circle the tool shows: a drag from the center ends
|
||||
/// where it is let go, and a second press moved less than 2 screen points draws the outline
|
||||
/// through the pointer, not through the point of the press.
|
||||
/// where it is let go, and a second press moved less than 2 screen points shows and draws the
|
||||
/// outline through the point of the press.
|
||||
#[test]
|
||||
fn from_center_the_release_draws_the_circle_shown() {
|
||||
let (d, _) = doc_with_rect();
|
||||
@@ -488,26 +488,24 @@ fn from_center_the_release_draws_the_circle_shown() {
|
||||
t.pointer(&cx, &ev(PointerKind::Down, (330.0, 340.0), Mods::default()));
|
||||
t.pointer(&cx, &ev(PointerKind::Drag, (331.0, 340.0), Mods::default()));
|
||||
let shown = preview(&t.overlays(&cx)).expect("the circle is shown");
|
||||
let r = Point::new(300.0, 300.0).distance(Point::new(331.0, 340.0));
|
||||
let r = Point::new(300.0, 300.0).distance(Point::new(330.0, 340.0));
|
||||
assert!(near(shown, Rect::new(300.0 - r, 300.0 - r, 300.0 + r, 300.0 + r)), "{:?}", t.overlays(&cx));
|
||||
assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, (331.0, 340.0), Mods::default())), centered((300.0, 300.0), (331.0, 340.0)));
|
||||
assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, (331.0, 340.0), Mods::default())), centered((300.0, 300.0), (330.0, 340.0)));
|
||||
}
|
||||
|
||||
/// Once a press has moved 2 screen points, its release draws the circle the tool shows, also when
|
||||
/// the pointer comes back nearer than that: from a center and on a diameter. A drag back onto the
|
||||
/// press itself shows no circle and places the first point, as a click does.
|
||||
/// A first press let go within 2 screen points of where it was pressed is a click also after a
|
||||
/// drag that came back to it, from a center and on a diameter: it places the first point.
|
||||
#[test]
|
||||
fn a_drag_brought_back_near_its_press_draws_the_circle_shown() {
|
||||
fn a_first_press_dragged_back_near_its_press_places_the_first_point() {
|
||||
let (d, _) = doc_with_rect();
|
||||
let (s, p) = (Selection::default(), paint());
|
||||
let cx = ToolContext { smart_guides: false, ..cx(&d, &s, &p) };
|
||||
let mut t = from_center();
|
||||
assert_eq!(drag(&mut t, &cx, (300.0, 300.0), &[(320.0, 300.0), (301.0, 300.0)], Mods::default()), centered((300.0, 300.0), (301.0, 300.0)));
|
||||
assert!(!t.ends_on_escape(&cx), "no center is left pending");
|
||||
assert_eq!(drag(&mut t, &cx, (300.0, 300.0), &[(320.0, 300.0), (301.0, 300.0)], Mods::default()), vec![]);
|
||||
assert!(t.ends_on_escape(&cx), "the center is placed");
|
||||
assert_eq!(click(&mut t, &cx, (380.0, 300.0)), centered((300.0, 300.0), (380.0, 300.0)));
|
||||
let mut t = CircleTool::default();
|
||||
assert_eq!(drag(&mut t, &cx, (300.0, 300.0), &[(320.0, 300.0), (301.0, 300.0)], Mods::default()), circle(&[(300.0, 300.0), (301.0, 300.0)]));
|
||||
assert!(!t.ends_on_escape(&cx));
|
||||
assert_eq!(drag(&mut t, &cx, (300.0, 300.0), &[(320.0, 300.0), (300.0, 300.0)], Mods::default()), vec![]);
|
||||
assert_eq!(drag(&mut t, &cx, (300.0, 300.0), &[(320.0, 300.0), (301.0, 300.0)], Mods::default()), vec![]);
|
||||
assert!(t.ends_on_escape(&cx), "the first point is placed");
|
||||
t.key(&cx, ToolKey::Escape, Mods::default());
|
||||
// A drag to a circle past the canvas draws nothing and leaves no point behind.
|
||||
|
||||
Reference in New Issue
Block a user