コード例 #1
0
 def test_SetPoints(self):
   theSegment = PhactoriSegment()
   theSegment.SetPoints([-1.0, -1.0, -1.0], [0.0, 1.0, 2.0])
   self.assertEqual(theSegment.AtoB[0], 1.0)
   self.assertEqual(theSegment.AtoB[1], 2.0)
   self.assertEqual(theSegment.AtoB[2], 3.0)
   self.assertEqual(theSegment.lengthSquared, 14.0)
   self.assertEqual(theSegment.oneOverLenSqrd, 1.0/14.0)
コード例 #2
0
 def test_FindNearestPointOnSegmentToPoint(self):
   theSegment = PhactoriSegment()
   theSegment.SetPoints([-1.0, -1.0, -1.0], [1.0, 2.0, 3.0])
   testpt1 = theSegment.FindNearestPointOnSegmentToPoint([-10.0, -10.0, -10.0])
   self.assertEqual(testpt1, theSegment.ptA)
   testpt1 = theSegment.FindNearestPointOnSegmentToPoint([10.0, 10.0, 10.0])
   self.assertEqual(testpt1, theSegment.ptB)
   testpt1 = theSegment.FindNearestPointOnSegmentToPoint([0.0, 0.0, 0.0])
   self.assertEqual(testpt1, [-0.3793103448275862, -0.06896551724137923, 0.24137931034482762])
コード例 #3
0
  def test_MyBoundingBoxIntersectsTargetBoundingBox(self):
    theSegment = PhactoriSegment()
    testBoundingBox = [-1.0, 1.0, -1.0, 1.0, -1.0, 1.0]
    theSegment.SetPoints([-3.0, -3.0, -3.0], [-2.0, -2.0, -2.0])
    self.assertFalse(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
    theSegment.SetPoints([-3.0, -3.0, -3.0], [2.0, 2.0, 2.0])
    self.assertTrue(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
    theSegment.SetPoints([-3.0, -3.0, -3.0], [0.0, 0.0, 0.0])
    self.assertTrue(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
    theSegment.SetPoints([0.0, 0.0, 0.0], [3.0, 2.0, 1.0])
    self.assertTrue(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))

    for axesTestIndex in range(0,3):
      tp1 = [0.0, 0.0, 0.0]
      tp2 = [0.0, 0.0, 0.0]
      tp1[axesTestIndex] = -3.0
      tp2[axesTestIndex] = -1.01
      theSegment.SetPoints(tp1, tp2)
      self.assertFalse(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
      theSegment.SetPoints(tp2, tp1)
      self.assertFalse(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
      tp1[axesTestIndex] = 3.0
      tp2[axesTestIndex] = 1.01
      theSegment.SetPoints(tp1, tp2)
      self.assertFalse(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
      theSegment.SetPoints(tp2, tp1)
      self.assertFalse(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
      tp1[axesTestIndex] = -3.0
      tp2[axesTestIndex] = -1.0
      theSegment.SetPoints(tp1, tp2)
      self.assertTrue(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
      theSegment.SetPoints(tp2, tp1)
      self.assertTrue(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
      tp1[axesTestIndex] = 3.0
      tp2[axesTestIndex] = 1.0
      theSegment.SetPoints(tp1, tp2)
      self.assertTrue(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
      theSegment.SetPoints(tp2, tp1)
      self.assertTrue(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
      tp1[axesTestIndex] = -3.0
      tp2[axesTestIndex] = -0.99
      theSegment.SetPoints(tp1, tp2)
      self.assertTrue(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
      theSegment.SetPoints(tp2, tp1)
      self.assertTrue(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
      tp1[axesTestIndex] = 3.0
      tp2[axesTestIndex] = 0.99
      theSegment.SetPoints(tp1, tp2)
      self.assertTrue(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
      theSegment.SetPoints(tp2, tp1)
      self.assertTrue(theSegment.MyBoundingBoxIntersectsTargetBoundingBox(testBoundingBox))
コード例 #4
0
 def test_FindDistanceSquaredToPoint(self):
   theSegment = PhactoriSegment()
   theSegment.SetPoints([-1.0, -1.0, -1.0], [1.0, 2.0, 3.0])
   testDist = theSegment.FindDistanceSquaredToPoint([0.5, 0.6, 0.7])
   self.assertEqual(testDist, 0.3496551724137931)
コード例 #5
0
  def test_IntersectsBoundingBoxProjected(self):
    theSegment = PhactoriSegment()
    testBoundingBox = [-1.0, 1.0, -1.0, 1.0, -1.0, 1.0]
    theSegment.SetPoints([-3.0, -3.0, -3.0], [-2.0, -2.0, -2.0])
    self.assertFalse(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
    theSegment.SetPoints([-2.0, -2.0, -2.0], [2.0, 2.0, 2.0])
    self.assertTrue(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
    theSegment.SetPoints([-3.0, -3.0, -3.0], [2.0, 2.0, 2.0])
    self.assertTrue(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))

    for axesTestIndex in range(0,3):
      tp1 = [-2.0, -2.0, -2.0]
      tp2 = [ 2.0,  2.0,  2.0]
      tp1[axesTestIndex] = 0.0
      tp2[axesTestIndex] = 0.0
      theSegment.SetPoints(tp1, tp2)
      self.assertTrue(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
      theSegment.SetPoints(tp2, tp1)
      self.assertTrue(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
      tp1 = [-1.875, -1.925, -2.125]
      tp2 = [ 2.125,  1.875,  2.5]
      tp1[axesTestIndex] = 0.125
      tp2[axesTestIndex] = -0.125
      theSegment.SetPoints(tp1, tp2)
      self.assertTrue(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
      theSegment.SetPoints(tp2, tp1)
      self.assertTrue(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
      tp1 = [-1.1, -1.1, -1.1]
      tp2 = [1.1, 1.1, 1.1]
      tp2[axesTestIndex] = -0.9
      theSegment.SetPoints(tp2, tp1)
      self.assertTrue(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
      theSegment.SetPoints(tp1, tp2)
      self.assertTrue(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
      tp2[axesTestIndex] = -0.999
      theSegment.SetPoints(tp2, tp1)
      self.assertFalse(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
      theSegment.SetPoints(tp1, tp2)
      self.assertFalse(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
      tp1 = [-1.1, -1.1, -1.1]
      tp2 = [1.1, 1.1, 1.1]
      tp1[axesTestIndex] = 0.9
      theSegment.SetPoints(tp2, tp1)
      self.assertTrue(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
      theSegment.SetPoints(tp1, tp2)
      self.assertTrue(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
      tp1[axesTestIndex] = 0.999
      theSegment.SetPoints(tp2, tp1)
      self.assertFalse(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
      theSegment.SetPoints(tp1, tp2)
      self.assertFalse(theSegment.IntersectsBoundingBoxProjected(testBoundingBox, -1))
コード例 #6
0
  def test_EitherEndpointIsInBoundingBox(self):
    theSegment = PhactoriSegment()
    testBoundingBox = [-1.0, 1.0, -1.0, 1.0, -1.0, 1.0]
    theSegment.SetPoints([-3.0, -3.0, -3.0], [-2.0, -2.0, -2.0])
    self.assertFalse(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
    theSegment.SetPoints([-3.0, -3.0, -3.0], [0.1, 0.1, 0.1])
    self.assertTrue(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
    theSegment.SetPoints([0.1, 0.1, 0.1], [3.0, 3.0, 3.0])
    self.assertTrue(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
    theSegment.SetPoints([0.1, 0.1, 0.1], [-0.1, -0.1, -0.1])
    self.assertTrue(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))

    for axesTestIndex in range(0,3):
      tp1 = [0.0, 0.0, 0.0]
      tp2 = [0.0, 0.0, 0.0]
      tp1[axesTestIndex] = -3.0
      tp2[axesTestIndex] = -1.01
      theSegment.SetPoints(tp1, tp2)
      self.assertFalse(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
      theSegment.SetPoints(tp2, tp1)
      self.assertFalse(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
      tp1[axesTestIndex] = 3.0
      tp2[axesTestIndex] = 1.01
      theSegment.SetPoints(tp1, tp2)
      self.assertFalse(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
      theSegment.SetPoints(tp2, tp1)
      self.assertFalse(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
      tp1[axesTestIndex] = -3.0
      tp2[axesTestIndex] = -1.0
      theSegment.SetPoints(tp1, tp2)
      self.assertTrue(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
      theSegment.SetPoints(tp2, tp1)
      self.assertTrue(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
      tp1[axesTestIndex] = 3.0
      tp2[axesTestIndex] = 1.0
      theSegment.SetPoints(tp1, tp2)
      self.assertTrue(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
      theSegment.SetPoints(tp2, tp1)
      self.assertTrue(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
      tp1[axesTestIndex] = -3.0
      tp2[axesTestIndex] = -0.99
      theSegment.SetPoints(tp1, tp2)
      self.assertTrue(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
      theSegment.SetPoints(tp2, tp1)
      self.assertTrue(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
      tp1[axesTestIndex] = 3.0
      tp2[axesTestIndex] = 0.99
      theSegment.SetPoints(tp1, tp2)
      self.assertTrue(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))
      theSegment.SetPoints(tp2, tp1)
      self.assertTrue(theSegment.EitherEndpointIsInBoundingBox(testBoundingBox))