first of all: thank you for sharing this amazing piece of code with us.
I noticed that cy::CubicRoots contains a division by zero if coef[3] equals zero. One of the roots then becomes infinity and won't count towards the correct number of roots. It would be better to check for this situation and call cy::QuadraticRoots instead.
Steps to reproduce:
Construct a cubic curve using points P0 = Vec2(10, 10), P1 = Vec2(70, 10), P2 = Vec2(100, 40) and P3 = Vec2(100, 100).
Calculate the coefficients for a horizontal line through P0:
Hi Cem,
first of all: thank you for sharing this amazing piece of code with us.
I noticed that
cy::CubicRoots
contains a division by zero ifcoef[3]
equals zero. One of the roots then becomes infinity and won't count towards the correct number of roots. It would be better to check for this situation and callcy::QuadraticRoots
instead.Steps to reproduce:
P0 = Vec2(10, 10)
,P1 = Vec2(70, 10)
,P2 = Vec2(100, 40)
andP3 = Vec2(100, 100)
.P0
:cy::CubicRoots
, the value ofdelta_4
becomes8100
, butrv0
now contains a division by zeroftype rv0 = q / a
.0.0
.cy::QuadraticRoots
with the same coefficients instead, it yields the proper result.It's easy enough for me to do something like:
, but it would be better if cyCodeBase does this check for us.
Is this something you could change, or are there reasons not to?