Ejemplo n.º 1
0
 def testConstruction(self):
     i = Interval1d(1)
     self.assertEqual(i.getA(), i.getB())
     self.assertEqual(i.getA(), 1)
     i = Interval1d(1, 2)
     self.assertEqual(i, Interval1d(1, 2))
     self.assertTrue(Interval1d.empty().isEmpty())
Ejemplo n.º 2
0
 def testExpandingAndClipping(self):
     a = Interval1d(1, 2)
     b = (a.expandedTo(3).expandedTo(Interval1d(2, 4)).clippedTo(
         Interval1d(0, 2)).clippedTo(1))
     a.expandTo(3).expandTo(Interval1d(2, 4))
     a.clipTo(Interval1d(0, 2)).clipTo(1)
     self.assertEqual(a, b)
     self.assertEqual(a, 1)
Ejemplo n.º 3
0
 def testConstruction(self):
     i = Interval1d(1)
     self.assertEqual(i.getA(), i.getB())
     self.assertEqual(i.getA(), 1)
     i = Interval1d(1, 2)
     self.assertEqual(i, Interval1d(1, 2))
     self.assertTrue(Interval1d.empty().isEmpty())
Ejemplo n.º 4
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)
Ejemplo n.º 5
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())
Ejemplo n.º 6
0
 def testRelationships(self):
     i02 = Interval1d(0, 2)
     i13 = Interval1d(1, 3)
     i46 = Interval1d(4, 6)
     i06 = Interval1d(0, 6)
     self.assertTrue(i02.contains(1))
     self.assertTrue(i02.contains(Interval1d(0.5, 1.5)))
     self.assertTrue(i02.isDisjointFrom(3))
     self.assertTrue(i02.isDisjointFrom(i46))
     self.assertTrue(i02.intersects(1))
     self.assertTrue(i02.intersects(i13))
     self.assertTrue(Interval1d(1, 1).isWithin(i02))
     self.assertTrue(i02.isWithin(i06))
     r = i02.relate(1)
     self.assertEqual(r, CONTAINS)
     r = i46.relate(i02)
     self.assertEqual(r, DISJOINT)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
 def testPickle(self):
     a = Interval1d(1.5, 3.5)
     b = pickle.loads(pickle.dumps(a))
     self.assertEqual(a, b)
Ejemplo n.º 9
0
 def testString(self):
     i = Interval1d(1, 2)
     self.assertEqual(str(i), '[1.0, 2.0]')
     self.assertEqual(repr(i), 'Interval1d(1.0, 2.0)')
     self.assertEqual(i, eval(repr(i), dict(Interval1d=Interval1d)))
Ejemplo n.º 10
0
 def testDilationAndErosion(self):
     a = Interval1d(1, 3)
     b = a.dilatedBy(1).erodedBy(2)
     a.dilateBy(1).erodeBy(2)
     self.assertEqual(a, b)
     self.assertEqual(a, 2)
Ejemplo n.º 11
0
 def testCenterAndSize(self):
     i = Interval1d(1, 2)
     self.assertEqual(i.getSize(), 1)
     self.assertEqual(i.getCenter(), 1.5)
Ejemplo n.º 12
0
 def testComparisonOperators(self):
     self.assertEqual(Interval1d(1), Interval1d(1, 1))
     self.assertEqual(Interval1d(1), 1)
     self.assertNotEqual(Interval1d(1, 1), Interval1d(2, 2))
     self.assertNotEqual(Interval1d(2, 2), 1)