PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(compose): scale artboard bounds in proxy documents (#131)
MikeeIad7046bf9935
diff --git a/crates/compose/src/proxy.rs b/crates/compose/src/proxy.rsindex 04c385f21..95d9471da 100644--- a/crates/compose/src/proxy.rs+++ b/crates/compose/src/proxy.rs@@ -42,6 +42,15 @@ fn shrink_layer(l: &mut Layer, k: u32) {match &mut l.content {LayerContent::Raster(s) => *s = downsample(s, k),LayerContent::Group(g) => {+ if let Some(ab) = &mut g.artboard {+ let divisor = i64::from(k);+ // Pixel x samples source x*k: both half-open edges round up, including negatives.+ let edge = |v: i32| {+ let v = i64::from(v);+ (v.div_euclid(divisor) + i64::from(v.rem_euclid(divisor) != 0)) as i32+ };+ ab.rect = Rect::new(edge(ab.rect.x0), edge(ab.rect.y0), edge(ab.rect.x1), edge(ab.rect.y1));+ }for c in &mut g.children {shrink_layer(c, k);}diff --git a/crates/compose/tests/artboard.rs b/crates/compose/tests/artboard.rsindex c0904039f..416236ad0 100644--- a/crates/compose/tests/artboard.rs+++ b/crates/compose/tests/artboard.rs@@ -44,6 +44,17 @@ fn contents_are_clipped_and_background_painted() {assert_eq!(render_tiled(&d, d.bounds(), 7).px, buf.px);}}++ // Proxy pixel (x,y) samples (4*x,4*y); unaligned half-open artboard edges must agree.+ let original = artboard_doc(SampleType::F32, ArtboardBackground::White, BlendMode::PassThrough);+ let source = render(&original, original.bounds());+ let proxy = photocraft_compose::proxy::proxy_document(&original, 4);+ let reduced = render(&proxy, proxy.bounds());+ for y in 0..proxy.size.height as i32 {+ for x in 0..proxy.size.width as i32 {+ assert!(close(reduced.get(x, y), source.get(4 * x, 4 * y)), "proxy artboard differs at ({x}, {y})");+ }+ }}#[test]