From cb3f66e06c1887290e9179f88ab150e446245642 Mon Sep 17 00:00:00 2001 From: FredApps Date: Wed, 18 Nov 2026 09:36:47 +0100 Subject: [PATCH] fix(psd): align local warp bounds with shared numeric contract --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/psd/src/placed.rs | 8 +++++++- crates/psd/src/tests/opt.rs | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7377934ab..377d2308f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1449,7 +1449,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=be556bedcbc3fcd63d3146fd7fcec9bc488fc7ae#be556bedcbc3fcd63d3146fd7fcec9bc488fc7ae" +source = "git+https://github.com/storytold/craft-libs?rev=e9ec4813311264ee1857079c2edd10a70e2389a6#e9ec4813311264ee1857079c2edd10a70e2389a6" dependencies = [ "encoding_rs", "flate2", diff --git a/Cargo.toml b/Cargo.toml index 0c010e3d3..4f064474f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs" craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "808730f49b9637b7909fe2ae56f9d63fdb100cae", default-features = false, features = ["read"] } craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } -craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "be556bedcbc3fcd63d3146fd7fcec9bc488fc7ae" } +craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e9ec4813311264ee1857079c2edd10a70e2389a6" } craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "77686f24fe8665c21369f1b593f4d65a973e2a45" } craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } diff --git a/crates/psd/src/placed.rs b/crates/psd/src/placed.rs index 93ba2755b..7b3f513a8 100644 --- a/crates/psd/src/placed.rs +++ b/crates/psd/src/placed.rs @@ -130,7 +130,13 @@ impl Warp { /// The warp of a content point (content pixels → content pixels). pub fn apply(&self, p: [f64; 2], w: f64, h: f64) -> [f64; 2] { - let [l, t, r, b] = if self.bounds[2] > self.bounds[0] && self.bounds[3] > self.bounds[1] { self.bounds } else { [0.0, 0.0, w, h] }; + // Keep the local mapping facade aligned with the shared bake evaluator. + let valid_bounds = self.bounds.iter().all(|x| x.is_finite()) + && (self.bounds[2] - self.bounds[0]).is_finite() + && self.bounds[2] > self.bounds[0] + && (self.bounds[3] - self.bounds[1]).is_finite() + && self.bounds[3] > self.bounds[1]; + let [l, t, r, b] = if valid_bounds { self.bounds } else { [0.0, 0.0, w, h] }; let (bw, bh) = (r - l, b - t); let (u, v) = ((p[0] - l) / bw, (p[1] - t) / bh); if self.style == "warpCustom" { diff --git a/crates/psd/src/tests/opt.rs b/crates/psd/src/tests/opt.rs index 3f351a7ab..c4fdefcfe 100644 --- a/crates/psd/src/tests/opt.rs +++ b/crates/psd/src/tests/opt.rs @@ -751,3 +751,24 @@ fn shared_placed_layer_adapter_normalizes_before_warp_classification() { assert!(!object.needs_bake()); assert_eq!(object.map([10.0, 5.0], 20.0, 10.0), [10.0, 5.0]); } + +#[test] +fn local_and_shared_warp_mapping_agree_on_overflowing_bounds() { + let mesh: Vec<_> = (0..4).flat_map(|j| (0..4).map(move |i| [i as f64 * 20.0 / 3.0, j as f64 * 10.0 / 3.0])).collect(); + for bounds in [[-f64::MAX, 0.0, f64::MAX, 10.0], [0.0, -f64::MAX, 20.0, f64::MAX]] { + let shared = craft_psd::smart::SmartObject { + uuid: String::new(), + quad: [[0.0, 0.0], [20.0, 0.0], [20.0, 10.0], [0.0, 10.0]], + size: Some([20.0, 10.0]), + warp: Some(craft_psd::smart::Warp { style: "warpCustom".into(), bounds, cols: 1, rows: 1, mesh: mesh.clone(), ..Default::default() }), + }; + let local = crate::placed::from_craft_smart(shared.clone()); + for point in [[5.0, 2.5], [10.0, 5.0], [15.0, 7.5]] { + let actual = local.map(point, 20.0, 10.0); + assert_eq!(actual, shared.map(point, 20.0, 10.0)); + for axis in 0..2 { + assert!((actual[axis] - point[axis]).abs() < 1e-9, "{bounds:?} {point:?}: {actual:?}"); + } + } + } +}