nearestPointOnPath_pathTime_ spectacularly wrong with Quadratic curves

I’m trying to write a script which uses nearestPointOnPath_pathTime_ but when testing I got bizarrely wrong answers. Here’s aKaf.medi from Khaled’s Amiri font.

28

In the Macro window, type:

Layer = Glyphs.font.selectedLayers[0]
print(Layer.paths[0].nearestPointOnPath_pathTime_(NSMakePoint(564,0), None))

Answer:

(<NSPoint x=551.0 y=731.0>, 26.0)

Converting to Cubic makes it work.

One workaround would be to duplicate the path and convert to cubic in script before running nearestPointOnPath_pathTime_ on it but I am not sure how to do that.

I’m working on adding support for TrueType in those functions. You don’t happen to have some good TrueType math functions laying around :wink:

1 Like

If it’s not in beziers.py I don’t know how to do it. :slight_smile:
Any way to convert to cubic from Python?

path.convertToCubic()

1 Like

Well that was easy. :slight_smile: Thanks.