mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Tests: trim repeated variants in ui-egui canvas integration tests (#15369)
Run each variant once where the loops reached the same code, and reuse one app harness instead of building one per case: - checker_canvas pixel grid: 8-bit on every canvas and scale, plus 16-bit and 32-bit once each on the GPU canvas (the grid reads the same f32 composite at every depth; depth only changes the GPU texture). - live_stroke_canvas: one harness for the raw pointer and camera tests; camera navigation runs the Brush only (no tool branch before a press); the committed stroke runs every zoom once with every smoothing amount, plus the special cases, split over the three parts so every case runs (the step was still 4 after part 3 was removed, so four cases never ran). - adjust_preview_gpu clipped target: each kind once per mode, cycling the depth/selection pairs; the full matrix stays in the unclipped test. - drag_preview_canvas marquee: one grey document that checks both ant colours, one harness for both scales. - arbitrary_rotation_preview: drop -45 degrees (same preview size as 45). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
08c4d76e9d
commit
3b62ce7cb8
5 files changed
+189
-129
No files matched your search
@@ -229,40 +229,46 @@ fn clipped_target_preview_composites_on_the_gpu_like_the_command() {
|
||||
let Some((device, queue, mut comp)) = gpu() else { return };
|
||||
let (tol_gpu, tol_cmd) = (2.0 / 255.0, 2.5 / 255.0);
|
||||
let mut worst = 0.0f32;
|
||||
for mode in [ColorMode::Rgb, ColorMode::Grayscale] {
|
||||
for depth in [SampleType::U8, SampleType::U16, SampleType::F32] {
|
||||
for selection in [false, true] {
|
||||
let (doc, target) = clipped_document(mode, depth, selection);
|
||||
for kind in photocraft_ui_egui::adjust_editors::KINDS {
|
||||
let params = sample(kind);
|
||||
let preview = match preview_document(&doc, target, kind, ¶ms) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
// Only grayscale kinds that make colour keep the CPU proxy preview.
|
||||
assert_eq!(mode, ColorMode::Grayscale, "{kind}: {e}");
|
||||
assert!(GRAY_COLOUR.contains(&kind), "{kind} {mode:?}: unexpected preview error: {e}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
assert!(preview.layer(PREVIEW_LAYER).is_some());
|
||||
assert!(preview.layer(target).unwrap().is_group(), "the clipped target is isolated");
|
||||
let what = format!("{kind} {mode:?} {depth:?} selection {selection}");
|
||||
let b = preview.bounds();
|
||||
let skip = if matches!(kind, "threshold" | "posterize") && depth != SampleType::U8 { (b.width() * b.height()) as usize / 100 } else { 0 };
|
||||
let on_gpu = render_to_vec(&mut comp, &device, &queue, &preview, b).unwrap_or_else(|e| panic!("{what}: {e:?}"));
|
||||
let on_cpu = photocraft_compose::render(&preview, b).into_px();
|
||||
let d = max_diff(&on_gpu, &on_cpu, skip);
|
||||
assert!(d <= tol_gpu, "{what}: GPU vs CPU {:.2}/255", d * 255.0);
|
||||
let mut s = photocraft_engine::Session::new();
|
||||
s.add_document(doc.clone(), None);
|
||||
s.select_layer(target).unwrap();
|
||||
s.execute(&format!("image.adjustments.{kind}"), params.clone()).unwrap();
|
||||
let cmd = photocraft_compose::render(&s.active().unwrap().doc, b).into_px();
|
||||
let d = max_diff(&on_gpu, &cmd, skip);
|
||||
worst = worst.max(d);
|
||||
assert!(d <= tol_cmd, "{what}: GPU preview vs command {:.2}/255", d * 255.0);
|
||||
// Each kind runs once per mode at one (depth, selection) pair, rather than kind x depth x selection: this test's
|
||||
// own case is the isolating group, which `base_document` builds before it knows the kind (`with_settings` only
|
||||
// swaps the preview layer's adjustment), and the GPU planner applies a clipped adjustment through the same
|
||||
// `atop_any` / `adjust` passes whatever the group around it (`crates/gpu/src/plan/planner.rs`). The kind x depth x
|
||||
// selection x mode matrix of those passes is `preview_layer_composites_on_the_gpu_like_the_command`. Cycling the
|
||||
// pairs over the kinds still runs every depth with and without a selection in both modes (in Grayscale among the
|
||||
// kinds that keep gray, too).
|
||||
const PAIRS: [(SampleType, bool); 6] =
|
||||
[(SampleType::U8, false), (SampleType::U16, true), (SampleType::F32, false), (SampleType::U8, true), (SampleType::U16, false), (SampleType::F32, true)];
|
||||
for (mode, offset) in [(ColorMode::Rgb, 0), (ColorMode::Grayscale, 3)] {
|
||||
for (i, kind) in photocraft_ui_egui::adjust_editors::KINDS.into_iter().enumerate() {
|
||||
let (depth, selection) = PAIRS[(i + offset) % PAIRS.len()];
|
||||
let (doc, target) = clipped_document(mode, depth, selection);
|
||||
let params = sample(kind);
|
||||
let preview = match preview_document(&doc, target, kind, ¶ms) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
// Only grayscale kinds that make colour keep the CPU proxy preview.
|
||||
assert_eq!(mode, ColorMode::Grayscale, "{kind}: {e}");
|
||||
assert!(GRAY_COLOUR.contains(&kind), "{kind} {mode:?}: unexpected preview error: {e}");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
};
|
||||
assert!(preview.layer(PREVIEW_LAYER).is_some());
|
||||
assert!(preview.layer(target).unwrap().is_group(), "the clipped target is isolated");
|
||||
let what = format!("{kind} {mode:?} {depth:?} selection {selection}");
|
||||
let b = preview.bounds();
|
||||
let skip = if matches!(kind, "threshold" | "posterize") && depth != SampleType::U8 { (b.width() * b.height()) as usize / 100 } else { 0 };
|
||||
let on_gpu = render_to_vec(&mut comp, &device, &queue, &preview, b).unwrap_or_else(|e| panic!("{what}: {e:?}"));
|
||||
let on_cpu = photocraft_compose::render(&preview, b).into_px();
|
||||
let d = max_diff(&on_gpu, &on_cpu, skip);
|
||||
assert!(d <= tol_gpu, "{what}: GPU vs CPU {:.2}/255", d * 255.0);
|
||||
let mut s = photocraft_engine::Session::new();
|
||||
s.add_document(doc.clone(), None);
|
||||
s.select_layer(target).unwrap();
|
||||
s.execute(&format!("image.adjustments.{kind}"), params.clone()).unwrap();
|
||||
let cmd = photocraft_compose::render(&s.active().unwrap().doc, b).into_px();
|
||||
let d = max_diff(&on_gpu, &cmd, skip);
|
||||
worst = worst.max(d);
|
||||
assert!(d <= tol_cmd, "{what}: GPU preview vs command {:.2}/255", d * 255.0);
|
||||
}
|
||||
}
|
||||
eprintln!("worst clipped-target GPU preview vs command: {:.3}/255", worst * 255.0);
|
||||
|
||||
@@ -108,12 +108,13 @@ fn size_changing_rotation_preview_is_visible_and_preserves_the_panned_center() {
|
||||
let _gpu = photocraft_testkit::gpu_lock();
|
||||
let Some(mut h) = harness() else { return };
|
||||
h.run_steps(4);
|
||||
for (width, height, zoom, center, degrees, factor) in [
|
||||
(400, 240, 1.0, [160.0, 90.0], 45.0, 1),
|
||||
(400, 240, 1.0, [160.0, 90.0], -45.0, 1),
|
||||
(400, 240, 1.0, [160.0, 90.0], 90.0, 1),
|
||||
(3000, 1800, 0.12, [1350.0, 825.0], 45.0, 2),
|
||||
] {
|
||||
// The canvas places a size-changing preview by its size alone (`canvas/gpu_picture.rs`: `growth` and
|
||||
// `preview_bounds` from `preview_size`): 45° grows both sides, 90° grows one and shrinks the other, and the large
|
||||
// document runs the reduced proxy. -45° gives 45°'s size, so it repeated the same placement; the direction of
|
||||
// the rotation itself is the engine's (its `image.rotation.arbitrary` tests with `"direction": "ccw"`).
|
||||
for (width, height, zoom, center, degrees, factor) in
|
||||
[(400, 240, 1.0, [160.0, 90.0], 45.0, 1), (400, 240, 1.0, [160.0, 90.0], 90.0, 1), (3000, 1800, 0.12, [1350.0, 825.0], 45.0, 2)]
|
||||
{
|
||||
setup(&mut h, width, height, zoom, center);
|
||||
assert_eq!(photocraft_ui_egui::proxy::factor(&h.state().session.active().unwrap().doc), factor);
|
||||
let id = open(&mut h);
|
||||
|
||||
@@ -289,15 +289,31 @@ fn pixel_grid_does_not_flip_colour_across_mid_tones() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The depths [`pixel_grid_is_solid_and_visible_at_scale`] runs at. Both canvases draw the grid with the same
|
||||
/// `PixelGrid` over a CPU composite (`PhotoComposite`: compose's f32 render, `canvas/raster_source.rs` `read`; see
|
||||
/// `grid_prep` and "The grid is drawn over the picture" in `canvas/document_display.rs`), and the fills 0 and 1 are
|
||||
/// exact at every depth, so the grid reads the same pixels at 8, 16 and 32 bits. Depth reaches only the picture under
|
||||
/// it, which the `inside` assertion reads: on the GPU canvas its texture (`Rgba8Unorm` for 8-bit, `Rgba16Float` for
|
||||
/// 16/32-bit, see `canvas_16f.rs`). So every canvas and scale runs 8-bit, and the GPU canvas adds 16-bit at 1x and
|
||||
/// 32-bit at 2x.
|
||||
fn grid_depths(gpu: bool, ppp: f32) -> Vec<photocraft_color::SampleType> {
|
||||
use photocraft_color::SampleType;
|
||||
match (gpu, ppp > 1.0) {
|
||||
(true, false) => vec![SampleType::U8, SampleType::U16],
|
||||
(true, true) => vec![SampleType::U8, SampleType::F32],
|
||||
(false, _) => vec![SampleType::U8],
|
||||
}
|
||||
}
|
||||
|
||||
fn pixel_grid_is_solid_and_visible_at_scale(gpu: bool, ppp: f32) {
|
||||
let _gpu = photocraft_testkit::gpu_lock();
|
||||
use photocraft_color::{ColorMode, PixelFormat, SampleType};
|
||||
use photocraft_color::{ColorMode, PixelFormat};
|
||||
use photocraft_doc::{Document, Layer, LayerContent, Size};
|
||||
use photocraft_geom::Rect;
|
||||
use photocraft_raster::Surface;
|
||||
|
||||
let Some(mut h) = harness_with_scale(gpu, ppp) else { return };
|
||||
for depth in [SampleType::U8, SampleType::U16, SampleType::F32] {
|
||||
for depth in grid_depths(gpu, ppp) {
|
||||
for v in [0.0, 1.0] {
|
||||
let mut doc = Document::new("grid contrast", Size::new(32, 16), ColorMode::Rgb, depth);
|
||||
let mut surface = Surface::new(PixelFormat::new(ColorMode::Rgb, depth, true));
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
//!
|
||||
//! They drive the real app offscreen on wgpu with real egui pointer events (press, then a series
|
||||
//! of moves past the click distance), render the frame mid-drag and look at the pixels along the
|
||||
//! preview's edges on white and on black documents. They also check the preview follows every
|
||||
//! preview's edges on a mid-grey document, for both colours of the ants. They also check the preview follows every
|
||||
//! move (each move's frame shows the new outline) and that the animated ants keep frames coming
|
||||
//! while the pointer is held still. Skips when no GPU adapter exists (like `live_stroke_canvas.rs`).
|
||||
|
||||
@@ -169,11 +169,17 @@ fn coverage_along(img: &Image, ppp: f32, pts: &[Pos2], test: impl Fn(u8) -> bool
|
||||
hits as f32 / samples.max(1) as f32
|
||||
}
|
||||
|
||||
/// Ink that contrasts with `background`: dark on white, light on black. The 1 px ants are half
|
||||
/// antialiasing where the curve crosses pixel columns, so a quarter of the luma range suffices.
|
||||
fn ink(background: &str) -> impl Fn(u8) -> bool {
|
||||
let white = background == "white";
|
||||
move |l| if white { l < 192 } else { l > 63 }
|
||||
/// The document the marquee tests drag over: the grey halfway between the ants' two colours (luma 102 and 255 in the
|
||||
/// default theme), so both contrast with it.
|
||||
const GREY: &str = "#b3b3b3";
|
||||
|
||||
/// An ink's name and whether a luma shows it.
|
||||
type Ink = (&'static str, fn(u8) -> bool);
|
||||
|
||||
/// The two inks of the ants over [`GREY`] (luma 179): darker and lighter. The 1 px ants are half antialiasing where
|
||||
/// the curve crosses pixel columns (luma 140 and 217 there), so the thresholds sit just past the grey either way.
|
||||
fn inks() -> [Ink; 2] {
|
||||
[("dark", |l| l < 150), ("light", |l| l > 208)]
|
||||
}
|
||||
|
||||
/// The four edges of the document rectangle `[x0, y0]`–`[x1, y1]` on screen.
|
||||
@@ -186,22 +192,34 @@ fn edges(h: &Harness, a: [f32; 2], b: [f32; 2]) -> [(Pos2, Pos2); 4] {
|
||||
#[test]
|
||||
fn marquee_previews_show_while_dragging_on_white_and_black_at_1x_and_2x() {
|
||||
let _gpu = photocraft_testkit::gpu_lock();
|
||||
for ppp in [1.0, 2.0] {
|
||||
let Some(mut h) = harness(ppp) else { return };
|
||||
// One mid-grey document instead of a white and a black one: the ants are a band of the marquee colour with dashes
|
||||
// of the halo colour, fixed colours that never depend on the pixels under them (the framework's `marching_ants`,
|
||||
// which the marquee tool paints through `ToolContext::marching_ants`). White on white (#253) hid the light ants
|
||||
// and black would hide the dark ones; over grey the test sees both inks at once, so an outline missing either
|
||||
// colour fails here as it failed on one of the two documents. (The name is the one CI's slow-test order lists.)
|
||||
// One harness for both scales: the app derives its scale from the window's native one every frame
|
||||
// (`prefs_ui/appearance.rs` `interface_zoom`), so the 2x pass sets that, as a move to a HiDPI display does.
|
||||
let Some(mut h) = harness(1.0) else { return };
|
||||
h.run_steps(4);
|
||||
for ppp in [1.0f32, 2.0] {
|
||||
if let Some(root) = h.input_mut().viewports.get_mut(&egui::ViewportId::ROOT) {
|
||||
root.native_pixels_per_point = Some(ppp);
|
||||
}
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.ctx.pixels_per_point(), ppp, "the harness runs at {ppp}x");
|
||||
for tool in ["rectMarquee", "ellipseMarquee"] {
|
||||
for bg in ["white", "black"] {
|
||||
setup(&mut h, bg, tool);
|
||||
let (a, b) = ([100.0, 80.0], [300.0, 220.0]);
|
||||
let before = render(&mut h);
|
||||
drag_to(&mut h, a, b);
|
||||
let img = render(&mut h);
|
||||
setup(&mut h, GREY, tool);
|
||||
let (a, b) = ([100.0, 80.0], [300.0, 220.0]);
|
||||
let before = render(&mut h);
|
||||
drag_to(&mut h, a, b);
|
||||
let img = render(&mut h);
|
||||
for (ink, test) in inks() {
|
||||
if tool == "rectMarquee" {
|
||||
for (i, (p, q)) in edges(&h, a, b).into_iter().enumerate() {
|
||||
let was = coverage(&before, ppp, p, q, ink(bg));
|
||||
let now = coverage(&img, ppp, p, q, ink(bg));
|
||||
// Ants: half the dashes contrast with the pixels under them.
|
||||
assert!(was < 0.05 && now > 0.3, "{tool} on {bg} @{ppp}x, edge {i}: {was:.2} → {now:.2} contrasting");
|
||||
let was = coverage(&before, ppp, p, q, test);
|
||||
let now = coverage(&img, ppp, p, q, test);
|
||||
// Ants: half the dashes are each ink.
|
||||
assert!(was < 0.05 && now > 0.3, "{tool} @{ppp}x, edge {i}: {was:.2} → {now:.2} {ink}");
|
||||
}
|
||||
} else {
|
||||
// The ellipse touches its box at the edge midpoints. Walk the curve around
|
||||
@@ -220,21 +238,24 @@ fn marquee_previews_show_while_dragging_on_white_and_black_at_1x_and_2x() {
|
||||
screen(&h, (cx as f64 + rx as f64 * t.cos()) as f32, (cy as f64 + ry as f64 * t.sin()) as f32)
|
||||
})
|
||||
.collect();
|
||||
let now = coverage_along(&img, ppp, &pts, ink(bg));
|
||||
assert!(now > 0.3, "{tool} on {bg} @{ppp}x at ({mx}, {my}): {now:.2} contrasting");
|
||||
let was = coverage_along(&before, ppp, &pts, test);
|
||||
let now = coverage_along(&img, ppp, &pts, test);
|
||||
assert!(was < 0.05 && now > 0.3, "{tool} @{ppp}x at ({mx}, {my}): {was:.2} → {now:.2} {ink}");
|
||||
}
|
||||
}
|
||||
// Each move's frame shows the outline where the pointer is now (no stale frame).
|
||||
pointer_move(&mut h, 340.0, 250.0);
|
||||
let img = render(&mut h);
|
||||
if tool == "rectMarquee" {
|
||||
let [top, right, ..] = edges(&h, a, [340.0, 250.0]);
|
||||
assert!(coverage(&img, ppp, top.0, top.1, ink(bg)) > 0.3, "{tool} {bg} @{ppp}x: top edge follows the pointer");
|
||||
assert!(coverage(&img, ppp, right.0, right.1, ink(bg)) > 0.3, "{tool} {bg} @{ppp}x: right edge follows the pointer");
|
||||
}
|
||||
button(&mut h, 340.0, 250.0, false);
|
||||
h.run_steps(2);
|
||||
}
|
||||
// Each move's frame shows the outline where the pointer is now (no stale frame).
|
||||
pointer_move(&mut h, 340.0, 250.0);
|
||||
let img = render(&mut h);
|
||||
if tool == "rectMarquee" {
|
||||
let [top, right, ..] = edges(&h, a, [340.0, 250.0]);
|
||||
for (ink, test) in inks() {
|
||||
assert!(coverage(&img, ppp, top.0, top.1, test) > 0.3, "{tool} @{ppp}x: top edge follows the pointer ({ink})");
|
||||
assert!(coverage(&img, ppp, right.0, right.1, test) > 0.3, "{tool} @{ppp}x: right edge follows the pointer ({ink})");
|
||||
}
|
||||
}
|
||||
button(&mut h, 340.0, 250.0, false);
|
||||
h.run_steps(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,15 @@ type Pixels = Vec<[u8; 4]>;
|
||||
fn raw_pointer_brush_and_mixer_pixels_appear_in_the_input_frame() {
|
||||
use photocraft_ui_egui::state::Tool;
|
||||
let _gpu = photocraft_testkit::gpu_lock();
|
||||
// One harness for every case: each case closes what the last one left open and sets its own tool, view flip,
|
||||
// brush and colours, so a fresh harness per case only repeated the wgpu setup.
|
||||
let Some(mut h) = harness() else { return };
|
||||
for flip in [false, true] {
|
||||
for tool in [Tool::Brush, Tool::MixerBrush] {
|
||||
let Some(mut h) = harness() else { return };
|
||||
let app = h.state_mut();
|
||||
while app.session.active().is_some() {
|
||||
app.run("file.close", json!({"discard": true})).unwrap();
|
||||
}
|
||||
app.run("file.new", json!({"width":300,"height":200,"background":"white"})).unwrap();
|
||||
app.run("edit.fill", json!({"color":"#2040df"})).unwrap();
|
||||
app.run("tools.setColors", json!({"foreground":"#ef2000"})).unwrap();
|
||||
@@ -202,11 +207,14 @@ fn the_canvas_shows_the_committed_stroke_part(part: usize) {
|
||||
let _gpu = photocraft_testkit::gpu_lock();
|
||||
let Some(mut h) = harness() else { return };
|
||||
h.run_steps(4);
|
||||
// Every zoom once, with every smoothing amount among them, rather than zoom x smoothing: the canvas branches on
|
||||
// the zoom (reduced, 1:1 and magnified pictures) and only on whether smoothing is on (a held pointer repeats its
|
||||
// point while smoothing catches up, `canvas/strokes.rs`); that the live stroke equals the commit at
|
||||
// every zoom and smoothing amount is the engine's `live_stroke_equals_the_commit_at_every_zoom_with_smoothing`
|
||||
// (`brush_cmds/tests.rs`). The zoom 4, smoothing 0.1 case is the base the cases after it change one thing of.
|
||||
let mut cases = Vec::new();
|
||||
for zoom in [0.5, 1.0, 4.0, 12.0] {
|
||||
for smoothing in [0.0, 0.1, 0.5] {
|
||||
cases.push(Case { zoom, smoothing, hardness: 0.0, depth: 8, pressure: false, flip: false });
|
||||
}
|
||||
for (zoom, smoothing) in [(0.5, 0.5), (1.0, 0.0), (4.0, 0.1), (12.0, 0.0)] {
|
||||
cases.push(Case { zoom, smoothing, hardness: 0.0, depth: 8, pressure: false, flip: false });
|
||||
}
|
||||
cases.push(Case { zoom: 4.0, smoothing: 0.1, hardness: 1.0, depth: 8, pressure: false, flip: false });
|
||||
cases.push(Case { zoom: 4.0, smoothing: 0.1, hardness: 0.0, depth: 16, pressure: false, flip: false });
|
||||
@@ -214,7 +222,8 @@ fn the_canvas_shows_the_committed_stroke_part(part: usize) {
|
||||
cases.push(Case { zoom: 4.0, smoothing: 0.1, hardness: 0.0, depth: 8, pressure: false, flip: true });
|
||||
cases.push(Case { zoom: 12.0, smoothing: 0.5, hardness: 0.0, depth: 16, pressure: true, flip: true });
|
||||
let mut gpu_seen = false;
|
||||
for c in cases.into_iter().skip(part).step_by(4) {
|
||||
// One step per `_part_N` test, so every case runs in exactly one of them.
|
||||
for c in cases.into_iter().skip(part).step_by(3) {
|
||||
let (before, drawing, done, gpu) = frames(&mut h, c);
|
||||
gpu_seen |= gpu;
|
||||
// The stroke is on screen while drawing (not a blank canvas compared with a blank one)…
|
||||
@@ -248,60 +257,67 @@ fn the_canvas_shows_the_committed_stroke_part_2() {
|
||||
fn live_tool_camera_navigation_is_visible_in_the_input_frame() {
|
||||
use photocraft_ui_egui::state::Tool;
|
||||
let _gpu = photocraft_testkit::gpu_lock();
|
||||
// Brush only: no stroke is drawn, and the canvas has no branch on the live tool before a press. Since the canvas
|
||||
// moved onto the framework it always runs the tools, then shows the picture with the camera of this pass
|
||||
// (`canvas/document_display.rs` `show`: "The tools run after the controls … and before the picture"); the Mixer
|
||||
// Brush's own paths (`canvas/paint_tool.rs`, `canvas/strokes.rs`) start at a press, which
|
||||
// `raw_pointer_brush_and_mixer_pixels_appear_in_the_input_frame` covers. The flip (CPU or GPU picture) and the
|
||||
// input (pinch zoom or wheel pan) do reach different code, so they stay, on one harness.
|
||||
let tool = Tool::Brush;
|
||||
let Some(mut h) = harness() else { return };
|
||||
for flip in [false, true] {
|
||||
for tool in [Tool::Brush, Tool::MixerBrush] {
|
||||
for zoom in [false, true] {
|
||||
let Some(mut h) = harness() else { return };
|
||||
let app = h.state_mut();
|
||||
app.run("file.new", json!({"width":300,"height":200,"background":"white"})).unwrap();
|
||||
app.run("paint.stroke", json!({"points":[[40,40],[240,160]],"size":30,"hardness":1.0,"color":"#2050df"})).unwrap();
|
||||
app.run("prefs.set", json!({"values":{"tools.overscroll":true,"general.animatedZoom":false,"general.zoomWithScrollWheel":false}})).unwrap();
|
||||
app.ui.tool = tool;
|
||||
app.ui.view.flip_horizontal = flip;
|
||||
app.sync_views();
|
||||
h.run_steps(4);
|
||||
control(&mut h, "ui.set", json!({"zoom":1.0,"center":[150,100]}));
|
||||
let at = h.state().last_canvas_rect.center() + egui::vec2(30.0, 10.0);
|
||||
h.hover_at(at);
|
||||
h.run_steps(2);
|
||||
let before = h.state().ui.views[0].clone();
|
||||
h.input_mut().events.push(if zoom {
|
||||
egui::Event::Zoom(1.25)
|
||||
} else {
|
||||
egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: egui::vec2(30.0, 20.0),
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
phase: egui::TouchPhase::Move,
|
||||
source: egui::MouseWheelSource::Unknown,
|
||||
}
|
||||
});
|
||||
h.step();
|
||||
let moved = h.state().ui.views[0].clone();
|
||||
assert!(if zoom { moved.zoom != before.zoom } else { moved.center != before.center }, "navigation was applied");
|
||||
let immediate = h.render().unwrap();
|
||||
let rect = h.state().last_canvas_rect.shrink(8.0);
|
||||
h.step();
|
||||
let settled = h.render().unwrap();
|
||||
if tool == Tool::MixerBrush
|
||||
&& flip
|
||||
&& zoom
|
||||
&& let Ok(path) = std::env::var("PHOTOCRAFT_NAV_SNAPSHOT")
|
||||
{
|
||||
settled.save(path).unwrap();
|
||||
}
|
||||
assert_eq!(h.state().ui.views[0].zoom, moved.zoom);
|
||||
assert_eq!(h.state().ui.views[0].center, moved.center);
|
||||
let mut diff = 0;
|
||||
for y in rect.top() as u32..rect.bottom() as u32 {
|
||||
for x in rect.left() as u32..rect.right() as u32 {
|
||||
for (a, b) in immediate.get_pixel(x, y).0.into_iter().zip(settled.get_pixel(x, y).0) {
|
||||
diff = diff.max(a.abs_diff(b));
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(diff <= 1, "{tool:?} flip={flip} zoom={zoom}: canvas changes {diff}/255 one frame after navigation");
|
||||
for zoom in [false, true] {
|
||||
let app = h.state_mut();
|
||||
while app.session.active().is_some() {
|
||||
app.run("file.close", json!({"discard": true})).unwrap();
|
||||
}
|
||||
app.run("file.new", json!({"width":300,"height":200,"background":"white"})).unwrap();
|
||||
app.run("paint.stroke", json!({"points":[[40,40],[240,160]],"size":30,"hardness":1.0,"color":"#2050df"})).unwrap();
|
||||
app.run("prefs.set", json!({"values":{"tools.overscroll":true,"general.animatedZoom":false,"general.zoomWithScrollWheel":false}})).unwrap();
|
||||
app.ui.tool = tool;
|
||||
app.ui.view.flip_horizontal = flip;
|
||||
app.sync_views();
|
||||
h.run_steps(4);
|
||||
control(&mut h, "ui.set", json!({"zoom":1.0,"center":[150,100]}));
|
||||
let at = h.state().last_canvas_rect.center() + egui::vec2(30.0, 10.0);
|
||||
h.hover_at(at);
|
||||
h.run_steps(2);
|
||||
let before = h.state().ui.views[0].clone();
|
||||
h.input_mut().events.push(if zoom {
|
||||
egui::Event::Zoom(1.25)
|
||||
} else {
|
||||
egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: egui::vec2(30.0, 20.0),
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
phase: egui::TouchPhase::Move,
|
||||
source: egui::MouseWheelSource::Unknown,
|
||||
}
|
||||
});
|
||||
h.step();
|
||||
let moved = h.state().ui.views[0].clone();
|
||||
assert!(if zoom { moved.zoom != before.zoom } else { moved.center != before.center }, "navigation was applied");
|
||||
let immediate = h.render().unwrap();
|
||||
let rect = h.state().last_canvas_rect.shrink(8.0);
|
||||
h.step();
|
||||
let settled = h.render().unwrap();
|
||||
if flip
|
||||
&& zoom
|
||||
&& let Ok(path) = std::env::var("PHOTOCRAFT_NAV_SNAPSHOT")
|
||||
{
|
||||
settled.save(path).unwrap();
|
||||
}
|
||||
assert_eq!(h.state().ui.views[0].zoom, moved.zoom);
|
||||
assert_eq!(h.state().ui.views[0].center, moved.center);
|
||||
let mut diff = 0;
|
||||
for y in rect.top() as u32..rect.bottom() as u32 {
|
||||
for x in rect.left() as u32..rect.right() as u32 {
|
||||
for (a, b) in immediate.get_pixel(x, y).0.into_iter().zip(settled.get_pixel(x, y).0) {
|
||||
diff = diff.max(a.abs_diff(b));
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(diff <= 1, "{tool:?} flip={flip} zoom={zoom}: canvas changes {diff}/255 one frame after navigation");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user