Haskell-Things / ImplicitCAD

A math-inspired CAD program in haskell. CSG, bevels, and shells; 2D & 3D geometry; 2D gcode generation...
https://implicitcad.org/
GNU Affero General Public License v3.0
1.39k stars 142 forks source link

rotateExtrude crashes for totalRotation < 180 degrees #307

Closed isovector closed 3 years ago

isovector commented 3 years ago
main :: IO ()
main = writeSTL 0.5 "/tmp/inrads.stl" $
  rotateExtrude
    179
    Nothing
    (Left (0, 5))
    (Left 0) $
      translate (10, 0) $ rectR 0 0 3
> main
*** Exception: Prelude.minimum: empty list

The same program works fine when 179 is replaced with 180.

isovector commented 3 years ago

I did some digging into this. The issue is here:

https://github.com/colah/ImplicitCAD/blob/aea51dd6b61473d76e0ef4020660b63bbbcc30ca/Graphics/Implicit/ObjectUtil/GetImplicit3.hs#L123

caused by the do block producing []. That in turn is caused by this bind failing:

https://github.com/colah/ImplicitCAD/blob/aea51dd6b61473d76e0ef4020660b63bbbcc30ca/Graphics/Implicit/ObjectUtil/GetImplicit3.hs#L134

because ns is an empty list:

https://github.com/colah/ImplicitCAD/blob/aea51dd6b61473d76e0ef4020660b63bbbcc30ca/Graphics/Implicit/ObjectUtil/GetImplicit3.hs#L128-L133

So the question is --- what the hell is ns trying to compute?

isovector commented 3 years ago

When the crash above happens, the locals are:

x = -15.6
y = 0.24761904761904674
totalRotation = 179.0
totalRotation' = 3.12413936106985
θ = 3.125720970598003

and (totalRotation' - θ) / tau is -2.5172097444680865e-4.

isovector commented 3 years ago

This x value is weird. The rect is from (10,0) to (13,3), so x = -15.6 should be completely outside of the object in question.