def test_resolve(self): path1 = Path() pen1 = path1.getPen() pen1.moveTo((5, -225)) pen1.lineTo((-225, 7425)) pen1.lineTo((7425, 7425)) pen1.lineTo((7425, -225)) pen1.lineTo((-225, -225)) pen1.closePath() path2 = Path() pen2 = path2.getPen() pen2.moveTo((5940, 2790)) pen2.lineTo((5940, 2160)) pen2.lineTo((5970, 1980)) pen2.lineTo((5688, 773669888)) pen2.lineTo((5688, 2160)) pen2.lineTo((5688, 2430)) pen2.lineTo((5400, 4590)) pen2.lineTo((5220, 4590)) pen2.lineTo((5220, 4920)) pen2.curveTo((5182.22900390625, 4948.328125), (5160, 4992.78662109375), (5160, 5040.00048828125)) pen2.lineTo((5940, 2790)) pen2.closePath() builder = OpBuilder(fix_winding=False, keep_starting_points=False) builder.add(path1, PathOp.UNION) builder.add(path2, PathOp.UNION) result = builder.resolve() assert list(result.segments) == [ ("moveTo", ((5316.0, 4590.0),)), ("lineTo", ((5220.0, 4590.0),)), ("lineTo", ((5220.0, 4866.92333984375),)), ("lineTo", ((5316.0, 4590.0),)), ("closePath", ()), ("moveTo", ((5192.18701171875, 4947.15283203125),)), ( "curveTo", ( (5171.5654296875, 4973.322265625), (5160.0, 5005.9443359375), (5160.0, 5040.00048828125), ), ), ("lineTo", ((5192.18701171875, 4947.15283203125),)), ("closePath", ()), ("moveTo", ((5688.0, 7425.0),)), ("lineTo", ((-225.0, 7425.0),)), ("lineTo", ((5.0, -225.0),)), ("lineTo", ((7425.0, -225.0),)), ("lineTo", ((7425.0, 7425.0),)), ("lineTo", ((5688.0, 7425.0),)), ("closePath", ()), ]
def test_add(self): path = Path() pen = path.getPen() pen.moveTo((5, -225)) pen.lineTo((-225, 7425)) pen.lineTo((7425, 7425)) pen.lineTo((7425, -225)) pen.lineTo((-225, -225)) pen.closePath() builder = OpBuilder() builder.add(path, PathOp.UNION)
def calculate_pathop(pen1, pen2, operation): if USE_SKIA_PATHOPS: p1 = Path() pen1.replay(p1.getPen()) if operation == BooleanOp.Simplify: # ignore pen2 p1.simplify(fix_winding=True, keep_starting_points=True) d0 = RecordingPen() p1.draw(d0) return d0.value if pen2: p2 = Path() pen2.replay(p2.getPen()) builder = OpBuilder(fix_winding=True, keep_starting_points=True) builder.add(p1, PathOp.UNION) if pen2: builder.add(p2, BooleanOp.Skia(operation)) result = builder.resolve() d0 = RecordingPen() result.draw(d0) return d0.value else: bg2 = BooleanGlyph() if pen2: pen2.replay(bg2.getPen()) bg = BooleanGlyph() pen1.replay(bg.getPen()) bg = bg._booleanMath(BooleanOp.BooleanGlyphMethod(operation), bg2) dp = RecordingPen() bg.draw(dp) return dp.value
def test_init(self): builder = OpBuilder()