tamasmeszaros/libnest2d

crash: division by 0

supermerill opened this issue · 0 comments

Hello
I had a division by 0 in the geometry_traits_nfp:l285
the reason is that lsq1 is equal to 0 because e1.second() == e1.first()
I don't know if it's the intended behaviour or not.
I fixed it by replacing

            auto pcos1 = Ratio(lcos[0]) / lsq1 * sign * lcos[0];
            auto pcos2 = Ratio(lcos[1]) / lsq2 * sign * lcos[1];

by

            auto pcos1 = lsq1 != 0 ? Ratio(lcos[0]) / lsq1 * sign * lcos[0] : 1 * sign * lcos[0];
            auto pcos2 = lsq2 != 0 ? Ratio(lcos[1]) / lsq2 * sign * lcos[1] : 1 * sign * lcos[1];

Or maybe add an assert to test the input if it's the intended behaviour.