Merge pull request #690 from jamesgk/area-pen

Allow single-point open contours in area pen
This commit is contained in:
James Godfrey-Kittle 2016-10-04 18:05:43 -07:00 committed by GitHub
commit 0682e77370
2 changed files with 17 additions and 2 deletions

View File

@ -63,5 +63,9 @@ class AreaPen(BasePen):
del self._p0, self._startPoint
def _endPath(self):
"""Area is not defined for open contours."""
raise NotImplementedError
"""Area is not defined for open contours.
Single-point open contours, which often represent anchors, are allowed.
"""
if self._p0 != self._startPoint:
raise NotImplementedError
del self._p0, self._startPoint

View File

@ -163,6 +163,17 @@ class AreaPenTest(unittest.TestCase):
draw8_(pen)
self.assertEqual(104602.791667, round(pen.value, precision))
def test_openPaths(self):
pen = AreaPen()
pen.moveTo((0, 0))
pen.endPath()
self.assertEqual(0, pen.value)
pen.moveTo((0, 0))
pen.lineTo((1, 0))
with self.assertRaises(NotImplementedError):
pen.endPath()
if __name__ == '__main__':
unittest.main()