Get segment of point in tool

I want to write a tool which is a little like the measurement tool. When I drag across a curve, I would like to know the point coordinates of the intersection and also the segment being intersected. Is there a way to get this information already or do I have to work it all out from the coordinates of the mouse cursor and interpolate on the curve manually?

`GSLayer.intersectionsBetweenPoints(p1,p2)` but that doesnâ€™t give you the segment. There are some methods for that in GSGeometrieHelper, but I havenâ€™t figured out yet how to access it via the PyObjC bridge.

Iâ€™m happy to write in ObjC; what are the methods?

Actually I think there might be another way to do it; I can test each segment with `GSSegment.intersects` against the line.

Look in `GSGeometrieHelper.h`, which contains this:

``````NSArray* GSIntersectBezier3LineTimes(NSPoint p1, NSPoint p2, NSPoint p3, NSPoint p4, NSPoint a1, NSPoint a2, BOOL checkBounds);
``````

â€¦ but also dozens of similar methods, perhaps one that fits your purpose even better. Just poke around a bit.

There is a path method for this: http://docu.glyphsapp.com/Core/Classes/GSPath.html#//api/name/nearestPointOnPath:pathTime:

edit:
But iterating the segments yourself with the methods mentioned by mekkablue is the better option for you.

Got it! Thank you!

Hereâ€™s what Iâ€™m working on:

I have been working on something similar. How are you finding the opposite segment? Taking a perpendicular cut from t=0.5?

Thatâ€™s why I was talking about â€śsomething like the measurement toolâ€ť and finding the intersections on the segment: the user draws a line through the path to set the start thickness, (i.e. start point on two segments) and then another line through to set the end thickness.

(or at least, they will when itâ€™s finished - that bit isnâ€™t quite done yetâ€¦)

My approach is as follows:

1. Do not display anything until the user selects two non-adjacent segments.
2. Then display the distances between t=0â€¦1 and t=1â€¦0 of these two segments until the user selects two other non-adjacent segments.

Well, hereâ€™s my approach: https://github.com/simoncozens/Callipers

1 Like