def test_pathops_union(shapes, expected_result): assert (SVGPath.from_commands( svg_pathops.union([s.as_cmd_seq() for s in shapes], [s.clip_rule for s in shapes])).d == expected_result)
# same rect, offset ( SVGRect(x=0, y=1, width=1, height=1), SVGRect(x=1, y=0, width=1, height=1), Affine2D.identity().translate(1, -1), ), # circles that may happen to match the ones Noto clock emoji ( SVGCircle(cx=15.89, cy=64.13, r=4), SVGCircle(cx=64.89, cy=16.13, r=4), Affine2D.identity().translate(49, -48), ), # path observed in wild to normalize but not compute affine_between # caused by failure to normalize equivalent d attributes in affine_between ( SVGPath(fill="#99AAB5", d="M18 12H2 c-1.104 0-2 .896-2 2h20c0-1.104-.896-2-2-2z"), SVGPath(fill="#99AAB5", d="M34 12H18c-1.104 0-2 .896-2 2h20c0-1.104-.896-2-2-2z"), Affine2D.identity().translate(16, 0), ), ], ) def test_svg_reuse(s1, s2, expected_affine): # if we can get an affine we should normalize to same shape if expected_affine: assert normalize(s1) == normalize(s2) else: assert normalize(s1) != normalize(s2) assert affine_between(s1, s2) == expected_affine
import pytest from picosvg import svg_pathops from picosvg.svg_types import SVGCircle, SVGPath, SVGRect def _round(pt, digits): return tuple(round(v, digits) for v in pt) @pytest.mark.parametrize( "shape, expected_segments, expected_path", [ # path ( SVGPath(d="M1,1 2,2 z"), (("moveTo", ((1.0, 1.0), )), ("lineTo", ((2.0, 2.0), )), ("closePath", ())), "M1,1 L2,2 Z", ), # rect ( SVGRect(x=4, y=4, width=6, height=16), ( ("moveTo", ((4.0, 4.0), )), ("lineTo", ((10.0, 4.0), )), ("lineTo", ((10.0, 20.0), )), ("lineTo", ((4.0, 20.0), )), ("lineTo", ((4.0, 4.0), )), ("closePath", ()), ),