alexbol99 / flatten-js

Javascript library for 2d geometry
MIT License
564 stars 58 forks source link

feature request: isZeroLength for Vector #203

Open ensconced opened 3 days ago

ensconced commented 3 days ago

Segment has an isZeroLength method - would it make sense to add the same for Vector?

Of couse I can do vec.length === 0, but this involves an expensive Math.sqrt. I can do vec.dot(vec) === 0 to avoid the sqrt, but this somewhat less readable.

ensconced commented 3 days ago

Alternatively, maybe we could have a lengthSquared method - that would also serve cases where vectors need to be compared by length, and the overhead of the sqrt is not necessary