コード例 #1
0
 def test_addextremes(self):
     q = CubicBezier(Point(42, 135), Point(129, 242), Point(167, 77),
                     Point(65, 59))
     ex = q.findExtremes()
     self.assertEqual(len(ex), 2)
     path = BezierPath()
     path.closed = False
     path.activeRepresentation = SegmentRepresentation(path, [q])
     path.addExtremes()
     path.balance()
     segs = path.asSegments()
     self.assertEqual(len(segs), 3)
コード例 #2
0
    def _curve_from_lines(self, point_tuple_list: list) -> list:
        error = 50.0
        cornerTolerance = 20.0
        maxSegments = 20
        curve_points = SCBezierPath().fromPoints(
            [SCPoint(p[0], p[1]) for p in point_tuple_list],
            error=1.0,
            cornerTolerance=1.0,
            maxSegments=10000,
        )

        # Reconvert the BezierPath segments to our segment type
        point_tuple_list = []
        first = True
        for segment in curve_points.asSegments():
            segment_tuple = []
            if first:
                # For the first segment, add the move point
                p = segment[0]
                point_tuple_list.append([(p.x, p.y)])
            for p in segment[1:]:
                segment_tuple.append((p.x, p.y))
            point_tuple_list.append(segment_tuple)
        return point_tuple_list
コード例 #3
0
ファイル: test_offset.py プロジェクト: simoncozens/beziers.py
 def not_a_test_offset(self):
     b = DotMap({
         "closed":
         False,
         "nodes": [{
             "x": 412.0,
             "y": 500.0,
             "type": "line"
         }, {
             "x": 308.0,
             "y": 665.0,
             "type": "offcurve"
         }, {
             "x": 163.0,
             "y": 589.0,
             "type": "offcurve"
         }, {
             "x": 163.0,
             "y": 504.0,
             "type": "curve"
         }, {
             "x": 163.0,
             "y": 424.0,
             "type": "offcurve"
         }, {
             "x": 364.0,
             "y": 321.0,
             "type": "offcurve"
         }, {
             "x": 366.0,
             "y": 216.0,
             "type": "curve"
         }, {
             "x": 368.0,
             "y": 94.0,
             "type": "offcurve"
         }, {
             "x": 260.0,
             "y": 54.0,
             "type": "offcurve"
         }, {
             "x": 124.0,
             "y": 54.0,
             "type": "curve"
         }]
     })
     path = BezierPath()
     path.activeRepresentation = GSPathRepresentation(path, b)
     import matplotlib.pyplot as plt
     fig, ax = plt.subplots()
     path.addExtremes()
     path.plot(ax)
     for n in path.asSegments():
         p = n.tunniPoint
         if p:
             circle = plt.Circle((p.x, p.y), 1, fill=False, color="blue")
             ax.add_artist(circle)
         n.balance()
     path.translate(Point(5, 5))
     path.plot(ax, color="red")
     # o1 = path.offset(Point(10,10))
     # o2 = path.offset(Point(-10,-10))
     # o2.reverse()
     # o1.append(o2)
     # o1.plot(ax)
     plt.show()
コード例 #4
0
    def test_representations(self):
        b = DotMap({
            "closed":
            True,
            "nodes": [{
                "x": 385.0,
                "y": 20.0,
                "type": "offcurve"
            }, {
                "x": 526.0,
                "y": 79.0,
                "type": "offcurve"
            }, {
                "x": 566.0,
                "y": 135.0,
                "type": "curve"
            }, {
                "x": 585.0,
                "y": 162.0,
                "type": "offcurve"
            }, {
                "x": 566.0,
                "y": 260.0,
                "type": "offcurve"
            }, {
                "x": 484.0,
                "y": 281.0,
                "type": "curve"
            }, {
                "x": 484.0,
                "y": 407.0,
                "type": "offcurve"
            }, {
                "x": 381.0,
                "y": 510.0,
                "type": "offcurve"
            }, {
                "x": 255.0,
                "y": 510.0,
                "type": "curve"
            }, {
                "x": 26.0,
                "y": 281.0,
                "type": "line"
            }, {
                "x": 26.0,
                "y": 155.0,
                "type": "offcurve"
            }, {
                "x": 129.0,
                "y": 20.0,
                "type": "offcurve"
            }, {
                "x": 255.0,
                "y": 20.0,
                "type": "curve"
            }]
        })

        path = BezierPath()
        path.activeRepresentation = GSPathRepresentation(path, b)
        nl = path.asNodelist()
        self.assertEqual(len(nl), 13)
        self.assertIsInstance(nl[1], Node)
        self.assertEqual(nl[1].type, "offcurve")
        self.assertAlmostEqual(nl[1].x, 526.0)

        segs = path.asSegments()
        self.assertEqual(len(segs), 5)
        self.assertIsInstance(segs[1], CubicBezier)
        self.assertIsInstance(segs[2], Line)