typemytype / booleanOperations

Boolean operations on paths
MIT License
39 stars 18 forks source link

Assertion error #31

Closed khaledhosny closed 8 years ago

khaledhosny commented 8 years ago

I’m using the following code:

import sys
from booleanOperations import BooleanOperationManager
from defcon import Font

ufo = Font(sys.argv[1])
manager = BooleanOperationManager()
for glyph in ufo:
    contours = list(glyph)
    glyph.clearContours()
    print(glyph.name)
    manager.union(contours, glyph.getPointPen())

Which gives me the following assertion error with JosefinSans-Regular.ufo.zip (different glyph each time):

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    manager.union(contours, glyph.getPointPen())
  File "/lib/python3.5/site-packages/booleanOperations/booleanOperationManager.py", line 58, in union
    return _performOperation("union", contours, [], outPen)
  File "/lib/python3.5/site-packages/booleanOperations/booleanOperationManager.py", line 18, in _performOperation
    subjectInputContours = [InputContour(contour) for contour in subjectContours if contour and len(contour) > 1]
  File "/lib/python3.5/site-packages/booleanOperations/booleanOperationManager.py", line 18, in <listcomp>
    subjectInputContours = [InputContour(contour) for contour in subjectContours if contour and len(contour) > 1]
  File "/lib/python3.5/site-packages/booleanOperations/flatten.py", line 71, in __init__
    self.segments = _convertPointsToSegments(points)
  File "/lib/python3.5/site-packages/booleanOperations/flatten.py", line 436, in _convertPointsToSegments
    willBeReversed=willBeReversed
  File "/lib/python3.5/site-packages/booleanOperations/flatten.py", line 173, in __init__
    for pt1, pt2 in decomposeQuadraticSegment(pointCoordinates[1:]):
  File "/fonttools/Lib/fontTools/pens/basePen.py", line 329, in decomposeQuadraticSegment
    assert n > 0
AssertionError

I’m not sure if this is a bug in the font (the font was converted from FontLab .vfb file by vfb2ufo), FontTools, or booleanOperations.

anthrotype commented 8 years ago

Does the font contain qcurve segments?

BooleanOperations currently only works with PostScript cubic curves, but there's a work in progress branch by @typemytype that adds Support for TrueType quadratic splines.

https://github.com/typemytype/booleanOperations/tree/quadratics?files=1

khaledhosny commented 8 years ago

Seems to be the case.