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

Binary build at https://github.com/simoncozens/Callipers/releases/download/pre-alpha-1/Callipers-pre-alpha-1.zip

1 Like