Start work on crafting/combinations

This commit is contained in:
2021-12-02 00:50:29 +00:00
parent ce06845278
commit 85ededc158
28 changed files with 189 additions and 112 deletions
+10 -3
View File
@@ -108,10 +108,17 @@ vNormal (V2 x y) = V2 y (negate x)
vInverse :: Point2 -> Point2
vInverse (V2 x y) = V2 (-x) (-y)
{- | Normalize a vector safely: on (0,0) return (0,0). -}
safeNormalizeV :: Point2 -> Point2
squashNormalizeV :: Point2 -> Point2
{-# INLINE squashNormalizeV #-}
squashNormalizeV p
| magV p == 0 = V2 0 0
| otherwise = (1/magV p ) *.* p
{- | Normalize a vector safely: on (0,0) return Nothing. -}
safeNormalizeV :: Point2 -> Maybe Point2
{-# INLINE safeNormalizeV #-}
safeNormalizeV (V2 0 0) = V2 0 0
safeNormalizeV p = (1/magV p ) *.* p
safeNormalizeV p
| magV p == 0 = Nothing
| otherwise = Just $ (1/magV p ) *.* p
{- | Magnitude of a vector. -}
magV :: Point2 -> Float
{-# INLINE magV #-}