Live Paint: a Bucket drag from an edge strokes every edge it crosses

A press on an edge (Shift with Paint Fills alone, or a plain press with
Paint Strokes on) now starts a drag, as a press on a face does. The drag
paints the edge and every visible edge of the same group that it crosses
or comes within 0.0001 pt of, between pointer events and on the release,
as one undo step; Escape cancels it. Edges of other groups and hidden
edges keep their strokes, a drag over edges that already have the stroke
records no undo step, and a drag that starts on a face still fills only
faces. A double-click after such a drag joins through the edges the drag
stroked as the paint they had before it.

livePaint.strokeEdge takes the drag's points and continuation as
livePaint.fill does, and both refuse them with scope connected or
samePaint.

Help page: https://helpx.adobe.com/illustrator/desktop/paint-and-fill/learn-painting-basics/paint-with-the-live-paint-bucket-tool.html
This commit is contained in:
dotCooCoo
2026-11-16 05:32:00 -08:00
parent 7452b6f383
commit ebeffa15ab
9 changed files with 475 additions and 76 deletions
+48 -40
View File
@@ -1,7 +1,7 @@
use super::cache::RegionCache;
use super::lookup::{
connected_edges, connected_edges_through, edges, face_at, faces, flood_faces, is_live_paint, leaf_shapes, live_paint_at, live_paint_at_where,
lp_stroke_paint, node_outline, visible_edge_near, visible_face_at,
lp_stroke_paint, node_outline, visible_edge_near, visible_edges_along, visible_face_at,
};
use super::map::{BuilderMap, HIGHLIGHT_RED, sorted_roots};
use super::{
@@ -173,9 +173,12 @@ enum LpPaint {
/// With Paint Strokes alone on, a click paints the edge nearest the pointer and
/// Shift-click fills the face. With both on, a click paints the edge nearest the pointer when one
/// is within 4 pixels, else it fills the face, and Shift-click fills the face. With both off, a
/// click paints nothing. With Highlight off, the face or edge under the pointer is not
/// highlighted. The cursor is a filled bucket where a click fills a face, a brush where it paints
/// an edge and an empty bucket where it paints nothing; with Alt it is the Eyedropper.
/// click paints nothing. A drag from where a click paints an edge paints that edge and every edge
/// of the same group that the drag crosses or touches with the current stroke, as one undo step
/// (Escape cancels); a drag from where a click fills a face fills only faces. With Highlight off,
/// the face or edge under the pointer is not highlighted. The cursor is a filled bucket where a
/// click fills a face, a brush where it paints an edge and an empty bucket where it paints nothing;
/// with Alt it is the Eyedropper.
///
/// A double-click on a face fills it and the faces reached from it across edges that draw no
/// stroke (`scope: "connected"`); on an edge it paints the edges joined to it that have its stroke.
@@ -195,16 +198,17 @@ enum LpPaint {
/// Swatches panel, wrapping around; from a color that is no swatch, Right picks the first swatch
/// and Left the last. The selected art keeps its paint. With `cursorSwatchPreview` (on), the
/// active paint shows as a chip above the pointer between the swatches before and after it,
/// except during a fill drag or with Alt held; a solid color that is no swatch shows alone, and a
/// except during a fill or stroke drag or with Alt held; a solid color that is no swatch shows alone, and a
/// paint that is not a solid color shows no chip.
pub struct LivePaintBucketTool {
pub(super) cache: RegionCache,
pub(super) hover: LpHover,
/// Where the pointer last moved, and the modifiers held there.
at: Option<(Point, Mods)>,
/// The fill command and polyline previewed from the press's snapshot.
fill_drag: Option<(Value, Vec<Vec<Point>>)>,
/// What a fill drag paints, as it was at its press.
/// The command (`livePaint.fill` or `livePaint.strokeEdge`), its params and the polyline of a
/// drag, previewed from the press's snapshot.
fill_drag: Option<(&'static str, Value, Vec<Vec<Point>>)>,
/// What a drag paints, as it was at its press.
drag_from: LpDragFrom,
/// The last [`LP_PRESSES`] presses, oldest first: the face or edge each one painted, with its
/// paint before that press, or None for a press that painted no face or edge.
@@ -234,15 +238,15 @@ struct LpPress {
/// The other faces or edges the double-click that followed the press reached, each with its
/// fill or drawn stroke paint before the double-click.
also: Vec<(NodeId, Paint)>,
/// The other faces the press's drag crossed, its release included, each with its fill before
/// the press.
/// The other faces or edges the press's drag crossed, its release included, each with its fill
/// or drawn stroke paint before the press.
dragged: Vec<(NodeId, Paint)>,
/// For a press that makes the Live Paint group: what the group is made from, with the path
/// chunks of the press's drag, its release included.
dragged_made: Option<Arc<(LpMade, Vec<Vec<Point>>)>>,
}
/// What a Live Paint Bucket fill drag paints, as it was at the press.
/// What a Live Paint Bucket fill or stroke drag paints, as it was at the press.
#[derive(Default)]
enum LpDragFrom {
#[default]
@@ -251,6 +255,8 @@ enum LpDragFrom {
Faces(Vec<Arc<Node>>),
/// What the group is made from, for a drag that makes the group.
Made(LpMade),
/// The Live Paint group whose edges a stroke drag paints.
Edges(Arc<Node>),
}
/// The faces among `faces` (a Live Paint group's faces, back to front) that a drag along the path
@@ -404,13 +410,15 @@ impl LivePaintBucketTool {
usize::from(!cx.fill_active)
}
fn begin_fill(&mut self, params: Value, p: Point) -> Vec<Action> {
self.fill_drag = Some((params.clone(), vec![vec![p]]));
vec![Action::Begin("Live Paint Bucket".into()), Action::Preview("livePaint.fill".into(), params)]
/// Start a drag pressed at `p` that previews `cmd` with `params` and the drag's path.
fn begin_fill(&mut self, cmd: &'static str, params: Value, p: Point) -> Vec<Action> {
self.fill_drag = Some((cmd, params.clone(), vec![vec![p]]));
vec![Action::Begin("Live Paint Bucket".into()), Action::Preview(cmd.into(), params)]
}
fn drag_fill(&mut self, p: Point) -> Vec<Action> {
let Some((params, chunks)) = &mut self.fill_drag else { return vec![] };
let Some((cmd, params, chunks)) = &mut self.fill_drag else { return vec![] };
let cmd = *cmd;
let Some(points) = chunks.last_mut() else { return vec![] };
let Some(&last) = points.last() else { return vec![] };
if last == p {
@@ -431,7 +439,7 @@ impl LivePaintBucketTool {
if !continuation.is_empty() {
params["continuation"] = Value::Array(continuation);
}
vec![Action::Preview("livePaint.fill".into(), params)]
vec![Action::Preview(cmd.into(), params)]
}
/// What a click paints, Shift held or not. Shift switches Paint Fills alone to Paint Strokes
@@ -459,13 +467,13 @@ impl LivePaintBucketTool {
self.note_press(Some(LpPress { part: Some(n.id), at, before, also: vec![], dragged: vec![], dragged_made: None }));
}
/// End the fill drag, noting on the last press the other faces its drag crossed, with their
/// fills before the press (for a press that makes the group, what the group is made from and
/// the drag, for [`Self::before`] to look the faces up in the group made). → whether a fill
/// drag was on.
/// End the drag, noting on the last press the other faces or edges its drag crossed, with their
/// fills or drawn stroke paints before the press (for a press that makes the group, what the
/// group is made from and the drag, for [`Self::before`] to look the faces up in the group
/// made). → whether a drag was on.
fn end_fill(&mut self) -> bool {
let from = std::mem::take(&mut self.drag_from);
let Some((_, chunks)) = self.fill_drag.take() else { return false };
let Some((_, _, chunks)) = self.fill_drag.take() else { return false };
let Some(Some(last)) = self.presses.last_mut() else { return true };
match from {
LpDragFrom::None => {}
@@ -474,6 +482,11 @@ impl LivePaintBucketTool {
last.dragged = crossed_faces(&faces, &chunks).into_iter().filter(|(id, _)| part != Some(*id)).collect();
}
LpDragFrom::Made(made) => last.dragged_made = Some(Arc::new((made, chunks))),
LpDragFrom::Edges(group) => {
let part = last.part;
last.dragged =
visible_edges_along(&group, &chunks).into_iter().filter(|e| part != Some(e.id)).map(|e| (e.id, lp_stroke_paint(e))).collect();
}
}
true
}
@@ -549,22 +562,16 @@ impl LivePaintBucketTool {
if clicks == 2
&& let Some(group) = cx.doc.node(g)
{
// The other edge of this group either click painted joins as the stroke paint it
// had before. A face either click filled is not an edge and does not join.
// The other edges of this group either click painted, by its press or its drag, join
// as the stroke paint they had before. A face either click filled is not an edge and
// does not join. `livePaint.strokeEdge` takes at most 4096 of them.
let group_edges: std::collections::HashSet<NodeId> = edges(group).iter().map(|x| x.id).collect();
let mut seen = std::collections::HashSet::from([e.id]);
let mut through: Vec<NodeId> = vec![];
for id in self
.presses
.len()
.checked_sub(2)
.and_then(|i| self.presses.get(i..))
.into_iter()
.flatten()
.flatten()
.filter(|q| q.before == like)
.filter_map(|q| q.part)
{
if id != e.id && group_edges.contains(&id) && !through.contains(&id) {
for id in self.presses.len().checked_sub(2).and_then(|i| self.presses.get(i..)).into_iter().flatten().flatten().flat_map(|q| {
q.part.filter(|_| q.before == like).into_iter().chain(q.dragged.iter().filter(|(_, before)| *before == like).map(|(id, _)| *id))
}) {
if through.len() < 4096 && group_edges.contains(&id) && seen.insert(id) {
through.push(id);
}
}
@@ -718,7 +725,8 @@ impl Tool for LivePaintBucketTool {
&& let Some((g, Some(e))) = lp_part_at(cx.doc, p, cx.tol(4.0), true, &|id| lp_visible(cx, id))
{
self.note_part(e, true, p);
return vec![Action::Exec("livePaint.strokeEdge".into(), json!({ "group": g.0, "point": point, "tolerance": cx.tol(4.0) }))];
self.drag_from = cx.doc.node(g).map_or(LpDragFrom::None, |n| LpDragFrom::Edges(Arc::new(n.clone())));
return self.begin_fill("livePaint.strokeEdge", json!({ "group": g.0, "point": point, "tolerance": cx.tol(4.0) }), p);
}
if !matches!(paint, LpPaint::Fills | LpPaint::Both) {
self.note_press(None);
@@ -730,7 +738,7 @@ impl Tool for LivePaintBucketTool {
None => self.note_press(None),
}
self.drag_from = LpDragFrom::Faces(cx.doc.node(g).map(|n| faces(n).into_iter().cloned().collect()).unwrap_or_default());
return self.begin_fill(json!({ "group": g.0, "point": point }), p);
return self.begin_fill("livePaint.fill", json!({ "group": g.0, "point": point }), p);
}
if self.cache.at(cx, p).is_some() {
let roots = sorted_roots(cx.doc, &cx.selection.objects);
@@ -738,7 +746,7 @@ impl Tool for LivePaintBucketTool {
let before = made_face_fill(&made, p);
self.note_press(Some(LpPress { part: None, at: p, before, also: vec![], dragged: vec![], dragged_made: None }));
self.drag_from = LpDragFrom::Made(made);
return self.begin_fill(json!({ "ids": json_ids(&roots), "point": point }), p);
return self.begin_fill("livePaint.fill", json!({ "ids": json_ids(&roots), "point": point }), p);
}
self.note_press(None);
vec![]
@@ -762,7 +770,7 @@ impl Tool for LivePaintBucketTool {
self.presses.clear();
}
/// Escape during a fill drag cancels it. Left and Right pick the color swatch before or after
/// Escape during a fill or stroke drag cancels it. Left and Right pick the color swatch before or after
/// the active paint, while no drag is on.
fn key(&mut self, cx: &ToolContext, key: ToolKey, mods: Mods) -> Vec<Action> {
if key == ToolKey::Escape {
@@ -819,7 +827,7 @@ impl Tool for LivePaintBucketTool {
fn overlays(&self, cx: &ToolContext) -> Vec<Overlay> {
let mut out = lp_overlays(&self.hover, &self.cache, self.color, self.width as f32, (self.width * LP_BUCKET_EDGE_FRACTION) as f32);
// No chips during a fill drag, or while Alt makes the tool sample with the eyedropper.
// No chips during a fill or stroke drag, or while Alt makes the tool sample with the eyedropper.
if self.preview
&& !self.busy()
&& let Some((at, mods)) = self.at
+58
View File
@@ -90,6 +90,64 @@ pub fn visible_edge_near(group: &Node, p: Point, tol: f64) -> Option<&Arc<Node>>
nearest_edge(edges(group).into_iter().filter(|e| e.visible), p, tol)
}
/// The edges of `group` that are not hidden and that the polyline through the points of each chunk
/// of `chunks` crosses or comes within [`LP_JOIN_TOL`] of, each once, in the group's order. Each
/// stretch of the polyline tests only the edge segments whose bounds lie near it.
pub fn visible_edges_along<'a>(group: &'a Node, chunks: &[Vec<Point>]) -> Vec<&'a Arc<Node>> {
use kurbo::ParamCurveNearest as _;
let shown: Vec<&Arc<Node>> = edges(group).into_iter().filter(|e| e.visible).collect();
// Each edge segment, with the index in `shown` of its edge.
let mut owner: Vec<usize> = vec![];
let mut segs: Vec<(kurbo::CubicBez, bool)> = vec![];
for (i, e) in shown.iter().enumerate() {
for s in e.path_data().map(lp_segments).unwrap_or_default() {
owner.push(i);
segs.push((s, true));
}
}
if segs.is_empty() {
return vec![];
}
let grid = LpEdgeGrid::new(&segs);
let close = LP_JOIN_TOL * LP_JOIN_TOL;
let mut hit = vec![false; shown.len()];
for chunk in chunks {
for pair in chunk.windows(2) {
let &[a, b] = pair else { continue };
let line = kurbo::Line::new(a, b);
let on_line = |p: Point| line.nearest(p, 1e-9).distance_sq <= close;
for k in grid.near_box(Rect::from_points(a, b).inflate(LP_JOIN_TOL, LP_JOIN_TOL)) {
let (Some((c, _)), Some(&i)) = (segs.get(k), owner.get(k)) else { continue };
let Some(h) = hit.get_mut(i) else { continue };
if *h {
continue;
}
let on_seg = |p: Point| c.nearest(p, 1e-9).distance_sq <= close;
// An end of either one on the other covers a touch and a stretch that runs along
// the edge, where no single crossing point exists. Where neither crosses the other,
// their closest points are ends or a point of the edge where it runs parallel to
// the drag.
*h = on_seg(a)
|| on_seg(b)
|| on_line(c.p0)
|| on_line(c.p3)
|| (a != b
&& (!kurbo::PathSeg::Cubic(*c).intersect_line(line).is_empty()
|| lp_parallel_at(c, b - a).into_iter().any(|t| on_line(kurbo::ParamCurve::eval(c, t)))));
}
}
}
shown.into_iter().zip(hit).filter_map(|(e, h)| h.then_some(e)).collect()
}
/// The parameters strictly between 0 and 1 where cubic `c` runs parallel to direction `d`: the
/// roots of the cross product of its derivative with `d`.
fn lp_parallel_at(c: &kurbo::CubicBez, d: kurbo::Vec2) -> Vec<f64> {
let [a, b, e] = [c.p1 - c.p0, c.p2 - c.p1, c.p3 - c.p2].map(|v| v.cross(d));
// a(1-t)² + 2b·t(1-t) + e·t², expanded in powers of t.
kurbo::common::solve_quadratic(a, 2.0 * (b - a), a - 2.0 * b + e).into_iter().filter(|t| t.is_finite() && *t > 0.0 && *t < 1.0).collect()
}
/// The edge of `edges` nearest to `p` within `tol`.
fn nearest_edge<'a>(edges: impl IntoIterator<Item = &'a Arc<Node>>, p: Point, tol: f64) -> Option<&'a Arc<Node>> {
let mut best: Option<(f64, &Arc<Node>)> = None;
+160 -6
View File
@@ -1120,8 +1120,147 @@ fn bucket_click_fills_face_and_shift_click_strokes_edge() {
assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, 75.0, 25.0)), vec![Action::Commit]);
let shift = Mods { shift: true, ..Default::default() };
let acts = t.pointer(&cx, &ev(PointerKind::Down, 51.0, 25.0).with_mods(shift));
let Action::Exec(id, _) = &acts[0] else { panic!() };
let [Action::Begin(_), Action::Preview(id, _)] = acts.as_slice() else { panic!("{acts:?}") };
assert_eq!(id, "livePaint.strokeEdge");
assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, 51.0, 25.0).with_mods(shift)), vec![Action::Commit]);
}
/// A drag reaches the visible edges its path crosses or passes within 0.0001 pt of, including the
/// middle of a curved edge it runs past without crossing; a hidden edge and an edge farther away are
/// not reached.
#[test]
fn visible_edges_along_finds_crossed_and_near_edges() {
let mut d = Document::new(500.0, 500.0);
let l = d.layers[0].id;
let mut arc = BezPath::new();
arc.move_to((100.0, 0.0));
// Farthest right at (130, 50), where it runs straight down.
arc.curve_to((140.0, 0.0), (140.0, 100.0), (100.0, 100.0));
let mut kids = vec![empty_sources(&mut d)];
let mut ids = vec![];
for (path, visible) in [
(shapes::line(Point::new(0.0, 0.0), Point::new(0.0, 100.0)), true),
(shapes::line(Point::new(50.0, 0.0), Point::new(50.0, 100.0)), false),
(vectorcraft_geom::PathData::from_bezpath(&arc), true),
(shapes::line(Point::new(0.0, 200.0), Point::new(100.0, 200.0)), true),
] {
let id = d.alloc_id();
let mut edge = Node::path(id, path, Appearance::default());
edge.name = Some(EDGE_NAME.into());
edge.visible = visible;
kids.push(Arc::new(edge));
ids.push(id);
}
let gid = d.alloc_id();
let mut g = Node::group(gid, kids);
g.name = Some(LIVE_PAINT_NAME.into());
d.insert(Some(l), 0, g).unwrap();
let group = d.node(gid).unwrap();
let reached = |x: f64| {
let chunks = vec![
vec![Point::new(-10.0, 50.0), Point::new(60.0, 50.0), Point::new(60.0, -20.0)],
vec![Point::new(60.0, -20.0), Point::new(x, -20.0), Point::new(x, 60.0)],
];
visible_edges_along(group, &chunks).iter().map(|e| e.id).collect::<Vec<_>>()
};
assert_eq!(reached(130.00005), vec![ids[0], ids[2]]);
assert_eq!(reached(130.001), vec![ids[0]]);
}
/// A double-click on an edge after a press whose drag stroked another edge of the line joins
/// through that edge as the stroke paint it had before the drag.
#[test]
fn bucket_edge_double_click_joins_through_an_edge_the_first_drag_stroked() {
let black = vectorcraft_color::Paint::solid(vectorcraft_color::Color::rgb(0.0, 0.0, 0.0));
let green = vectorcraft_color::Paint::solid(vectorcraft_color::Color::rgb(0.0, 1.0, 0.0));
let mut d = Document::new(500.0, 500.0);
let l = d.layers[0].id;
let mut kids = vec![empty_sources(&mut d)];
let mut ids = vec![];
for (x0, x1) in [(0.0, 30.0), (30.0, 70.0), (70.0, 100.0)] {
let id = d.alloc_id();
let mut a = Appearance::default();
a.set_stroke(black.clone());
let mut edge = Node::path(id, shapes::line(Point::new(x0, 100.0), Point::new(x1, 100.0)), a);
edge.name = Some(EDGE_NAME.into());
kids.push(Arc::new(edge));
ids.push(id);
}
let gid = d.alloc_id();
let mut g = Node::group(gid, kids);
g.name = Some(LIVE_PAINT_NAME.into());
d.insert(Some(l), 0, g).unwrap();
let mut later = d.clone();
for id in &ids[1..] {
later.node_mut(*id).unwrap().appearance.set_stroke(green.clone());
}
let s = Selection::default();
let p = paint();
let (cx, later) = (cx(&d, &s, &p), cx(&later, &s, &p));
let shift = Mods { shift: true, ..Default::default() };
let mut t = LivePaintBucketTool::default();
// The first press strokes the right edge and its drag crosses the middle one.
for (k, x, y) in
[(PointerKind::Down, 85.0, 100.0), (PointerKind::Drag, 85.0, 110.0), (PointerKind::Drag, 50.0, 110.0), (PointerKind::Up, 50.0, 90.0)]
{
t.pointer(&cx, &ev(k, x, y).with_mods(shift));
}
t.pointer(&later, &ev(PointerKind::Down, 85.0, 100.0).with_mods(shift));
t.pointer(&later, &ev(PointerKind::Up, 85.0, 100.0).with_mods(shift));
let like = serde_json::to_value(&black).unwrap();
assert_eq!(
t.pointer(&later, &ev(PointerKind::DoubleClick, 85.0, 100.0).with_mods(shift)),
vec![Action::Exec(
"livePaint.strokeEdge".into(),
json!({ "group": gid.0, "point": [85.0, 100.0], "tolerance": 4.0, "scope": "connected", "through": [ids[1].0], "match": like })
)]
);
}
/// A drag from an edge previews `livePaint.strokeEdge` with the drag's path as it goes and commits
/// once on the release; Escape cancels it, and what the drag paints is fixed at the press.
#[test]
fn bucket_edge_drag_previews_points_and_commits_once() {
let (d, gid, ..) = live_group_doc();
let s = Selection::default();
let p = paint();
let cx = cx(&d, &s, &p);
let shift = Mods { shift: true, ..Default::default() };
let stroke = |points: Value| {
let mut v = json!({ "group": gid.0, "point": [51.0, 25.0], "tolerance": 4.0 });
if !points.is_null() {
v["points"] = points;
}
Action::Preview("livePaint.strokeEdge".into(), v)
};
let mut t = LivePaintBucketTool::default();
assert_eq!(
t.pointer(&cx, &ev(PointerKind::Down, 51.0, 25.0).with_mods(shift)),
vec![Action::Begin("Live Paint Bucket".into()), stroke(Value::Null)]
);
assert!(t.busy());
// Shift let go during the drag: the drag still paints edges.
assert_eq!(t.pointer(&cx, &ev(PointerKind::Drag, 75.0, 25.0)), vec![stroke(json!([[51.0, 25.0], [75.0, 25.0]]))]);
assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, 120.0, 25.0)), vec![stroke(json!([[51.0, 25.0], [75.0, 25.0], [120.0, 25.0]])), Action::Commit]);
assert!(!t.busy());
// Escape before the release cancels the drag, and the release then commits nothing.
assert_eq!(
t.pointer(&cx, &ev(PointerKind::Down, 51.0, 25.0).with_mods(shift)),
vec![Action::Begin("Live Paint Bucket".into()), stroke(Value::Null)]
);
t.pointer(&cx, &ev(PointerKind::Drag, 75.0, 25.0).with_mods(shift));
assert!(t.claims_key(&cx, ToolKey::Escape));
assert_eq!(t.key(&cx, ToolKey::Escape, Mods::default()), vec![Action::Cancel]);
assert!(t.pointer(&cx, &ev(PointerKind::Up, 120.0, 25.0).with_mods(shift)).is_empty());
// With both options on, a drag from a face fills faces, even across an edge.
t.set_option("paintStrokes", &json!(true));
let acts = t.pointer(&cx, &ev(PointerKind::Down, 75.0, 25.0));
let [Action::Begin(_), Action::Preview(id, _)] = acts.as_slice() else { panic!("{acts:?}") };
assert_eq!(id, "livePaint.fill");
let acts = t.pointer(&cx, &ev(PointerKind::Drag, 51.0, 25.0));
let [Action::Preview(id, _)] = acts.as_slice() else { panic!("{acts:?}") };
assert_eq!(id, "livePaint.fill");
t.pointer(&cx, &ev(PointerKind::Up, 51.0, 25.0));
}
/// A double-click runs a click's command with `scope: "connected"` and a triple-click with
@@ -1484,7 +1623,12 @@ fn bucket_options_choose_what_a_click_paints() {
let fill = |x: f64| {
vec![Action::Begin("Live Paint Bucket".into()), Action::Preview("livePaint.fill".into(), json!({ "group": gid.0, "point": [x, 25.0] }))]
};
let stroke = |x: f64| vec![Action::Exec("livePaint.strokeEdge".into(), json!({ "group": gid.0, "point": [x, 25.0], "tolerance": 4.0 }))];
let stroke = |x: f64| {
vec![
Action::Begin("Live Paint Bucket".into()),
Action::Preview("livePaint.strokeEdge".into(), json!({ "group": gid.0, "point": [x, 25.0], "tolerance": 4.0 })),
]
};
let click = |t: &mut LivePaintBucketTool, x: f64, m: Mods| {
let acts = t.pointer(&cx, &ev(PointerKind::Down, x, 25.0).with_mods(m));
t.pointer(&cx, &ev(PointerKind::Up, x, 25.0).with_mods(m));
@@ -3095,8 +3239,13 @@ fn live_paint_edges_outside_the_faces_come_from_the_nearest_visible_group() {
bucket.set_option("cursorSwatchPreview", &json!(false));
bucket.pointer(&cx, &ev(PointerKind::Move, x, y).with_mods(shift));
assert_eq!(edge_x(&bucket.overlays(&cx)), want.map(|w| w.2));
let stroked = want.map(|(g, ..)| Action::Exec("livePaint.strokeEdge".into(), json!({ "group": g.0, "point": [x, y], "tolerance": 4.0 })));
assert_eq!(bucket.pointer(&cx, &ev(PointerKind::Down, x, y).with_mods(shift)), stroked.into_iter().collect::<Vec<_>>());
let stroked = want.map(|(g, ..)| {
vec![
Action::Begin("Live Paint Bucket".into()),
Action::Preview("livePaint.strokeEdge".into(), json!({ "group": g.0, "point": [x, y], "tolerance": 4.0 })),
]
});
assert_eq!(bucket.pointer(&cx, &ev(PointerKind::Down, x, y).with_mods(shift)), stroked.unwrap_or_default());
};
check(&d, Some((back, back_right, 100.0)));
// A hidden group's edges are not highlighted or picked.
@@ -3139,8 +3288,13 @@ fn live_paint_tools_skip_hidden_edges() {
bucket.set_option("cursorSwatchPreview", &json!(false));
bucket.pointer(&cx, &ev(PointerKind::Move, x, 50.0).with_mods(shift));
assert_eq!(edge_x(&bucket.overlays(&cx)), want.map(|w| w.2), "x {x}");
let stroked = want.map(|(g, ..)| Action::Exec("livePaint.strokeEdge".into(), json!({ "group": g.0, "point": [x, 50.0], "tolerance": 4.0 })));
assert_eq!(bucket.pointer(&cx, &ev(PointerKind::Down, x, 50.0).with_mods(shift)), stroked.into_iter().collect::<Vec<_>>(), "x {x}");
let stroked = want.map(|(g, ..)| {
vec![
Action::Begin("Live Paint Bucket".into()),
Action::Preview("livePaint.strokeEdge".into(), json!({ "group": g.0, "point": [x, 50.0], "tolerance": 4.0 })),
]
});
assert_eq!(bucket.pointer(&cx, &ev(PointerKind::Down, x, 50.0).with_mods(shift)), stroked.unwrap_or_default(), "x {x}");
}
}