Best way to find intersection

What is the best way to find intersection coordinates of two paths via Glyphs?
Or is there something like layer.intersectionsBetweenPoints() but for path?

I’ve found path.bezierPath.intersectionWithLine_lineStart_lineEnd_() , but what arguments are required?

This is not officially documented but you can get good hints by looking at the headers in /Applications/ I usually open the whole folder in my text editor and do a multi-file search for the method or class in question.

In this case the file NSBezierPath-OAExtensions.h contains the definition (in ObjectiveC):

- (BOOL)intersectionWithLine:(NSPoint *)result lineStart:(NSPoint)lineStart lineEnd:(NSPoint)lineEnd;

That suggests you need three NSPoints as parameters but I have not tested it. Does it work for you?

Thanks for help, Tim.

I can’t figure out what I need to send as (NSPoint *)result

ValueError: deponitize a pointer, received an NSPoint

Did you set up an NSPoint first and then pass it to the method (as opposed to constructing one in-line)?

But, to be honest, that’s beyond my PyObjC knowledge. @GeorgSeifert?

The (NSPoint *) means that the value is returned by reference. So in python, you normally put in a None and the result will be returned as a tuple.

What exactly are you trying to do?

Glyphs crashes when I run this code.

I want to find coordinates of intersection of 2 paths or path and line using Glyphs built-ins.

With the current build in functions, your first idea is probably the best. You can make a new layer, put a copy of both paths in it and run newLayer.intersectionsBetweenPoints().

Hi @GeorgSeifert, is this still the case? The function intersectionsBetweenPoints requires three parameters, the first two of which are the coordinates of a measurement line. As far as I have understood the OP, he wants to find the intersections between two paths, which may contain curves - is there a built-in function to do this?

I seem to have solved this myself; there is a function in NSBezierPath that does exactly this:
where p1 and p2 are of type GSPath.
Perhaps this info helps someone else.

I still don’t know what exactly you are trying to do.

There is a method layer.intersections() that will return a list of points that is used to draw the black intersection dots in the edit view.

Can I ask how to iterate over layer.intersections()?

inter = Layer.intersections()
for i in range(inter.count()):
	print(i, inter.pointAtIndex_(i))
1 Like