Find nearest point for a given coordinate

157 views
Skip to first unread message

Jens Kutilek

unread,
Sep 3, 2013, 12:41:49 PM9/3/13
to rob...@googlegroups.com
Hi,

is there any shortcut method that returns the on-curve point of a glyph which has the closest distance from a given coordinate?

Or do I have to bake my own? ;)

Cheers,
Jens

Tal Leming

unread,
Sep 3, 2013, 1:33:46 PM9/3/13
to rob...@googlegroups.com
I think you'll have to bake your own.

A custom point pen might be the easiest way to do it. You could store something like (x, y, contour index, point index) for all points passed through addPoint and then iterate over that when you test the coordinate. Or you could start the pen with the coordinate and as a point comes in through addPoint you could test the distance and store the contour index and point index if the distance is closer to the coordinate than the point that was formerly closest. If there is a direct hit, you can stop. Or… Lots of fun ways to do this. :-)

Tal
> --
> --
> You received this message because you are subscribed to the Google Groups "RoboFab" group.
> To post to this group, send email to rob...@googlegroups.com
> To unsubscribe from this group, send email to robofab-u...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/robofab?hl=en
>
> Messages from newly joined members are subject to moderation.
> Download RoboFab and documentation at http://robofab.com
> ---
> You received this message because you are subscribed to the Google Groups "RoboFab" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to robofab+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Frederik Berlaen

unread,
Sep 3, 2013, 1:57:09 PM9/3/13
to rob...@googlegroups.com
or in case you are using RoboFont you can use:

"""
g = CurrentGlyph()
closestPointFactory = g.naked().getRepresentation("doodle.closestPoint")
contourIndex, pointOnTheCurve = closestPointFactory.getClosestContourIndex((100, 100))
"""

but I guess Ive spoiled your nice evening finding it out :)

good luck!

gr Frederik
www.typemytype.com

Jens Kutilek

unread,
Sep 4, 2013, 11:04:14 AM9/4/13
to rob...@googlegroups.com
Thanks, Tal and Frederik,

I've built a pen for it. I love pens :)

The closestPointFactory doesn't do exactly what I wanted, which is the closest of the existing points (excluding off-curve points).

(The closestPointFactory returns the coordinate of the shortest distance from the reference point to the curve of the closest contour.)

Cheers,
Jens

> -----Original Message-----
> Behalf Of Frederik Berlaen
>
> or in case you are using RoboFont you can use:
>
> """
> g = CurrentGlyph()
> closestPointFactory = g.naked().getRepresentation("doodle.closestPoint")
> contourIndex, pointOnTheCurve =
> closestPointFactory.getClosestContourIndex((100, 100))
> """
>
> but I guess Ive spoiled your nice evening finding it out :)
>
> good luck!
>
> gr Frederik
> www.typemytype.com
>
>
>
> On 03 Sep 2013, at 19:33, Tal Leming wrote:
>
> > I think you'll have to bake your own.
> >
> > A custom point pen might be the easiest way to do it. You could store
> something like (x, y, contour index, point index) for all points passed through
> addPoint and then iterate over that when you test the coordinate. Or you could
> start the pen with the coordinate and as a point comes in through addPoint you
> could test the distance and store the contour index and point index if the
> distance is closer to the coordinate than the point that was formerly closest. If
> there is a direct hit, you can stop. Or... Lots of fun ways to do this. :-)

Reply all
Reply to author
Forward
0 new messages