{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
{-# LANGUAGE ExistentialQuantification, MultiParamTypeClasses, FlexibleInstances, StandaloneDeriving #-}
module Data.Vector2 (
Vector2,
vector2,
vector2X,
vector2Y,
vector2XY,
vector2Polar,
vector2Rho,
vector2Theta,
vector2RhoTheta,
vector2Rotate
) where
import Control.DeepSeq (NFData(..))
import Data.VectorSpace
data Vector2 a = RealFloat a => Vector2 !a !a
deriving instance Eq a => Eq (Vector2 a)
deriving instance Show a => Show (Vector2 a)
instance NFData a => NFData (Vector2 a) where
rnf :: Vector2 a -> ()
rnf (Vector2 a
x a
y) = forall a. NFData a => a -> ()
rnf a
x seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf a
y seq :: forall a b. a -> b -> b
`seq` ()
vector2 :: RealFloat a => a -> a -> Vector2 a
vector2 :: forall a. RealFloat a => a -> a -> Vector2 a
vector2 = forall a. RealFloat a => a -> a -> Vector2 a
Vector2
vector2X :: RealFloat a => Vector2 a -> a
vector2X :: forall a. RealFloat a => Vector2 a -> a
vector2X (Vector2 a
x a
_) = a
x
vector2Y :: RealFloat a => Vector2 a -> a
vector2Y :: forall a. RealFloat a => Vector2 a -> a
vector2Y (Vector2 a
_ a
y) = a
y
vector2XY :: RealFloat a => Vector2 a -> (a, a)
vector2XY :: forall a. RealFloat a => Vector2 a -> (a, a)
vector2XY (Vector2 a
x a
y) = (a
x, a
y)
vector2Polar :: RealFloat a => a -> a -> Vector2 a
vector2Polar :: forall a. RealFloat a => a -> a -> Vector2 a
vector2Polar a
rho a
theta = forall a. RealFloat a => a -> a -> Vector2 a
Vector2 (a
rho forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
cos a
theta) (a
rho forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
sin a
theta)
vector2Rho :: RealFloat a => Vector2 a -> a
vector2Rho :: forall a. RealFloat a => Vector2 a -> a
vector2Rho (Vector2 a
x a
y) = forall a. Floating a => a -> a
sqrt (a
x forall a. Num a => a -> a -> a
* a
x forall a. Num a => a -> a -> a
+ a
y forall a. Num a => a -> a -> a
* a
y)
vector2Theta :: RealFloat a => Vector2 a -> a
vector2Theta :: forall a. RealFloat a => Vector2 a -> a
vector2Theta (Vector2 a
x a
y) = forall a. RealFloat a => a -> a -> a
atan2 a
y a
x
vector2RhoTheta :: RealFloat a => Vector2 a -> (a, a)
vector2RhoTheta :: forall a. RealFloat a => Vector2 a -> (a, a)
vector2RhoTheta Vector2 a
v = (forall a. RealFloat a => Vector2 a -> a
vector2Rho Vector2 a
v, forall a. RealFloat a => Vector2 a -> a
vector2Theta Vector2 a
v)
instance RealFloat a => VectorSpace (Vector2 a) a where
zeroVector :: Vector2 a
zeroVector = forall a. RealFloat a => a -> a -> Vector2 a
Vector2 a
0 a
0
a
a *^ :: a -> Vector2 a -> Vector2 a
*^ (Vector2 a
x a
y) = forall a. RealFloat a => a -> a -> Vector2 a
Vector2 (a
a forall a. Num a => a -> a -> a
* a
x) (a
a forall a. Num a => a -> a -> a
* a
y)
(Vector2 a
x a
y) ^/ :: Vector2 a -> a -> Vector2 a
^/ a
a = forall a. RealFloat a => a -> a -> Vector2 a
Vector2 (a
x forall a. Fractional a => a -> a -> a
/ a
a) (a
y forall a. Fractional a => a -> a -> a
/ a
a)
negateVector :: Vector2 a -> Vector2 a
negateVector (Vector2 a
x a
y) = (forall a. RealFloat a => a -> a -> Vector2 a
Vector2 (-a
x) (-a
y))
(Vector2 a
x1 a
y1) ^+^ :: Vector2 a -> Vector2 a -> Vector2 a
^+^ (Vector2 a
x2 a
y2) = forall a. RealFloat a => a -> a -> Vector2 a
Vector2 (a
x1 forall a. Num a => a -> a -> a
+ a
x2) (a
y1 forall a. Num a => a -> a -> a
+ a
y2)
(Vector2 a
x1 a
y1) ^-^ :: Vector2 a -> Vector2 a -> Vector2 a
^-^ (Vector2 a
x2 a
y2) = forall a. RealFloat a => a -> a -> Vector2 a
Vector2 (a
x1 forall a. Num a => a -> a -> a
- a
x2) (a
y1 forall a. Num a => a -> a -> a
- a
y2)
(Vector2 a
x1 a
y1) dot :: Vector2 a -> Vector2 a -> a
`dot` (Vector2 a
x2 a
y2) = a
x1 forall a. Num a => a -> a -> a
* a
x2 forall a. Num a => a -> a -> a
+ a
y1 forall a. Num a => a -> a -> a
* a
y2
vector2Rotate :: RealFloat a => a -> Vector2 a -> Vector2 a
vector2Rotate :: forall a. RealFloat a => a -> Vector2 a -> Vector2 a
vector2Rotate a
theta' Vector2 a
v = forall a. RealFloat a => a -> a -> Vector2 a
vector2Polar (forall a. RealFloat a => Vector2 a -> a
vector2Rho Vector2 a
v) (forall a. RealFloat a => Vector2 a -> a
vector2Theta Vector2 a
v forall a. Num a => a -> a -> a
+ a
theta')