typemytype / booleanOperations

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

colinear overlaps not detected #54

Closed gferreira closed 5 years ago

gferreira commented 5 years ago

continuing from hasOverlap() does not detect all overlaps? (RoboFont Forum)

it seems the problem can be generalised to colinear straight segments in different contours. here are some examples with other shapes (red circles show detected overlaps):

Screen Shot 2019-04-29 at 13 50 41

Screen Shot 2019-04-29 at 13 50 37

some points appear/disappear when the objects are rotated:

Screen Shot 2019-04-29 at 13 50 28

here’s a helper to visualize overlaps while editing a glyph:

from vanilla import *
from defconAppKit.windows.baseWindow import BaseWindowController
from mojo.events import addObserver, removeObserver
from mojo.UI import UpdateCurrentGlyphView
from mojo.drawingTools import *

class ShowOverlaps(BaseWindowController):

    def __init__(self):
        self.w = FloatingWindow((130, 40))
        self.w.draw = CheckBox((10, 10, -10, 20), 'show overlaps', value=True, callback=self.updateViewCallback)
        addObserver(self, "drawBackgroundCallback", "drawBackground")
        self.setUpBaseWindowBehavior()
        self.w.open()

    def windowCloseCallback(self, sender):
        removeObserver(self, 'drawBackground')
        super(ShowOverlaps, self).windowCloseCallback(sender)

    def updateViewCallback(self, sender):
        UpdateCurrentGlyphView()

    def drawBackgroundCallback(self, info):
        if not self.w.draw.get():
            return
        g = info["glyph"]
        pts = g.hasOverlap()
        if not len(pts):
            return
        r = 20
        save()
        fill(None)
        stroke(1, 0, 0)
        strokeWidth(10)
        for x, y in pts:
            oval(x-r, y-r, r*2, r*2)
        restore()
        UpdateCurrentGlyphView()

ShowOverlaps()

thanks in advance for looking into it!

typemytype commented 5 years ago

can the glif xml be posted?

thanks!!

gferreira commented 5 years ago

sure, here are some rects :) testOverlaps.ufo.zip thx

typemytype commented 5 years ago

Oh yeah, getIntersections() is just returning all new points... in most of those cases there is no new point as the intersection is on top of an existing point...

see https://github.com/typemytype/booleanOperations/blob/master/Lib/booleanOperations/booleanOperationManager.py#L133