Question

The path I'm using has no curves; just a series of connected points.

The method I'm currently using involves iterating through the NZBezierPathElement components of the path and getting each point, but this is clumsy - especially because I have to save the last point to get each new distance. If any of you know of a better method, that would be very much appreciated.

Was it helpful?

Solution

Your algorithm sounds exactly right - the length of the path is the sum of the lengths between each pair of points. It's hard to see why you think this is "clumsy", so here is the algorithm in pseudo code just in case:

startPoint <- point[1]
length <- 0
repeat with n <- 2 to number of points
   nextPoint <- point[n]
   length <- length + distanceBetween(startPoint, nextPoint)
   startPoint <- nextPoint // hardly clumsy
end repeat

Maybe you're doing it differently?

The notion of current point is fundamental to NSBezierPath (and SVG, turtle graphics, etc.), with its relative commands (e.g. move relative, line relative) - there is no escaping it!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top