1

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.

chm
  • 1,519
  • 13
  • 21

1 Answers1

1

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!

CRD
  • 52,522
  • 5
  • 70
  • 86
  • Very reassuring, thanks! I just thought there may have been some built-in support for this that I was missing. Your pseudocode is exactly what I have been doing. – chm Oct 05 '12 at 10:43