From 60a3690908ad60d03411173dda88ad28220ac65b Mon Sep 17 00:00:00 2001 From: hypercube <0hypercube@gmail.com> Date: Sat, 28 Jun 2025 00:45:45 +0100 Subject: [PATCH] No bounding box for empty rasters --- node-graph/gcore/src/raster_types.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/node-graph/gcore/src/raster_types.rs b/node-graph/gcore/src/raster_types.rs index 0c34ba0c5e..4fb1fc4d52 100644 --- a/node-graph/gcore/src/raster_types.rs +++ b/node-graph/gcore/src/raster_types.rs @@ -57,6 +57,10 @@ impl Raster { let RasterStorage::Cpu(cpu) = self.data else { unreachable!() }; cpu } + pub fn is_empty(&self) -> bool { + let data = self.data(); + data.height == 0 || data.width == 0 + } } impl Default for Raster { fn default() -> Self { @@ -93,6 +97,10 @@ impl Raster { let RasterStorage::Gpu(gpu) = &self.data else { unreachable!() }; gpu.clone() } + pub fn is_empty(&self) -> bool { + let data = self.data(); + data.width() == 0 || data.height() == 0 + } } #[cfg(feature = "wgpu")] impl Deref for Raster { @@ -104,9 +112,23 @@ impl Deref for Raster { } pub type RasterDataTable = Instances>; -impl BoundingBox for RasterDataTable { +// TODO: Make this not dupliated +impl BoundingBox for RasterDataTable { + fn bounding_box(&self, transform: DAffine2, _include_stroke: bool) -> Option<[DVec2; 2]> { + self.instance_ref_iter() + .filter(|instance| !instance.instance.is_empty()) // Eliminate empty images + .flat_map(|instance| { + let transform = transform * *instance.transform; + (transform.matrix2.determinant() != 0.).then(|| (transform * Quad::from_box([DVec2::ZERO, DVec2::ONE])).bounding_box()) + }) + .reduce(Quad::combine_bounds) + } +} + +impl BoundingBox for RasterDataTable { fn bounding_box(&self, transform: DAffine2, _include_stroke: bool) -> Option<[DVec2; 2]> { self.instance_ref_iter() + .filter(|instance| !instance.instance.is_empty()) // Eliminate empty images .flat_map(|instance| { let transform = transform * *instance.transform; (transform.matrix2.determinant() != 0.).then(|| (transform * Quad::from_box([DVec2::ZERO, DVec2::ONE])).bounding_box())