Bounding Box Contains?

I’m trying to use the contains? method for bounding boxes and I am comparing one bounding box to another. I’m assuming for the boolean to be true that the bounding box you are checking on must be fully inside the other one and not just touching it.

Don’t assume, … test …

# Touching ...
b1 = Geom::BoundingBox.new
#<Geom::BoundingBox:0x0000000a79a888>
b2 = Geom::BoundingBox.new
#<Geom::BoundingBox:0x0000000a799b68>
b1.add([0,0,0],[10,10,10])
#<Geom::BoundingBox:0x0000000a79a888>
b2.add([10,0,0],[20,10,10])
#<Geom::BoundingBox:0x0000000a799b68>
b1.contains?(b2)
# false

# Intersecting ...
b2.add([9,0,0])
#<Geom::BoundingBox:0x0000000a799b68>
b1.contains?(b2)
# false
b1.intersect(b2).empty?
# false
b1.intersect(Geom::BoundingBox.new).empty?
# true

# Totally Within ...
b3 = Geom::BoundingBox.new
#<Geom::BoundingBox:0x0000000a6d5fd8>
b3.add([1,0,0],[9,9,9])
#<Geom::BoundingBox:0x0000000a6d5fd8>
b1.contains?(b3)
# true

# Exactly the same (one is clone of the other) ...
b4 = Geom::BoundingBox.new
#<Geom::BoundingBox:0x0000000a608e98>
b4.add(b1)
#<Geom::BoundingBox:0x0000000a608e98>
b1.contains?(b4)
# true
b4.contains?(b1)
# true
1 Like

Roger that, assuming usually never gets me very far, and I’m usually wrong.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.