mozman / ezdxf

Python interface to DXF
https://ezdxf.mozman.at
MIT License
926 stars 190 forks source link

Divide by zero error #394

Closed DanielLundDev closed 3 years ago

DanielLundDev commented 3 years ago

I've run across an issue while using the to_splines_and_polylines functionality.

In have_bezier_curves_g1_continuity there are calls to normalize te = (b1_pnts[-1] - b1_pnts[-2]).normalize() and ts = (b2_pnts[1] - b2_pnts[0]).normalize()

If the points are equal you get a vec3 of 0,0,0 with a magnitude of 0 This causes normalize to crash with a divide by 0 error

Thanks!

mozman commented 3 years ago

Please show me your data, because your are dealing with degenerated bezier curves with coincident control points (p0 == p1 or p2==p3). What was the source of the bezier curves or how were they created.

mozman commented 3 years ago

I just treated the symptom not the disease! Please provide your data or your code. I want to know where this degenerated bezier curves were created.

DanielLundDev commented 3 years ago

I wrote up a quick example

test.zip

mozman commented 3 years ago

Thank you for this exceptional example.

I added a check to add linear Bèzier curves as LINE_TO commands, which creates straight line segments for this example:

image

It is an improvement but not perfect as you can see at the location X, with two consecutive LINE_TO commands. The triangles are the markers of the LWPOLYLINE segments.

Nice to see, that some developers can read the documentation or the source code or at least can find the examples ;).