Skip to content

Commit

Permalink
Stop infinite loop in .segments with quadratic curves (#951)
Browse files Browse the repository at this point in the history
* Allow .segments to work on cubic curves, fixes #949

* Tests for #949

* Fixup test

* Lint fix
  • Loading branch information
simoncozens authored Oct 25, 2023
1 parent 217564d commit cb8a4a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/glyphsLib/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2314,7 +2314,7 @@ def wrap(i):
newSegment.appendNode(nodes[wrap(nodeCount + 1)])
newSegment.appendNode(nodes[wrap(nodeCount + 2)])
nodeCount += 3
elif nodes[nodeCount].type == "line":
elif nodes[nodeCount].type == "line" or nodes[nodeCount].type == "qcurve":
newSegment.appendNode(nodes[nodeCount])
nodeCount += 1

Expand Down
22 changes: 22 additions & 0 deletions tests/classes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,28 @@ def test_segments_2(self):
]
self.assertEqual(len(p.segments), 4)

def test_segments_3(self):
p = GSPath()
p.nodes = [
GSNode((327, 185), "offcurve"),
GSNode((299, 210), "offcurve"),
GSNode((297, 266), "curve"),
GSNode((294, 351), "offcurve"),
GSNode((297, 434), "qcurve"),
GSNode((299, 490), "offcurve"),
GSNode((328, 515), "offcurve"),
GSNode((371, 515), "curve"),
GSNode((414, 515), "offcurve"),
GSNode((443, 490), "offcurve"),
GSNode((445, 434), "curve"),
GSNode((448, 351), "offcurve"),
GSNode((445, 266), "qcurve"),
GSNode((443, 210), "offcurve"),
GSNode((415, 185), "offcurve"),
GSNode((371, 185), "curve"),
]
self.assertEqual(len(p.segments), 6)

def test_bounds(self):
bounds = self.path.bounds
self.assertEqual(bounds.origin.x, 80)
Expand Down

0 comments on commit cb8a4a9

Please sign in to comment.