Search code examples
objective-ciosintersectionuibezierpathcgpath

How to detect if an UIBezierPath intersects itself?


I have an user drawn UIBezierPath and I want to know if it intersects itself. Can anyone point me in a good direction for detecting this?

Thanks!


Solution

  • How do you build your path? Is it just an accumulation of straight line segments? If so you could keep a list of those (parallel to your UIBezierPath, that you use for rendering), and then perform line intersection tests. It'll be O(N^2), though, in the naive implementation.