typemytype / booleanOperations

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

Union produces different contour order depending on platform #55

Closed madig closed 4 years ago

madig commented 5 years ago

Stumbled over this because fonts build on our build server (running Linux) produce differently ordered contours for a specific glyph which broke hinting. Can reproduce with two glyphs from Noto Sans Regular (NotoSansTest.ufo.zip). Running the following script on Linux and Windows will produce differently ordered contours:

import sys

import booleanOperations
import ufoLib2

u = ufoLib2.Font.open("NotoSansTest.ufo")

for g in u:
    if not g.contours:
        continue

    cs = [c for c in g.contours]
    g.clearContours()
    p = g.getPointPen()
    booleanOperations.union(cs, p)

if sys.platform == "win32":
    u.save("test-win.ufo")
else:
    u.save("test-lin.ufo")

Still drilling down to where this happens.

madig commented 5 years ago

It happens inside clipExecute(). The input parameters are the same, but the output resultContours are ordered differently on Windows and Linux.

madig commented 5 years ago

Here's a reproducer driving pyclipper directly: https://gist.github.com/madig/998ec05ef8a496f984aaa86aeceda6fc.

anthrotype commented 5 years ago

I suggest you open the bug on pyclipper repository, maybe other non-font users can help

madig commented 5 years ago

Filed upstream at https://sourceforge.net/p/polyclipping/bugs/195.

madig commented 5 years ago

Oh well. angusj responded there and said it's just how the algorithm works. Guess I have to write that ufo2ft filter.

madig commented 4 years ago

Optional ufo2ft filter implemented in https://github.com/googlefonts/ufo2ft/pull/345.