コード例 #1
0
 def test_cubic_line(self):
     q = CubicBezier(Point(100, 240), Point(30, 60), Point(210, 230),
                     Point(160, 30))
     l = Line(Point(25, 260), Point(230, 20))
     path = BezierPath()
     path.closed = False
     path.activeRepresentation = SegmentRepresentation(path, [q])
     i = q.intersections(l)
     self.assertEqual(len(i), 3)
     self.assertEqual(i[0].point, q.pointAtTime(0.117517031451))
     self.assertEqual(i[1].point, q.pointAtTime(0.518591792307))
     self.assertEqual(i[2].point, q.pointAtTime(0.867886610031))
コード例 #2
0
  def test_loop(self):
    q = CubicBezier(
      Point(171,272), Point(388,249), Point(167,444), Point(388,176)
    )
    self.assertTrue(not q.hasLoop)

    q = CubicBezier(
      Point(171,272), Point(595,249), Point(167,444), Point(388,176)
    )
    roots = q.hasLoop
    p1 = q.pointAtTime(roots[0])
    p2 = q.pointAtTime(roots[1])
    self.assertTrue(q.hasLoop)
    self.assertEqual(p1,p2)
コード例 #3
0
        # Subdivision
        r1 = self.minDist(uinterval=(umin, newuMid), vinterval=(vmin, newvMid))
        r2 = self.minDist(uinterval=(umin, newuMid), vinterval=(newvMid, vmax))
        r3 = self.minDist(uinterval=(newuMid, umax), vinterval=(vmin, newvMid))
        r4 = self.minDist(uinterval=(newuMid, umax), vinterval=(newvMid, vmax))
        results = min([r1, r2, r3, r4], key=lambda x: x[0])
        return results


def curveDistance(bez1, bez2):
    """Find the distance between two curves."""
    c = MinimumCurveDistanceFinder(bez1, bez2)
    dist, t1, t2 = c.minDist()
    return math.sqrt(dist), t1, t2


if __name__ == "__main__":
    bez1 = CubicBezier(Point(129, 139), Point(190, 139), Point(201, 364),
                       Point(90, 364))
    bez2 = CubicBezier(Point(309, 159), Point(178, 159), Point(215, 408),
                       Point(309, 408))
    bez3 = Line(Point(309, 159), Point(309, 408))

    c = MinimumCurveDistanceFinder(bez1, bez3)
    dist, t1, t2 = c.minDist()
    print(bez1.pointAtTime(t1))
    print(bez3.pointAtTime(t2))
    print(math.sqrt(dist))
    print(c.iterations)