ianmackenzie / elm-geometry

2D/3D geometry package for Elm
Mozilla Public License 2.0
183 stars 26 forks source link

Investigate accuracy of axis/plane intersections #112

Closed ianmackenzie closed 4 years ago

ianmackenzie commented 4 years ago

Fuzz tests sometimes show error creeping up above 1e-12; may not actually be possible to improve but should be checked.

ianmackenzie commented 4 years ago

Sample error as reported by @matyjas:

 ↓ Tests.Axis3d
 ✗ intersectionWithPlane works properly

 Given (Axis3d { direction = Direction3d { x = 0.7310653855963402, y = 0.6789406235236046, z = 0.06769809238267588 }, originPoint = Point3d { x = 0.000001, y = 0.000001, z = 0.000001 } },Plane3d { normalDirection = Direction3d { x = -0.4716854275417519, y = 0.4297095022248174, z = 0.7699757146445947 }, originPoint = Point3d { x = 0.000001, y = 7.142710360026999, z = 0 } })

     1.0184335716967847e-12
     ╷
     │ Expect.within AbsoluteOrRelative 1e-12 1e-12
     ╵
     0
matyjas commented 4 years ago

Bumped into another instance of this test failing, reproduce with: elm-test --seed 63090040233875

ianmackenzie commented 4 years ago

I took a look at the test code and I think it's just occasionally hitting cases with almost-parallel axes and planes, such that the intersection point is very far away from either origin point (in which case it's not reasonable to expect high accuracy for the intersection point). I've added in a bit of logic to just discard those sorts of really pathological cases - hopefully that should be enough, so I'll close this issue for now.