Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Clone Stamp and History Brush: releasing a stroke commits the live pixels (#4019)

xsvm776b9dddd089
diff --git a/crates/engine/src/brush_cmds.rs b/crates/engine/src/brush_cmds.rs
index 321973b8d..e66e18b94 100644
--- a/crates/engine/src/brush_cmds.rs
+++ b/crates/engine/src/brush_cmds.rs
@@ -437,17 +437,19 @@ pub struct LiveStroke {
base: (photocraft_doc::DocId, u64),
}
-/// A finished live stroke offered to its own commit ([`Session::offer_live_stroke`]): when the
-/// committing `paint.stroke` / `paint.pencil` matches it (same command, document revision, params,
-/// seed and points), the command takes these pixels instead of rendering the stroke again.
+/// A finished live stroke offered to its own commit ([`Session::offer_live_stroke`],
+/// [`Session::offer_live_retouch`]): when the committing command matches it (same command,
+/// document revision, params, seed and points), it takes these pixels instead of rendering the
+/// stroke again.
pub struct LiveCommit {
- cmd: String,
- base: (photocraft_doc::DocId, u64),
- params: Value,
- seed: u64,
- points: Vec<StrokePoint>,
- surface: Surface,
- bounds: Rect,
+ pub(crate) cmd: String,
+ pub(crate) base: (photocraft_doc::DocId, u64),
+ pub(crate) params: Value,
+ /// The Brush's and Pencil's seed; the retouching tools have none.
+ pub(crate) seed: Option<u64>,
+ pub(crate) points: Vec<StrokePoint>,
+ pub(crate) surface: Surface,
+ pub(crate) bounds: Rect,
}
impl LiveCommit {
@@ -461,11 +463,11 @@ impl LiveCommit {
p
}
- fn matches(&self, s: &Session, cmd: &str, p: &Value, pts: &[StrokePoint]) -> bool {
+ pub(crate) fn matches(&self, s: &Session, cmd: &str, p: &Value, pts: &[StrokePoint]) -> bool {
let base = s.active().map(|st| (st.doc.id, st.revision));
self.cmd == cmd
&& base == Some(self.base)
- && p.get("seed").and_then(Value::as_u64) == Some(self.seed)
+ && p.get("seed").and_then(Value::as_u64) == self.seed
&& self.points == pts
&& Self::settings(p) == Self::settings(&self.params)
}
@@ -531,7 +533,7 @@ impl LiveStroke {
pub fn into_commit(mut self) -> Result<LiveCommit> {
let bounds = self.bounds();
let (surf, _) = crate::channel_cmds::target_surface(std::sync::Arc::make_mut(&mut self.doc), self.layer, &self.params)?;
- Ok(LiveCommit { cmd: self.cmd, base: self.base, params: self.params, seed: self.seed, points: self.points, surface: surf.clone(), bounds })
+ Ok(LiveCommit { cmd: self.cmd, base: self.base, params: self.params, seed: Some(self.seed), points: self.points, surface: surf.clone(), bounds })
}
/// Everything the stroke has touched so far.
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index 27a2f941a..45cf3418f 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -567,6 +567,15 @@ impl Session {
Ok(())
}
+ /// [`Self::offer_live_stroke`] for a live Clone Stamp or History Brush stroke, taken by the
+ /// `paint.cloneStamp` / `paint.historyBrush` it was drawn for. Refused for the Healing Brush
+ /// (it blends on release) and when the brush, layer or clone source changed during the stroke.
+ pub fn offer_live_retouch(&mut self, live: retouch_cmds::LiveRetouch) -> Result<()> {
+ let commit = live.into_commit(self)?;
+ self.live_commit = Some(commit);
+ Ok(())
+ }
+
/// Withdraw an offer the command didn't take.
pub fn clear_live_stroke(&mut self) {
self.live_commit = None;
diff --git a/crates/engine/src/retouch_cmds.rs b/crates/engine/src/retouch_cmds.rs
index 833e2db62..cba7a2297 100644
--- a/crates/engine/src/retouch_cmds.rs
+++ b/crates/engine/src/retouch_cmds.rs
@@ -297,15 +297,27 @@ fn clone_stamp(s: &mut Session, p: &Value) -> Result<Value> {
let which = sample_layers(p, CMD)?;
let mode = blend_param(p, CMD)?;
let aligned = flag(p, "aligned", true);
+ // The live stroke the canvas already drew for exactly this commit: take its pixels instead of
+ // rendering the stroke again (the hitch on release).
+ let live = s.live_commit.take().filter(|l| l.matches(s, CMD, p, &stroke.points));
+ let from_live = live.is_some();
let map = clone_mapping(s, p, &stroke, CMD)?;
let off = map.offset();
let dmg = run_stroke(s, "Clone Stamp", id, p, |pre, surf, sel, lock| {
+ if let Some(l) = live {
+ *surf = l.surface;
+ return Ok(l.bounds);
+ }
let (bounds, cov) = stroke_coverage(&stroke);
// Samples come from the pre-stroke state, so pixels painted earlier in the stroke are never re-cloned.
let paint = clone_sample(pre, id, surf, which, bounds, &map, CMD)?;
Ok(apply_coverage(surf, bounds, &cov, stroke.brush.opacity, sel, lock, &paint, mode))
})?;
- Ok(clone_result(dmg, off, aligned, p, &stroke))
+ let mut r = clone_result(dmg, off, aligned, p, &stroke);
+ if from_live {
+ r["fromLive"] = json!(true);
+ }
+ Ok(r)
}
/// What a live retouching stroke paints through its coverage.
@@ -337,6 +349,11 @@ pub struct LiveRetouch {
/// Where the doc shows what finishing the stroke now would add (a lone first dab, the
/// smoothing catch-up), redrawn on every step as the Brush's live stroke does.
tail: Rect,
+ /// The document and revision the stroke started on.
+ base: (photocraft_doc::DocId, u64),
+ brush: Box<BrushSettings>,
+ /// Every point rendered so far, in order.
+ points: Vec<StrokePoint>,
}
impl LiveRetouch {
@@ -358,7 +375,8 @@ impl LiveRetouch {
"paint.historyBrush" => LivePaint::History(history_source(s, id, p, cmd)?),
other => return Err(bad(other, "live retouching strokes are the Clone Stamp, Healing Brush and History Brush")),
};
- let pre = s.active().ok_or(EngineError::NoDocument)?.doc.clone();
+ let st = s.active().ok_or(EngineError::NoDocument)?;
+ let (pre, base) = (st.doc.clone(), (st.doc.id, st.revision));
let mut doc = (*pre).clone();
let sel = doc.selection.clone();
let (surf, lock) = crate::channel_cmds::target_surface(&mut doc, id, p)?;
@@ -366,6 +384,7 @@ impl LiveRetouch {
// As `stroke_coverage`, which the commit uses.
let renderer = photocraft_paint::StrokeRenderer::new(&stroke.brush, None, 1.0);
let opacity = stroke.brush.opacity;
+ let brush = Box::new(stroke.brush.clone());
let paint = match paint {
LivePaint::History(src) if src.format() != pre_surf.format() => LivePaint::History(src.convert(pre_surf.format())),
other => other,
@@ -384,6 +403,9 @@ impl LiveRetouch {
sel,
lock,
tail: Rect::EMPTY,
+ base,
+ brush,
+ points: Vec::new(),
};
live.push(&stroke.points)?;
Ok(live)
@@ -394,15 +416,46 @@ impl LiveRetouch {
self.renderer.bounds().union(&self.tail)
}
+ /// Every point rendered so far, in order.
+ pub fn points(&self) -> &[StrokePoint] {
+ &self.points
+ }
+
+ /// The finished stroke as its commit would take it over ([`Session::offer_live_retouch`]).
+ /// Only the Clone Stamp and History Brush draw what they commit (the Healing Brush blends on
+ /// release), and only while the brush, layer and clone source are still the ones the stroke
+ /// started with: the document revision doesn't cover those.
+ pub(crate) fn into_commit(mut self, s: &Session) -> Result<crate::brush_cmds::LiveCommit> {
+ let (stroke, id) = parse_brush(s, &self.params, &self.cmd)?;
+ let source_unchanged = match &self.paint {
+ LivePaint::Clone { map, .. } if self.cmd == "paint.cloneStamp" => {
+ let f = stroke.points.first().ok_or_else(|| bad(&self.cmd, "`points` is empty"))?;
+ crate::presets::clone_source::resolve(s, &self.params, (f.x, f.y), &self.cmd)?.0 == *map
+ }
+ LivePaint::History(_) if self.cmd == "paint.historyBrush" => true,
+ _ => return Err(bad(&self.cmd, "only Clone Stamp and History Brush strokes commit their live pixels")),
+ };
+ if !source_unchanged || *self.brush != stroke.brush || id != self.id {
+ return Err(bad(&self.cmd, "the brush, layer or clone source changed during the stroke"));
+ }
+ let bounds = self.bounds();
+ let (surf, _) = crate::channel_cmds::target_surface(std::sync::Arc::make_mut(&mut self.doc), self.id, &self.params)?;
+ let surface = surf.clone();
+ Ok(crate::brush_cmds::LiveCommit { cmd: self.cmd, base: self.base, params: self.params, seed: None, points: self.points, surface, bounds })
+ }
+
/// Render more points; returns the rectangle that changed. Each changed area is redrawn from
/// the pre-stroke pixels with the stroke's coverage so far, so overlapping dabs build up as in
/// the commit, and pixels painted earlier in the stroke are never re-cloned. What finishing
/// the stroke now would add is drawn too (a lone first dab shows on the press), and redrawn on
/// every step.
/// Invalid coordinates reject the whole batch without changing the preview.
+ /// Only the position and pressure of `pts` are used: the commands take no tilt or times.
pub fn push(&mut self, pts: &[StrokePoint]) -> Result<Rect> {
crate::brush_cmds::check_coords(pts, &self.cmd)?;
- self.renderer.push(pts);
+ let pts: Vec<_> = pts.iter().map(|q| StrokePoint::new(q.x, q.y, q.pressure)).collect();
+ self.points.extend_from_slice(&pts);
+ self.renderer.push(&pts);
let old = std::mem::replace(&mut self.tail, Rect::EMPTY);
let mut dmg = Rect::EMPTY;
if !old.is_empty() {
@@ -519,15 +572,25 @@ fn history_brush(s: &mut Session, p: &Value) -> Result<Value> {
const CMD: &str = "paint.historyBrush";
let (stroke, id) = parse_brush(s, p, CMD)?;
let mode = blend_param(p, CMD)?;
+ let live = s.live_commit.take().filter(|l| l.matches(s, CMD, p, &stroke.points));
+ let from_live = live.is_some();
let src_surface = history_source(s, id, p, CMD)?;
let dmg = run_stroke(s, "History Brush", id, p, |_, surf, sel, lock| {
+ if let Some(l) = live {
+ *surf = l.surface;
+ return Ok(l.bounds);
+ }
let fmt = surf.format();
let src = if src_surface.format() == fmt { src_surface } else { src_surface.convert(fmt) };
let (bounds, cov) = stroke_coverage(&stroke);
let paint = Region::read(&src, bounds);
Ok(apply_coverage(surf, bounds, &cov, stroke.brush.opacity, sel, lock, &paint, mode))
})?;
- Ok(json!({ "damage": damage_json(dmg) }))
+ let mut r = json!({ "damage": damage_json(dmg) });
+ if from_live {
+ r["fromLive"] = json!(true);
+ }
+ Ok(r)
}
// ---------------------------------------------------------------------------------------------
diff --git a/crates/engine/src/retouch_cmds/tests.rs b/crates/engine/src/retouch_cmds/tests.rs
index a0fac91b2..b56619673 100644
--- a/crates/engine/src/retouch_cmds/tests.rs
+++ b/crates/engine/src/retouch_cmds/tests.rs
@@ -1640,3 +1640,125 @@ fn remove_to_a_new_layer_leaves_the_target_untouched() {
assert!(near(d.doc.layer(nid).unwrap().surface().unwrap().rgba(46, 30), bg, 0.03));
assert!(near(d.doc.layer(target).unwrap().surface().unwrap().rgba(46, 30), square, 0.001));
}
+
+/// A Clone Stamp or History Brush stroke drawn live and offered to its commit: the commit takes
+/// the live pixels, and they are what running the command afresh paints, bit for bit, at every
+/// depth, with and without a feathered selection.
+#[test]
+fn a_live_clone_or_history_stroke_commits_its_own_pixels() {
+ let all = [[30.0, 30.0], [50.0, 34.0], [70.0, 28.0], [90.0, 40.0], [60.0, 50.0], [35.0, 44.0], [36.0, 45.0]];
+ let pts = |v: &[[f64; 2]]| v.iter().map(|q| StrokePoint::new(q[0], q[1], 1.0)).collect::<Vec<_>>();
+ for depth in DEPTHS {
+ for (cmd, extra) in [("paint.cloneStamp", json!({"source": [20, 15], "mode": "multiply"})), ("paint.historyBrush", json!({"state": 1}))] {
+ for selected in [false, true] {
+ let setup = || {
+ let mut s = session(120, 70, depth, "rgb");
+ paint_layer(&mut s, texture);
+ s.execute("paint.stroke", json!({"points": [[0, 40], [120, 40]], "size": 20, "hardness": 1.0, "color": "#c03030"})).unwrap();
+ if selected {
+ s.execute("select.rect", json!({"x": 40, "y": 20, "width": 50, "height": 40, "ellipse": true, "feather": 3})).unwrap();
+ }
+ s
+ };
+ let params = |v: &[[f64; 2]]| {
+ let mut p = json!({"points": v, "size": 14, "hardness": 40, "opacity": 70});
+ for (k, x) in extra.as_object().unwrap() {
+ p[k] = x.clone();
+ }
+ p
+ };
+ let mut s = setup();
+ let mut live = LiveRetouch::begin(&s, cmd, &params(&all[..1])).unwrap();
+ live.push(&pts(&all[1..3])).unwrap();
+ live.push(&pts(&all[3..4])).unwrap();
+ live.push(&pts(&all[4..])).unwrap();
+ s.offer_live_retouch(live).unwrap();
+ let r = s.execute(cmd, params(&all)).unwrap();
+ s.clear_live_stroke();
+ assert_eq!(r["fromLive"], true, "{cmd} {depth}-bit selected={selected}");
+ let mut fresh = setup();
+ let r = fresh.execute(cmd, params(&all)).unwrap();
+ assert!(r.get("fromLive").is_none());
+ let (a, b) = (s.active().unwrap(), fresh.active().unwrap());
+ let bounds = a.doc.bounds();
+ let got = a.doc.layer(a.active_layer.unwrap()).unwrap().surface().unwrap().read_region(bounds);
+ let want = b.doc.layer(b.active_layer.unwrap()).unwrap().surface().unwrap().read_region(bounds);
+ let diff = got.iter().zip(&want).position(|(x, y)| x.to_bits() != y.to_bits());
+ assert!(diff.is_none(), "{cmd} {depth}-bit selected={selected}: first difference at value {diff:?}");
+ assert_eq!(a.history.past_len(), b.history.past_len());
+ }
+ }
+ }
+}
+
+/// An offered live stroke is taken only by the commit it was drawn for, and only once.
+#[test]
+fn a_live_retouch_offer_is_taken_only_by_its_own_commit() {
+ let mut s = session(96, 64, 8, "rgb");
+ paint_layer(&mut s, texture);
+ let all = [[50.0, 30.0], [60.0, 34.0], [70.0, 30.0]];
+ let params = |v: &[[f64; 2]], opacity: u32| json!({"points": v, "source": [20, 20], "size": 12, "hardness": 50, "opacity": opacity});
+ let offer = |s: &mut Session| {
+ let live = LiveRetouch::begin(s, "paint.cloneStamp", &params(&all, 70)).unwrap();
+ s.offer_live_retouch(live).unwrap();
+ };
+ let from_live = |r: Value| r.get("fromLive").is_some();
+ // Other points, other params, another command: rendered afresh.
+ offer(&mut s);
+ assert!(!from_live(s.execute("paint.cloneStamp", params(&all[..2], 70)).unwrap()));
+ s.execute("edit.undo", json!({})).unwrap();
+ offer(&mut s);
+ assert!(!from_live(s.execute("paint.cloneStamp", params(&all, 60)).unwrap()));
+ s.execute("edit.undo", json!({})).unwrap();
+ offer(&mut s);
+ let mut history = params(&all, 70);
+ history.as_object_mut().unwrap().remove("source");
+ assert!(!from_live(s.execute("paint.historyBrush", history).unwrap()));
+ s.execute("edit.undo", json!({})).unwrap();
+ // The document changed after the stroke started.
+ offer(&mut s);
+ s.execute("paint.stroke", json!({"points": [[5, 5], [9, 9]], "size": 4})).unwrap();
+ assert!(!from_live(s.execute("paint.cloneStamp", params(&all, 70)).unwrap()));
+ s.execute("edit.undo", json!({})).unwrap();
+ s.execute("edit.undo", json!({})).unwrap();
+ // A withdrawn offer, and an offer used once.
+ offer(&mut s);
+ s.clear_live_stroke();
+ assert!(!from_live(s.execute("paint.cloneStamp", params(&all, 70)).unwrap()));
+ s.execute("edit.undo", json!({})).unwrap();
+ offer(&mut s);
+ assert!(from_live(s.execute("paint.cloneStamp", params(&all, 70)).unwrap()));
+ s.execute("edit.undo", json!({})).unwrap();
+ assert!(!from_live(s.execute("paint.cloneStamp", params(&all, 70)).unwrap()));
+ // The Healing Brush blends on release: it has no live pixels to offer.
+ let healing = LiveRetouch::begin(&s, "paint.healingBrush", &params(&all, 70)).unwrap();
+ assert!(s.offer_live_retouch(healing).is_err());
+ // The brush changed during the stroke (the document revision doesn't show it).
+ let live = LiveRetouch::begin(&s, "paint.cloneStamp", &params(&all, 70)).unwrap();
+ s.execute("tools.setBrush", json!({"brush": {"spacing": 0.5}})).unwrap();
+ assert!(s.offer_live_retouch(live).is_err());
+}
+
+/// The live stroke renders only the position and pressure of its points, as its commit parses
+/// them: a pen's tilt and the times don't change what it shows.
+#[test]
+fn a_live_retouch_stroke_ignores_tilt_and_times() {
+ let mut s = session(64, 48, 8, "rgb");
+ paint_layer(&mut s, texture);
+ let p = json!({"points": [[20, 20]], "source": [8, 8], "size": 10, "hardness": 50});
+ let mut plain = LiveRetouch::begin(&s, "paint.cloneStamp", &p).unwrap();
+ let mut pen = LiveRetouch::begin(&s, "paint.cloneStamp", &p).unwrap();
+ let pts = [[30.0, 24.0], [44.0, 30.0]];
+ plain.push(&pts.map(|q| StrokePoint::new(q[0], q[1], 0.8))).unwrap();
+ pen.push(&pts.map(|q| {
+ let mut sp = StrokePoint::new(q[0], q[1], 0.8);
+ (sp.tilt_x, sp.tilt_y, sp.rotation, sp.time) = (40.0, -20.0, 90.0, 120.0);
+ sp
+ }))
+ .unwrap();
+ assert_eq!(plain.points(), pen.points());
+ let id = s.active().unwrap().active_layer.unwrap();
+ let b = s.active().unwrap().doc.bounds();
+ let read = |l: &LiveRetouch| l.doc.layer(id).unwrap().surface().unwrap().read_region(b);
+ assert_eq!(read(&plain), read(&pen));
+}
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index af3a11f04..3c067c756 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -680,6 +680,28 @@ fn feed_live_stroke(app: &mut PhotocraftApp) {
}
}
+/// The points the live retouching stroke has rendered.
+#[cfg(test)]
+pub(crate) fn live_retouch_points(app: &PhotocraftApp) -> Option<Vec<photocraft_engine::paint::StrokePoint>> {
+ match &app.live_stroke.as_ref()?.stroke {
+ EngineStroke::Retouch(l) => Some(l.points().to_vec()),
+ _ => None,
+ }
+}
+
+/// Offer the Clone Stamp's or History Brush's live stroke, with the drag points it hasn't rendered
+/// yet, to the command `retouch_ui::finish_stroke` commits, which then takes its pixels.
+fn offer_live_retouch(app: &mut PhotocraftApp, d: &Drag) {
+ if !matches!(d.tool, Tool::CloneStamp | Tool::HistoryBrush) {
+ return;
+ }
+ let Some(LiveStroke { stroke: EngineStroke::Retouch(mut live), fed, .. }) = app.live_stroke.take() else { return };
+ let rest: Vec<_> = d.points.get(fed..).unwrap_or_default().iter().map(|q| photocraft_engine::paint::StrokePoint::new(q[0], q[1], q[2] as f32)).collect();
+ if rest.is_empty() || live.push(&rest).is_ok() {
+ let _ = app.session.offer_live_retouch(live);
+ }
+}
+
/// A pen tap (a drag still at its one press point when released) paints its dab at the highest
/// pressure the pen reached during the contact, not just the first sample's (#1798). A mouse is
/// unchanged at full pressure.
@@ -5164,11 +5186,15 @@ pub(crate) fn finish_gesture(app: &mut PhotocraftApp, d: Drag) {
{
app.last_stroke_end = Some((st.doc.id, end));
}
- // A live Clone Stamp preview ends here; the commit below replaces it.
+ // A live Clone Stamp preview ends here; the commit below replaces it (the Clone Stamp's and
+ // History Brush's with the pixels it already drew).
+ offer_live_retouch(app, &d);
if live_retouch_command(d.tool).is_some() || crate::retouch_ui::dab_params(app, d.tool).is_some() || d.tool == Tool::ColorReplacement {
app.live_stroke = None;
}
- if crate::eraser_ui::finish_stroke(app, d.tool, &d.points) || crate::retouch_ui::finish_stroke(app, d.tool, &d.points, d.modifiers) {
+ let finished = crate::eraser_ui::finish_stroke(app, d.tool, &d.points) || crate::retouch_ui::finish_stroke(app, d.tool, &d.points, d.modifiers);
+ app.session.clear_live_stroke();
+ if finished {
return;
}
match d.tool {
diff --git a/crates/ui-egui/src/stroke_timing_tests.rs b/crates/ui-egui/src/stroke_timing_tests.rs
index 5c369370f..fc6d0c7e7 100644
--- a/crates/ui-egui/src/stroke_timing_tests.rs
+++ b/crates/ui-egui/src/stroke_timing_tests.rs
@@ -337,3 +337,49 @@ fn a_committed_stroke_refreshes_only_what_each_cache_had_not_shown() {
assert_eq!(c.since(0), Some(r(0).union(&r(20)).union(&r(40))), "never showed the stroke: all of it");
assert_eq!(c.since(99), None, "not a key of this stroke");
}
+
+/// A Clone Stamp stroke through the canvas renders the points its commit gets (position and
+/// pressure, no tilt or times), so the commit can take the live pixels; they are what replaying
+/// the journaled command paints.
+#[test]
+fn releasing_a_clone_stamp_stroke_commits_what_a_replay_paints() {
+ let setup = |run: &mut dyn FnMut(&str, Value)| {
+ run("tools.setBrush", json!({"brush": {"size": 16, "hardness": 0.4}}));
+ run("paint.stroke", json!({"points": [[10, 20], [190, 80]], "size": 30, "hardness": 0.5, "color": "#2060c0"}));
+ run("cloneSource.set", json!({"source": [40, 30]}));
+ };
+ let mut h = harness();
+ setup(&mut |id, p| {
+ h.state_mut().run(id, p).unwrap();
+ });
+ h.state_mut().ui.tool = Tool::CloneStamp;
+ h.run_steps(1);
+ move_to(&mut h, 60.0, 50.0);
+ button(&mut h, 60.0, 50.0, true);
+ for (x, y) in [(80.0, 40.0), (110.0, 60.0), (140.0, 45.0), (170.0, 65.0)] {
+ move_to(&mut h, x, y);
+ }
+ let shown = crate::canvas::live_retouch_points(h.state()).expect("a live Clone Stamp stroke");
+ button(&mut h, 170.0, 65.0, false);
+ h.run_steps(2);
+ let app = h.state();
+ let (_, p) = app.session.journal.iter().rev().find(|(id, _)| id == "paint.cloneStamp").cloned().expect("a committed Clone Stamp stroke");
+ let committed: Vec<_> = p["points"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .map(|q| photocraft_engine::paint::StrokePoint::new(q[0].as_f64().unwrap(), q[1].as_f64().unwrap(), q[2].as_f64().unwrap() as f32))
+ .collect();
+ assert!(shown.len() > 1 && committed.starts_with(&shown), "live {shown:?} vs committed {committed:?}");
+ let mut fresh = photocraft_engine::Session::new();
+ fresh.execute("file.new", json!({"width": 200, "height": 100, "background": "white"})).unwrap();
+ setup(&mut |id, p| {
+ fresh.execute(id, p).unwrap();
+ });
+ fresh.execute("paint.cloneStamp", p).unwrap();
+ let st = app.session.active().unwrap();
+ let a = photocraft_compose::render(&st.doc, st.doc.bounds());
+ let b = photocraft_compose::render(&fresh.active().unwrap().doc, st.doc.bounds());
+ assert_eq!(a.px.len(), b.px.len());
+ assert!(a.px.iter().zip(&b.px).all(|(x, y)| x == y), "live commit and replay differ");
+}