fix(psd): align local warp bounds with shared numeric contract

This commit is contained in:
FredApps committed 2026-11-18 09:36:47 +01:00
1 parent 7bb70c73d8
commit cb3f66e06c
4 files changed
+30 -3

No files matched your search

Generated
+1 -1
View File
@@ -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",
+1 -1
View File
@@ -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" }
+7 -1
View File
@@ -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" {
+21
View File
@@ -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:?}");
}
}
}
}