CodingMeSwiftly / UIBezierPath-Superpowers

MIT License
78 stars 16 forks source link

minor nit #1

Closed jerryhalstead closed 6 years ago

jerryhalstead commented 6 years ago

I'm using mx_perpendicularPoint so when a user taps on the screen we can highlight the nearest "drawing object".

Sometimes a line segment might not have a length (i.e. user touched/released to make a dot), but it is visible because of setLineCapStyle:kCGLineCapRound.

In calculatePointLookupTable it doesn't take into account a single point "path" like this, element.length is zero and points.append(element.point(at: offset / element.length)) fails because offset is divided by zero producing Nan for an index.

CodingMeSwiftly commented 6 years ago

Thanks for pointing this out. Fixing this is a bit tricky however. Am I right to assume that you create your path with a combination of calls to move(to:) and addLine(to:)? Calculations done by this library ignore all path elements constructed with move(to:) but I didn't think of addLine(to:) with zero length, which, from the librarys point of view, is basically the same. However, UIBezierPath draws zero length lines but not moveTo segments. Honestly this is a huge gotcha you found 🙈. The issue also affects mx_point(atFractionOfLength:) and quite a lot of other stuff. I'll look into this immediately. Thanks again.

CodingMeSwiftly commented 6 years ago

I've merged two PRs adressing your issue. Could you verify it's working for you?

jerryhalstead commented 6 years ago

Seems to do the trick, thanks!