Skip to content

Commit e35f9dc

Browse files
committed
Don't include empty boxes in their union.
The new behaviour matches what Rect does.
1 parent f271116 commit e35f9dc

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/box2d.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,18 @@ where
213213
}
214214
}
215215

216+
/// Computes the union of two boxes.
217+
///
218+
/// If either of the boxes is empty, the other one is returned.
216219
#[inline]
217220
pub fn union(&self, other: &Self) -> Self {
221+
if other.is_empty() {
222+
return *self;
223+
}
224+
if self.is_empty() {
225+
return *other;
226+
}
227+
218228
Box2D {
219229
min: point2(min(self.min.x, other.min.x), min(self.min.y, other.min.y)),
220230
max: point2(max(self.max.x, other.max.x), max(self.max.y, other.max.y)),

src/box3d.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,18 @@ where
183183
Box3D::new(intersection_min, intersection_max)
184184
}
185185

186-
/// Returns the smallest box containing both of the provided boxes.
186+
/// Computes the union of two boxes.
187+
///
188+
/// If either of the boxes is empty, the other one is returned.
187189
#[inline]
188190
pub fn union(&self, other: &Self) -> Self {
191+
if other.is_empty() {
192+
return *self;
193+
}
194+
if self.is_empty() {
195+
return *other;
196+
}
197+
189198
Box3D::new(
190199
Point3D::new(
191200
min(self.min.x, other.min.x),

src/rect.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,6 @@ where
368368
{
369369
#[inline]
370370
pub fn union(&self, other: &Self) -> Self {
371-
if self.size == Zero::zero() {
372-
return *other;
373-
}
374-
if other.size == Zero::zero() {
375-
return *self;
376-
}
377-
378371
self.to_box2d().union(&other.to_box2d()).to_rect()
379372
}
380373
}

0 commit comments

Comments
 (0)