{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
module Data.Point2
( Point2(..)
, point2X
, point2Y
)
where
import Control.DeepSeq (NFData(..))
import Data.AffineSpace
import Data.Vector2
import Data.VectorSpace ()
data Point2 a = RealFloat a => Point2 !a !a
deriving instance Eq a => Eq (Point2 a)
deriving instance Show a => Show (Point2 a)
instance NFData a => NFData (Point2 a) where
rnf :: Point2 a -> ()
rnf (Point2 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` ()
point2X :: RealFloat a => Point2 a -> a
point2X :: forall a. RealFloat a => Point2 a -> a
point2X (Point2 a
x a
_) = a
x
point2Y :: RealFloat a => Point2 a -> a
point2Y :: forall a. RealFloat a => Point2 a -> a
point2Y (Point2 a
_ a
y) = a
y
instance RealFloat a => AffineSpace (Point2 a) (Vector2 a) a where
origin :: Point2 a
origin = forall a. RealFloat a => a -> a -> Point2 a
Point2 a
0 a
0
(Point2 a
x a
y) .+^ :: Point2 a -> Vector2 a -> Point2 a
.+^ Vector2 a
v = forall a. RealFloat a => a -> a -> Point2 a
Point2 (a
x forall a. Num a => a -> a -> a
+ forall a. RealFloat a => Vector2 a -> a
vector2X Vector2 a
v) (a
y forall a. Num a => a -> a -> a
+ forall a. RealFloat a => Vector2 a -> a
vector2Y Vector2 a
v)
(Point2 a
x a
y) .-^ :: Point2 a -> Vector2 a -> Point2 a
.-^ Vector2 a
v = forall a. RealFloat a => a -> a -> Point2 a
Point2 (a
x forall a. Num a => a -> a -> a
- forall a. RealFloat a => Vector2 a -> a
vector2X Vector2 a
v) (a
y forall a. Num a => a -> a -> a
- forall a. RealFloat a => Vector2 a -> a
vector2Y Vector2 a
v)
(Point2 a
x1 a
y1) .-. :: Point2 a -> Point2 a -> Vector2 a
.-. (Point2 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)