{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
{-# LANGUAGE ExistentialQuantification, MultiParamTypeClasses, FlexibleInstances, StandaloneDeriving #-}
module Data.Point3 (
Point3(..),
point3X,
point3Y,
point3Z
) where
import Control.DeepSeq (NFData(..))
import Data.VectorSpace ()
import Data.AffineSpace
import Data.Vector3
data Point3 a = RealFloat a => Point3 !a !a !a
deriving instance Eq a => Eq (Point3 a)
deriving instance Show a => Show (Point3 a)
instance NFData a => NFData (Point3 a) where
rnf :: Point3 a -> ()
rnf (Point3 a
x a
y a
z) = 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` forall a. NFData a => a -> ()
rnf a
z seq :: forall a b. a -> b -> b
`seq` ()
point3X :: RealFloat a => Point3 a -> a
point3X :: forall a. RealFloat a => Point3 a -> a
point3X (Point3 a
x a
_ a
_) = a
x
point3Y :: RealFloat a => Point3 a -> a
point3Y :: forall a. RealFloat a => Point3 a -> a
point3Y (Point3 a
_ a
y a
_) = a
y
point3Z :: RealFloat a => Point3 a -> a
point3Z :: forall a. RealFloat a => Point3 a -> a
point3Z (Point3 a
_ a
_ a
z) = a
z
instance RealFloat a => AffineSpace (Point3 a) (Vector3 a) a where
origin :: Point3 a
origin = forall a. RealFloat a => a -> a -> a -> Point3 a
Point3 a
0 a
0 a
0
(Point3 a
x a
y a
z) .+^ :: Point3 a -> Vector3 a -> Point3 a
.+^ Vector3 a
v =
forall a. RealFloat a => a -> a -> a -> Point3 a
Point3 (a
x forall a. Num a => a -> a -> a
+ forall a. RealFloat a => Vector3 a -> a
vector3X Vector3 a
v) (a
y forall a. Num a => a -> a -> a
+ forall a. RealFloat a => Vector3 a -> a
vector3Y Vector3 a
v) (a
z forall a. Num a => a -> a -> a
+ forall a. RealFloat a => Vector3 a -> a
vector3Z Vector3 a
v)
(Point3 a
x a
y a
z) .-^ :: Point3 a -> Vector3 a -> Point3 a
.-^ Vector3 a
v =
forall a. RealFloat a => a -> a -> a -> Point3 a
Point3 (a
x forall a. Num a => a -> a -> a
- forall a. RealFloat a => Vector3 a -> a
vector3X Vector3 a
v) (a
y forall a. Num a => a -> a -> a
- forall a. RealFloat a => Vector3 a -> a
vector3Y Vector3 a
v) (a
z forall a. Num a => a -> a -> a
- forall a. RealFloat a => Vector3 a -> a
vector3Z Vector3 a
v)
(Point3 a
x1 a
y1 a
z1) .-. :: Point3 a -> Point3 a -> Vector3 a
.-. (Point3 a
x2 a
y2 a
z2) =
forall a. RealFloat a => a -> a -> a -> Vector3 a
vector3 (a
x1 forall a. Num a => a -> a -> a
- a
x2) (a
y1 forall a. Num a => a -> a -> a
- a
y2) (a
z1 forall a. Num a => a -> a -> a
- a
z2)