d3 / d3-shape

Graphical primitives for visualization, such as lines and areas.
https://d3js.org/d3-shape
ISC License
2.47k stars 307 forks source link

Fix #90 - Clamp acos when computing rounded corners #91

Closed sftrabbit closed 7 years ago

sftrabbit commented 7 years ago

Due to floating point imprecision, computing the angle between two vectors with theta = acos((a . b) / sqrt(|a||b|)) gives NaN when (a . b) / sqrt(|a||b|) is outside the domain of acos. We can use a clamped version of acos to avoid this, which clamps to [-1, 1].

sftrabbit commented 7 years ago

As I mentioned in the corresponding issue, it would be great if this could also be fixed in D3 v3, where the fix is simply to change the call to Math.acos in src/svg/arc.js to d3_acos (which already exists and is imported).

mbostock commented 7 years ago

Great, thanks!

With apologies, but there will be no future releases of v3.