module Diagrams.TwoD.Vector
(
unitX, unitY, unit_X, unit_Y
, xDir, yDir
, angleV, angleDir, e, signedAngleBetween, signedAngleBetweenDirs
, perp, leftTurn, cross2
) where
import Control.Lens (view, (&), (.~), (^.))
import Diagrams.Angle
import Diagrams.Direction
import Diagrams.TwoD.Types
import Linear.Metric
import Linear.V2
import Linear.Vector
unitX :: (R1 v, Additive v, Num n) => v n
unitX = zero & _x .~ 1
unit_X :: (R1 v, Additive v, Num n) => v n
unit_X = zero & _x .~ (1)
unitY :: (R2 v, Additive v, Num n) => v n
unitY = zero & _y .~ 1
unit_Y :: (R2 v, Additive v, Num n) => v n
unit_Y = zero & _y .~ (1)
xDir :: (R1 v, Additive v, Num n) => Direction v n
xDir = dir unitX
yDir :: (R2 v, Additive v, Num n) => Direction v n
yDir = dir unitY
angleDir :: Floating n => Angle n -> Direction V2 n
angleDir = dir . angleV
angleV :: Floating n => Angle n -> V2 n
angleV = angle . view rad
e :: Floating n => Angle n -> V2 n
e = angleV
leftTurn :: (Num n, Ord n) => V2 n -> V2 n -> Bool
leftTurn v1 v2 = (v1 `dot` perp v2) < 0
cross2 :: Num n => V2 n -> V2 n -> n
cross2 (V2 x1 y1) (V2 x2 y2) = x1 * y2 y1 * x2
signedAngleBetween :: RealFloat n => V2 n -> V2 n -> Angle n
signedAngleBetween u v = (u ^. _theta) ^-^ (v ^. _theta)
signedAngleBetweenDirs :: RealFloat n => Direction V2 n -> Direction V2 n -> Angle n
signedAngleBetweenDirs u v = (u ^. _theta) ^-^ (v ^. _theta)