Creating an empty box with Box(plane, BoundingBox.Empty)

Hi!

I found a weird behavior in rhinocommon api. It might be a bug or just me being fooled by expecting something different.

I want to create an oriented empty box to union with points and grow.

from Rhino.Geometry import Box, BoundingBox, Plane


box = Box(Plane.WorldXY, BoundingBox.Empty)
print box.X.Length, box.IsValid

box.Union(Plane.WorldXY.Origin)
print box.X.Length, box.IsValid

Result is:

-2.0 False
2.0 True

The box should just contain one point, so it should degenerate to just that point and have zero length in all intervals. Or Not?

Any feedback?
Thanks.
Gianluca

1 Like

Hey Gianluca!

I’m digging through the source code to find out more about this.

For now, here is a solution that returns
0.0 True
0.0 True

from Rhino.Geometry import Box, BoundingBox, Plane, Interval

box = Box(Plane.WorldXY, Interval(0,0),Interval(0,0),Interval(0,0))
print (box.X.Length, box.IsValid)

box.Union(Plane.WorldXY.Origin)
print (box.X.Length, box.IsValid)

In RhinoCommon an empty bounding box is this.
new BoundingBox(1, 0, 0, -1, 0, 0);
A box that has a width of -2.

If you use box.Union(Point3d.Unset) you’ll notice the width becomes 2 because when using Union RhinoCommon attempts to make the BoundingBox Valid, which swaps the values.

This script illustrates what happens

from Rhino.Geometry import Box, BoundingBox, Plane, Point3d

box = Box(Plane.WorldXY, BoundingBox.Empty)
print (box.X, box.IsValid)

box.Union(Point3d.Unset)
print (box.X, box.IsValid)

And the output

1,-1 False
-1,1 True

Ciao old pal!

Thanks for the explanation, I’ve already used the intervals in the code to get an empty box as you showed. However I think the behavior of the constructor that takes the BoundingBox.Empty might be misleading.

Thanks for the quick answer!

1 Like

Ciao :slight_smile:

I’m asking internally about this, I think the way Box does Union is incorrect tbh. The proper solution might be to create your own Union method for now.

I’ve filed a bug so we can look into it
https://mcneel.myjetbrains.com/youtrack/issue/RH-85631/Box.Union-behaves-incorrectly

1 Like