Cannot distinguish horizontal and vertical path through NSIntersectsRect

There are two horizontal and vertical lines, but can’t copy it through the following script.
I think NSIntersectsRect can’t distinguish them.
Could you help.

layer = Glyphs.font.glyphs['space'].layers[0]

xPaths = []
checkRect =  NSMakeRect(0, 0, 330, 480)
i = 0
for p in layer.shapes:
	i = i +1
	if NSIntersectsRect(checkRect, p.bounds):

p1 = Glyphs.font.glyphs['P1'].layers[0]
print(i, xPaths)

lineCopy.glyphs (60.7 KB)

(Use three grave accents to build a code block “```”. I edited your post.)

What you can do is to add a very small amount to the height/width if it is zero.
something like this:

def expandRect(rect):
    if rect.size.width < 0.00001:
        rect.size.width += 0.00001
    if rect.size.height < 0.00001:
        rect.size.height += 0.00001
    return rect

Then NSIntersectsRect will catch it.

I’ve add other script to handle this special case.:slight_smile: