Exemple #1
0
 def test_construction(self):
     a = Box3d(Vector3d(0, 0, 0))
     b = Box3d(a)
     self.assertEqual(a, b)
     self.assertNotEqual(id(a), id(b))
     a = Box3d(Vector3d(1, 2, 3), Vector3d(3, 4, 5))
     b = Box3d(Interval1d(1, 3), Interval1d(2, 4), Interval1d(3, 5))
     c = Box3d(Vector3d(2, 3, 4), 1, 1, 1)
     self.assertEqual(a, b)
     self.assertEqual(b, c)
     i = Interval1d(1, 2)
     self.assertEqual(i, Interval1d(1, 2))
     self.assertTrue(Interval1d.empty().isEmpty())
Exemple #2
0
 def test_expanding_and_clipping(self):
     a = Box3d(Vector3d(1, 1, 1), Vector3d(2, 2, 2))
     b = (a.expandedTo(Vector3d(3, 3, 3)).expandedTo(
         Box3d(Vector3d(3, 3, 3), 1, 1,
               1)).clippedTo(Box3d(Vector3d(1, 1, 1), 1, 1,
                                   1)).clippedTo(Vector3d(1, 1, 1)))
     a.expandTo(Vector3d(3, 3, 3))
     a.expandTo(Box3d(Vector3d(3, 3, 3), 1, 1, 1))
     a.clipTo(Box3d(Vector3d(1, 1, 1), 1, 1, 1))
     a.clipTo(Vector3d(1, 1, 1))
     self.assertEqual(a, b)
     self.assertEqual(a, Vector3d(1, 1, 1))
     a.clipTo(Vector3d(0, 0, 0))
     self.assertTrue(a.isEmpty())
Exemple #3
0
 def test_comparison_operators(self):
     self.assertEqual(Box3d(Vector3d(1, 1, 1)), Vector3d(1, 1, 1))
     self.assertEqual(Box3d(Vector3d(1, 1, 1)),
                      Box3d(Vector3d(1, 1, 1), Vector3d(1, 1, 1)))
     self.assertEqual(Box3d(Vector3d(0, 0, 0), 1, 1, 1),
                      Box3d(Vector3d(-1, -1, -1), Vector3d(1, 1, 1)))
     self.assertNotEqual(Box3d(Vector3d(0, 0, 0), 1, 1, 1),
                         Box3d(Vector3d(-1, -1, -1), Vector3d(1, 1, 2)))
     self.assertNotEqual(Box3d(Vector3d(0, 0, 0), 1, 1, 1),
                         Vector3d(1, 1, 1))
Exemple #4
0
 def test_string(self):
     b = Box3d(Vector3d(0, 0, 0), 1, 1, 1)
     self.assertEqual(str(b), '[[-1.0, 1.0],\n'
                              ' [-1.0, 1.0],\n'
                              ' [-1.0, 1.0]]')
     self.assertEqual(repr(b), 'Box3d(Interval1d(-1.0, 1.0),\n'
                               '      Interval1d(-1.0, 1.0),\n'
                               '      Interval1d(-1.0, 1.0))')
     self.assertEqual(
         b, eval(repr(b), dict(Box3d=Box3d, Interval1d=Interval1d)))
Exemple #5
0
 def test_center_and_dimensions(self):
     b = Box3d(Vector3d(1.5, 1.5, 1.5), 0.5, 1.0, 1.5)
     self.assertEqual(b[0], b[-3])
     self.assertEqual(b[1], b[-2])
     self.assertEqual(b[2], b[-1])
     self.assertEqual(b[0], b.x())
     self.assertEqual(b[1], b.y())
     self.assertEqual(b[2], b.z())
     with self.assertRaises(IndexError):
         b[-4]
     with self.assertRaises(IndexError):
         b[3]
     self.assertEqual(b.x(), Interval1d(1, 2))
     self.assertEqual(b.y(), Interval1d(0.5, 2.5))
     self.assertEqual(b.z(), Interval1d(0, 3))
     self.assertEqual(b.getCenter(), Vector3d(1.5, 1.5, 1.5))
     self.assertEqual(b.getWidth(), 1)
     self.assertEqual(b.getHeight(), 2)
     self.assertEqual(b.getDepth(), 3)
     self.assertEqual(b.isEmpty(), False)
     self.assertEqual(b.isFull(), False)
Exemple #6
0
 def test_relationships(self):
     b02 = Box3d(Interval1d(0, 2), Interval1d(0, 2), Interval1d(0, 2))
     b13 = Box3d(Interval1d(1, 3), Interval1d(1, 3), Interval1d(1, 3))
     b46 = Box3d(Interval1d(4, 6), Interval1d(4, 6), Interval1d(4, 6))
     b06 = Box3d(Interval1d(0, 6), Interval1d(0, 6), Interval1d(0, 6))
     self.assertTrue(b02.contains(Vector3d(1, 1, 1)))
     self.assertTrue(b02.contains(Box3d(Vector3d(1, 1, 1), 0.5, 0.5, 0.5)))
     self.assertTrue(b02.isDisjointFrom(Vector3d(3, 3, 3)))
     self.assertTrue(b02.isDisjointFrom(b46))
     self.assertTrue(b02.intersects(Vector3d(1, 1, 1)))
     self.assertTrue(b02.intersects(b13))
     self.assertTrue(Box3d(Vector3d(1, 1, 1), 0, 0, 0).isWithin(b02))
     self.assertTrue(b02.isWithin(b06))
     r = b02.relate(Vector3d(1, 1, 1))
     self.assertEqual(r, CONTAINS)
     r = b46.relate(b02)
     self.assertEqual(r, DISJOINT)
Exemple #7
0
 def test_pickle(self):
     a = Box3d(Vector3d(0, 0, 0), 1, 1, 1)
     b = pickle.loads(pickle.dumps(a))
     self.assertEqual(a, b)
Exemple #8
0
 def test_dilation_and_erosion(self):
     a = Box3d(Vector3d(0, 0, 0), 1, 1, 1)
     b = a.dilatedBy(1).erodedBy(2)
     a.dilateBy(1).erodeBy(2)
     self.assertEqual(a, b)
     self.assertEqual(a, Vector3d(0, 0, 0))