Skip to content

Commit 62c7f88

Browse files
0HyperCubeKeavon
andauthored
Fix incorrectly calculating nonzero-area bounding boxes for empty raster images (#2772)
No bounding box for empty rasters Co-authored-by: Keavon Chambers <keavon@keavon.com>
1 parent 357e770 commit 62c7f88

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

node-graph/gcore/src/raster_types.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ impl Raster<CPU> {
5757
let RasterStorage::Cpu(cpu) = self.data else { unreachable!() };
5858
cpu
5959
}
60+
pub fn is_empty(&self) -> bool {
61+
let data = self.data();
62+
data.height == 0 || data.width == 0
63+
}
6064
}
6165
impl Default for Raster<CPU> {
6266
fn default() -> Self {
@@ -93,6 +97,10 @@ impl Raster<GPU> {
9397
let RasterStorage::Gpu(gpu) = &self.data else { unreachable!() };
9498
gpu.clone()
9599
}
100+
pub fn is_empty(&self) -> bool {
101+
let data = self.data();
102+
data.width() == 0 || data.height() == 0
103+
}
96104
}
97105
#[cfg(feature = "wgpu")]
98106
impl Deref for Raster<GPU> {
@@ -104,9 +112,23 @@ impl Deref for Raster<GPU> {
104112
}
105113
pub type RasterDataTable<Storage> = Instances<Raster<Storage>>;
106114

107-
impl<S: Storage> BoundingBox for RasterDataTable<S> {
115+
// TODO: Make this not dupliated
116+
impl BoundingBox for RasterDataTable<CPU> {
117+
fn bounding_box(&self, transform: DAffine2, _include_stroke: bool) -> Option<[DVec2; 2]> {
118+
self.instance_ref_iter()
119+
.filter(|instance| !instance.instance.is_empty()) // Eliminate empty images
120+
.flat_map(|instance| {
121+
let transform = transform * *instance.transform;
122+
(transform.matrix2.determinant() != 0.).then(|| (transform * Quad::from_box([DVec2::ZERO, DVec2::ONE])).bounding_box())
123+
})
124+
.reduce(Quad::combine_bounds)
125+
}
126+
}
127+
128+
impl BoundingBox for RasterDataTable<GPU> {
108129
fn bounding_box(&self, transform: DAffine2, _include_stroke: bool) -> Option<[DVec2; 2]> {
109130
self.instance_ref_iter()
131+
.filter(|instance| !instance.instance.is_empty()) // Eliminate empty images
110132
.flat_map(|instance| {
111133
let transform = transform * *instance.transform;
112134
(transform.matrix2.determinant() != 0.).then(|| (transform * Quad::from_box([DVec2::ZERO, DVec2::ONE])).bounding_box())

0 commit comments

Comments
 (0)