Esempio n. 1
0
    def test_Operators(self):
        l1 = Gf.Line(Gf.Vec3d(0, 0, 0), Gf.Vec3d(1, 1, 1))
        l2 = Gf.Line(Gf.Vec3d(0, 0, 0), Gf.Vec3d(1, 1, 1))
        self.assertEqual(l1, l2, err("equality"))

        l1 = Gf.Line(Gf.Vec3d(0, 0, 0), Gf.Vec3d(1, 2, 3))
        l2 = Gf.Line(Gf.Vec3d(0, 0, 0), Gf.Vec3d(1, 1, 1))
        self.assertNotEqual(l1, 2, err("inequality"))

        self.assertEqual(l1, eval(repr(l1)), err("repr"))
        self.assertTrue(len(str(Gf.Line())), err("str"))
Esempio n. 2
0
    def test_FindClosestPoint(self):
        r = Gf.Ray(Gf.Vec3d(), Gf.Vec3d(3, 4, 5))
        (p, dist) = r.FindClosestPoint(Gf.Vec3d(1, 1, 1))
        self.assertTrue(Gf.IsClose(p, Gf.Vec3d(0.72, 0.96, 1.2), 0.00001))
        self.assertTrue(Gf.IsClose(dist, 0.24, 0.00001))

        # non-intersecting case
        r = Gf.Ray(Gf.Vec3d(), Gf.Vec3d(3, 4, 5))
        l = Gf.Line(Gf.Vec3d(1, 0, 0), Gf.Vec3d(3, 3, 3))
        (intersects, rayPoint, linePoint, rayDistance, lineDistance) = \
                    Gf.FindClosestPoints(r, l)
        self.assertTrue(intersects and \
            rayPoint == Gf.Vec3d() and \
            Gf.IsClose(linePoint, Gf.Vec3d(-4./3,-7./3,-7./3), 0.00001) and \
            rayDistance == 0 and \
            Gf.IsClose(lineDistance, -4.04145188433, 0.00001))

        r = Gf.Ray(Gf.Vec3d(), Gf.Vec3d(3, 4, 5))
        l = Gf.Line(Gf.Vec3d(1, 0, 0), Gf.Vec3d(3, 4, 5))
        (intersects, rayPoint, linePoint, rayDistance, lineDistance) = \
                    Gf.FindClosestPoints(r, l)
        self.assertFalse(intersects)

        # closest point on theis line segment to the ray is going to
        # be the near end, (1,0,0)
        r = Gf.Ray(Gf.Vec3d(), Gf.Vec3d(3, 4, 5))
        l = Gf.LineSeg(Gf.Vec3d(1, 0, 0), Gf.Vec3d(3, 3, 3))
        (intersects, rayPoint, linePoint, rayDistance, lineDistance) = \
                    Gf.FindClosestPoints(r, l)
        (closestRayPtToNearEnd,
         rayDistToNearEnd) = r.FindClosestPoint(Gf.Vec3d(1, 0, 0))

        self.assertTrue(intersects and \
            Gf.IsClose(rayPoint, closestRayPtToNearEnd, 0.00001) and \
            Gf.IsClose(linePoint, Gf.Vec3d(1,0,0), 0.00001) and \
            Gf.IsClose(rayDistance, rayDistToNearEnd, 0.00001) and \
            Gf.IsClose(lineDistance, 0, 0.00001))

        r = Gf.Ray(Gf.Vec3d(), Gf.Vec3d(3, 4, 5))
        l = Gf.LineSeg(Gf.Vec3d(1, 0, 0), Gf.Vec3d(4, 4, 5))
        (intersects, rayPoint, linePoint, rayDistance, lineDistance) = \
                    Gf.FindClosestPoints(r, l)
        self.assertFalse(intersects)
Esempio n. 3
0
    def test_Methods(self):
        l = Gf.Line(Gf.Vec3d(0, 0, 0), Gf.Vec3d(1, 1, 1))
        (point, t) = l.FindClosestPoint(Gf.Vec3d(0.5, 0.5, 1))
        self.assertTrue(Gf.IsClose(point, Gf.Vec3d(2./3, 2./3, 2./3), 0.00001), err("FindClosestPoint"))
        self.assertTrue(Gf.IsClose(t, 1.1547, 0.0001), err("FindClosestPoint"))

        # (parallel case)
        l1 = Gf.Line(Gf.Vec3d(0, 0, 0), Gf.Vec3d(1, 1, 1))
        l2 = Gf.Line(Gf.Vec3d(1, 0, 0), Gf.Vec3d(1, 1, 1))
        self.assertEqual(Gf.FindClosestPoints(l1, l2)[0], False, err("FindClosestPoints"))

        l1 = Gf.Line(Gf.Vec3d(0, 0, 0), Gf.Vec3d(1, 1, 1))
        l2 = Gf.Line(Gf.Vec3d(1, 0, 0), Gf.Vec3d(1, -1, 1))
        (intersects, p1, p2, t1, t2) = Gf.FindClosestPoints(l1, l2)
        self.assertTrue(intersects, err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(p1, Gf.Vec3d(0.25, 0.25, 0.25), 0.00001), err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(p2, Gf.Vec3d(0.75, 0.25, -0.25), 0.00001), err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(t1, 0.433012701892, 0.00001))
        self.assertTrue(Gf.IsClose(t2, -0.433012701892, 0.00001))
Esempio n. 4
0
    def test_Properties(self):
        l = Gf.Line()
        l.Set(Gf.Vec3d(1,2,3), Gf.Vec3d(2,3,4))
        self.assertTrue(l.GetPoint(0) == Gf.Vec3d(1,2,3) and \
            l.direction == Gf.Vec3d(2,3,4).GetNormalized(), err("Set"))

        l.Set(Gf.Vec3d(0,0,0), Gf.Vec3d(0,1,0))
        self.assertTrue(l.GetPoint(0.5) == Gf.Vec3d(0, 0.5, 0) and \
            l.GetPoint(1.0) == Gf.Vec3d(0, 1, 0), err("GetPoint"))

        l.Set(Gf.Vec3d(1,2,3), Gf.Vec3d(2,3,4))
        l.direction = Gf.Vec3d(1, 1, 1)
        self.assertEqual(l.direction, Gf.Vec3d(1, 1, 1).GetNormalized(), err("direction"))
Esempio n. 5
0
 def test_Constructors(self):
     self.assertIsInstance(Gf.Line(), Gf.Line)
     self.assertIsInstance(Gf.Line(Gf.Vec3d(), Gf.Vec3d()), Gf.Line)
Esempio n. 6
0
    def test_Methods(self):
        l = Gf.LineSeg(Gf.Vec3d(0, 0, 0), Gf.Vec3d(1, 1, 1))
        (point, t) = l.FindClosestPoint(Gf.Vec3d(0.5, 0.5, 1))
        self.assertTrue(
            Gf.IsClose(point, Gf.Vec3d(2. / 3, 2. / 3, 2. / 3), 0.00001),
            err("FindClosestPoint"))
        self.assertTrue(Gf.IsClose(t, 2. / 3, 0.0001), err("FindClosestPoint"))

        l = Gf.LineSeg(Gf.Vec3d(0, 0, 0), Gf.Vec3d(0, 0, 0))
        (point, t) = l.FindClosestPoint(Gf.Vec3d(0.5, 0.5, 1))
        self.assertTrue(Gf.IsClose(point, Gf.Vec3d(), 0.00001),
                        err("FindClosestPoint"))
        self.assertTrue(Gf.IsClose(t, 0, 0.0001), err("FindClosestPoint"))

        # seg on seg
        # (parallel case)
        l1 = Gf.LineSeg(Gf.Vec3d(0, 0, 0), Gf.Vec3d(1, 1, 1))
        l2 = Gf.LineSeg(Gf.Vec3d(1, 0, 0), Gf.Vec3d(2, 1, 1))
        self.assertEqual(
            Gf.FindClosestPoints(l1, l2)[0], False, err("FindClosestPoints"))

        l1 = Gf.LineSeg(Gf.Vec3d(0, 0, 0), Gf.Vec3d(1, 1, 1))
        l2 = Gf.LineSeg(Gf.Vec3d(1, 0, 0), Gf.Vec3d(1, -1, 1))
        (intersects, p1, p2, t1, t2) = Gf.FindClosestPoints(l1, l2)
        self.assertTrue(intersects, err("FindClosestPoints"))
        self.assertTrue(
            Gf.IsClose(p1, Gf.Vec3d(1. / 3, 1. / 3, 1. / 3), 0.00001),
            err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(p2, Gf.Vec3d(1, 0, 0), 0.00001),
                        err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(t1, 1. / 3, 0.00001))
        self.assertTrue(Gf.IsClose(t2, 0, 0.00001))

        l1 = Gf.LineSeg(Gf.Vec3d(), Gf.Vec3d())
        l2 = Gf.LineSeg(Gf.Vec3d(1, 1, 1), Gf.Vec3d(1, 1, 1))
        (intersects, p1, p2, t1, t2) = Gf.FindClosestPoints(l1, l2)
        self.assertFalse(intersects, err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(p1, Gf.Vec3d(), 0.00001),
                        err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(p2, Gf.Vec3d(), 0.00001),
                        err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(t1, 0, 0.00001))
        self.assertTrue(Gf.IsClose(t2, 0, 0.00001))
        (intersects, p1, p2, t1, t2) = Gf.FindClosestPoints(l2, l1)
        self.assertFalse(intersects, err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(p1, Gf.Vec3d(), 0.00001),
                        err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(p2, Gf.Vec3d(), 0.00001),
                        err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(t1, 0, 0.00001))
        self.assertTrue(Gf.IsClose(t2, 0, 0.00001))

        # line on seg
        # (parallel case)
        l1 = Gf.Line(Gf.Vec3d(0, 0, 0), Gf.Vec3d(1, 1, 1))
        l2 = Gf.LineSeg(Gf.Vec3d(1, 0, 0), Gf.Vec3d(2, 1, 1))
        self.assertEqual(
            Gf.FindClosestPoints(l1, l2)[0], False, err("FindClosestPoints"))

        l1 = Gf.Line(Gf.Vec3d(0, 0, 0), Gf.Vec3d(1, 1, 1))
        l2 = Gf.LineSeg(Gf.Vec3d(1, 0, 0), Gf.Vec3d(1, -1, 1))
        (intersects, p1, p2, t1, t2) = Gf.FindClosestPoints(l1, l2)
        self.assertTrue(intersects, err("FindClosestPoints"))
        self.assertTrue(
            Gf.IsClose(p1, Gf.Vec3d(1. / 3, 1. / 3, 1. / 3), 0.00001),
            err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(p2, Gf.Vec3d(1, 0, 0), 0.00001),
                        err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(t1, 0.57735, 0.00001))
        self.assertTrue(Gf.IsClose(t2, 0, 0.00001))

        l1 = Gf.Line(Gf.Vec3d(0, 0, 0), Gf.Vec3d(1, 1, 1))
        l2 = Gf.LineSeg(Gf.Vec3d(), Gf.Vec3d())
        (intersects, p1, p2, t1, t2) = Gf.FindClosestPoints(l1, l2)
        self.assertFalse(intersects, err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(p1, Gf.Vec3d(), 0.00001),
                        err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(p2, Gf.Vec3d(), 0.00001),
                        err("FindClosestPoints"))
        self.assertTrue(Gf.IsClose(t1, 0, 0.00001))
        self.assertTrue(Gf.IsClose(t2, 0, 0.00001))