Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def max(self):
"""Return the max corner as a vector."""
return Vec3d(self._max)
def testExpand(self):
b1 = Box(Vec3d(1,1,1),[2,2,2])
b1.expand_by(1)
self.assertTrue(b1 == Box((0,0,0),(3,3,3)))
b1.expand_by((-1,0,0))
self.assertTrue(b1 == Box((1,0,0),(2,3,3)))
def __init__(self, v1_or_box, v2=None):
"""Initialize a box from another box or two vectors."""
if v2 == None:
self.set_coords(v1_or_box.min(), v1_or_box.max())
else:
self.set_coords(Vec3d(v1_or_box), Vec3d(v2))
def centered_box(c, s):
"""Return a box of size s centered on c."""
center = Vec3d(c)
size = Vec3d(s)
half = size/2
assert size.x >= 0 and size.y >= 0 and size.z >= 0
v1 = center - half
v2 = v1 + size
return Box(v1,v2)
def _set_offset(self, offset):
"""
Set an offset from origin.
"""
self._offset = Vec3d(offset)
# update bounding box & range
self._set_bounding_box()
self._set_range()
def testMerge(self):
b1 = Box(Vec3d(1,1,1),[2,2,2])
b2 = Box(Vec3d(3,3,3),[2,2,2])
b3 = b1.merge(b2)
self.assertTrue(b3 == Box((1,1,1),(3,3,3)))
b4 = b3.merge(Box((0,0,0),(-1,-1,-1)))
self.assertTrue(b4 == Box((-1,-1,-1),(3,3,3)))
def testContains(self):
b = Box(Vec3d(1,1,1),[3,3,3])
self.assertTrue(b.contains(b.min()))
self.assertTrue(not b.contains(b.max()))
self.assertTrue(b.contains((2,2,2)))
self.assertTrue(not b.contains((-2,-2,-2)))
def contains(self, v):
"""Return true if a point is inside the box."""
(x,y,z) = Vec3d(v)
return (self._min.x <= x < self._max.x and
self._min.y <= y < self._max.y and
self._min.z <= z < self._max.z)
def testCreationAndAccess(self):
b = Box((1,1,1),[2,2,2])
self.assertTrue(b.min() == Vec3d(1,1,1))
self.assertTrue(b.max() == Vec3d(2,2,2))
self.assertTrue(b.size() == Vec3d(1,1,1))
b = Box((1,0,1),[0,1,0])
self.assertTrue(b.min() == Vec3d(0,0,0))
self.assertTrue(b.max() == Vec3d(1,1,1))
self.assertTrue(b.size() == Vec3d(1,1,1))
b1 = Box(b)
self.assertTrue(b1.min() == Vec3d(0,0,0))
self.assertTrue(b1.max() == Vec3d(1,1,1))
self.assertTrue(b1.size() == Vec3d(1,1,1))