{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveLift #-}

#ifndef MIN_VERSION_hashable
#define MIN_VERSION_hashable(x,y,z) 1
#endif

#ifndef MIN_VERSION_vector
#define MIN_VERSION_vector(x,y,z) 1
#endif

#ifndef MIN_VERSION_transformers
#define MIN_VERSION_transformers(x,y,z) 1
#endif

-----------------------------------------------------------------------------

-- |

-- Copyright   :  (C) 2012-2015 Edward Kmett

-- License     :  BSD-style (see the file LICENSE)

--

-- Maintainer  :  Edward Kmett <ekmett@gmail.com>

-- Stability   :  experimental

-- Portability :  non-portable

--

-- 3-D Vectors

----------------------------------------------------------------------------

module Linear.V3
  ( V3(..)
  , cross, triple
  , R1(..)
  , R2(..)
  , _yx
  , R3(..)
  , _xz, _yz, _zx, _zy
  , _xzy, _yxz, _yzx, _zxy, _zyx
  , ex, ey, ez
  ) where

import Control.Applicative
import Control.DeepSeq (NFData(rnf))
import Control.Monad (liftM)
import Control.Monad.Fix
import Control.Monad.Zip
import Control.Lens as Lens hiding ((<.>))
import Data.Binary as Binary -- binary

import Data.Bytes.Serial -- bytes

import Data.Data
import Data.Distributive
import Data.Foldable
import qualified Data.Foldable.WithIndex as WithIndex
import Data.Functor.Bind
import Data.Functor.Classes
import Data.Functor.Rep
import qualified Data.Functor.WithIndex as WithIndex
import Data.Hashable
import Data.Hashable.Lifted
#if !(MIN_VERSION_base(4,11,0))
import Data.Semigroup
#endif
import Data.Semigroup.Foldable
import Data.Serialize as Cereal -- cereal

import qualified Data.Traversable.WithIndex as WithIndex
import qualified Data.Vector as V
import qualified Data.Vector.Generic.Mutable as M
import qualified Data.Vector.Generic as G
import qualified Data.Vector.Unboxed.Base as U
import Foreign.Ptr (castPtr)
import Foreign.Storable (Storable(..))
import GHC.Arr (Ix(..))
import GHC.Generics (Generic, Generic1)
#if defined(MIN_VERSION_template_haskell)
import Language.Haskell.TH.Syntax (Lift)
#endif
import Linear.Epsilon
import Linear.Metric
import Linear.V
import Linear.V2
import Linear.Vector
import System.Random (Random(..))

-- $setup

-- >>> import Control.Lens hiding (index)


-- | A 3-dimensional vector

data V3 a = V3 !a !a !a deriving (V3 a -> V3 a -> Bool
forall a. Eq a => V3 a -> V3 a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: V3 a -> V3 a -> Bool
$c/= :: forall a. Eq a => V3 a -> V3 a -> Bool
== :: V3 a -> V3 a -> Bool
$c== :: forall a. Eq a => V3 a -> V3 a -> Bool
Eq,V3 a -> V3 a -> Bool
V3 a -> V3 a -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (V3 a)
forall a. Ord a => V3 a -> V3 a -> Bool
forall a. Ord a => V3 a -> V3 a -> Ordering
forall a. Ord a => V3 a -> V3 a -> V3 a
min :: V3 a -> V3 a -> V3 a
$cmin :: forall a. Ord a => V3 a -> V3 a -> V3 a
max :: V3 a -> V3 a -> V3 a
$cmax :: forall a. Ord a => V3 a -> V3 a -> V3 a
>= :: V3 a -> V3 a -> Bool
$c>= :: forall a. Ord a => V3 a -> V3 a -> Bool
> :: V3 a -> V3 a -> Bool
$c> :: forall a. Ord a => V3 a -> V3 a -> Bool
<= :: V3 a -> V3 a -> Bool
$c<= :: forall a. Ord a => V3 a -> V3 a -> Bool
< :: V3 a -> V3 a -> Bool
$c< :: forall a. Ord a => V3 a -> V3 a -> Bool
compare :: V3 a -> V3 a -> Ordering
$ccompare :: forall a. Ord a => V3 a -> V3 a -> Ordering
Ord,Int -> V3 a -> ShowS
forall a. Show a => Int -> V3 a -> ShowS
forall a. Show a => [V3 a] -> ShowS
forall a. Show a => V3 a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [V3 a] -> ShowS
$cshowList :: forall a. Show a => [V3 a] -> ShowS
show :: V3 a -> String
$cshow :: forall a. Show a => V3 a -> String
showsPrec :: Int -> V3 a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> V3 a -> ShowS
Show,ReadPrec [V3 a]
ReadPrec (V3 a)
ReadS [V3 a]
forall a. Read a => ReadPrec [V3 a]
forall a. Read a => ReadPrec (V3 a)
forall a. Read a => Int -> ReadS (V3 a)
forall a. Read a => ReadS [V3 a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [V3 a]
$creadListPrec :: forall a. Read a => ReadPrec [V3 a]
readPrec :: ReadPrec (V3 a)
$creadPrec :: forall a. Read a => ReadPrec (V3 a)
readList :: ReadS [V3 a]
$creadList :: forall a. Read a => ReadS [V3 a]
readsPrec :: Int -> ReadS (V3 a)
$creadsPrec :: forall a. Read a => Int -> ReadS (V3 a)
Read,V3 a -> DataType
V3 a -> Constr
forall {a}. Data a => Typeable (V3 a)
forall a. Data a => V3 a -> DataType
forall a. Data a => V3 a -> Constr
forall a. Data a => (forall b. Data b => b -> b) -> V3 a -> V3 a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> V3 a -> u
forall a u. Data a => (forall d. Data d => d -> u) -> V3 a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> V3 a -> r
forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> V3 a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> V3 a -> m (V3 a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> V3 a -> m (V3 a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (V3 a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> V3 a -> c (V3 a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (V3 a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (V3 a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (V3 a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> V3 a -> c (V3 a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (V3 a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> V3 a -> m (V3 a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> V3 a -> m (V3 a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> V3 a -> m (V3 a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> V3 a -> m (V3 a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> V3 a -> m (V3 a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> V3 a -> m (V3 a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> V3 a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> V3 a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> V3 a -> [u]
$cgmapQ :: forall a u. Data a => (forall d. Data d => d -> u) -> V3 a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> V3 a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> V3 a -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> V3 a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> V3 a -> r
gmapT :: (forall b. Data b => b -> b) -> V3 a -> V3 a
$cgmapT :: forall a. Data a => (forall b. Data b => b -> b) -> V3 a -> V3 a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (V3 a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (V3 a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (V3 a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (V3 a))
dataTypeOf :: V3 a -> DataType
$cdataTypeOf :: forall a. Data a => V3 a -> DataType
toConstr :: V3 a -> Constr
$ctoConstr :: forall a. Data a => V3 a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (V3 a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (V3 a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> V3 a -> c (V3 a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> V3 a -> c (V3 a)
Data
                                 ,forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (V3 a) x -> V3 a
forall a x. V3 a -> Rep (V3 a) x
$cto :: forall a x. Rep (V3 a) x -> V3 a
$cfrom :: forall a x. V3 a -> Rep (V3 a) x
Generic,forall a. Rep1 V3 a -> V3 a
forall a. V3 a -> Rep1 V3 a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cto1 :: forall a. Rep1 V3 a -> V3 a
$cfrom1 :: forall a. V3 a -> Rep1 V3 a
Generic1
#if defined(MIN_VERSION_template_haskell)
                                 ,forall a (m :: * -> *). (Lift a, Quote m) => V3 a -> m Exp
forall a (m :: * -> *). (Lift a, Quote m) => V3 a -> Code m (V3 a)
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => V3 a -> m Exp
forall (m :: * -> *). Quote m => V3 a -> Code m (V3 a)
liftTyped :: forall (m :: * -> *). Quote m => V3 a -> Code m (V3 a)
$cliftTyped :: forall a (m :: * -> *). (Lift a, Quote m) => V3 a -> Code m (V3 a)
lift :: forall (m :: * -> *). Quote m => V3 a -> m Exp
$clift :: forall a (m :: * -> *). (Lift a, Quote m) => V3 a -> m Exp
Lift
#endif
                                 )

instance Finite V3 where
  type Size V3 = 3
  toV :: forall a. V3 a -> V (Size V3) a
toV (V3 a
a a
b a
c) = forall {k} (n :: k) a. Vector a -> V n a
V (forall a. Int -> [a] -> Vector a
V.fromListN Int
3 [a
a,a
b,a
c])
  fromV :: forall a. V (Size V3) a -> V3 a
fromV (V Vector a
v) = forall a. a -> a -> a -> V3 a
V3 (Vector a
v forall a. Vector a -> Int -> a
V.! Int
0) (Vector a
v forall a. Vector a -> Int -> a
V.! Int
1) (Vector a
v forall a. Vector a -> Int -> a
V.! Int
2)

instance Functor V3 where
  fmap :: forall a b. (a -> b) -> V3 a -> V3 b
fmap a -> b
f (V3 a
a a
b a
c) = forall a. a -> a -> a -> V3 a
V3 (a -> b
f a
a) (a -> b
f a
b) (a -> b
f a
c)
  {-# INLINE fmap #-}
  a
a <$ :: forall a b. a -> V3 b -> V3 a
<$ V3 b
_ = forall a. a -> a -> a -> V3 a
V3 a
a a
a a
a
  {-# INLINE (<$) #-}

instance Foldable V3 where
  foldMap :: forall m a. Monoid m => (a -> m) -> V3 a -> m
foldMap a -> m
f (V3 a
a a
b a
c) = a -> m
f a
a forall a. Monoid a => a -> a -> a
`mappend` a -> m
f a
b forall a. Monoid a => a -> a -> a
`mappend` a -> m
f a
c
  {-# INLINE foldMap #-}
#if MIN_VERSION_base(4,13,0)
  foldMap' :: forall m a. Monoid m => (a -> m) -> V3 a -> m
foldMap' a -> m
f (V3 a
a a
b a
c) = (a -> m
f a
a forall a. Monoid a => a -> a -> a
`mappend` a -> m
f a
b) forall a. Monoid a => a -> a -> a
`mappend` a -> m
f a
c
  {-# INLINE foldMap' #-}
#endif
  null :: forall a. V3 a -> Bool
null V3 a
_ = Bool
False
  length :: forall a. V3 a -> Int
length V3 a
_ = Int
3

instance Random a => Random (V3 a) where
  random :: forall g. RandomGen g => g -> (V3 a, g)
random g
g = case forall a g. (Random a, RandomGen g) => g -> (a, g)
random g
g of
    (a
a, g
g') -> case forall a g. (Random a, RandomGen g) => g -> (a, g)
random g
g' of
      (a
b, g
g'') -> case forall a g. (Random a, RandomGen g) => g -> (a, g)
random g
g'' of
        (a
c, g
g''') -> (forall a. a -> a -> a -> V3 a
V3 a
a a
b a
c, g
g''')
  randomR :: forall g. RandomGen g => (V3 a, V3 a) -> g -> (V3 a, g)
randomR (V3 a
a a
b a
c, V3 a
a' a
b' a
c') g
g = case forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a
a,a
a') g
g of
    (a
a'', g
g') -> case forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a
b,a
b') g
g' of
      (a
b'', g
g'') -> case forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a
c,a
c') g
g'' of
        (a
c'', g
g''') -> (forall a. a -> a -> a -> V3 a
V3 a
a'' a
b'' a
c'', g
g''')

instance Traversable V3 where
  traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> V3 a -> f (V3 b)
traverse a -> f b
f (V3 a
a a
b a
c) = forall a. a -> a -> a -> V3 a
V3 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
b forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
c
  {-# INLINE traverse #-}

instance Foldable1 V3 where
  foldMap1 :: forall m a. Semigroup m => (a -> m) -> V3 a -> m
foldMap1 a -> m
f (V3 a
a a
b a
c) = a -> m
f a
a forall a. Semigroup a => a -> a -> a
<> a -> m
f a
b forall a. Semigroup a => a -> a -> a
<> a -> m
f a
c
  {-# INLINE foldMap1 #-}

instance Traversable1 V3 where
  traverse1 :: forall (f :: * -> *) a b. Apply f => (a -> f b) -> V3 a -> f (V3 b)
traverse1 a -> f b
f (V3 a
a a
b a
c) = forall a. a -> a -> a -> V3 a
V3 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> a -> f b
f a
b forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> a -> f b
f a
c
  {-# INLINE traverse1 #-}

instance Apply V3 where
  V3 a -> b
a a -> b
b a -> b
c <.> :: forall a b. V3 (a -> b) -> V3 a -> V3 b
<.> V3 a
d a
e a
f = forall a. a -> a -> a -> V3 a
V3 (a -> b
a a
d) (a -> b
b a
e) (a -> b
c a
f)
  {-# INLINE (<.>) #-}

instance Applicative V3 where
  pure :: forall a. a -> V3 a
pure a
a = forall a. a -> a -> a -> V3 a
V3 a
a a
a a
a
  {-# INLINE pure #-}
  V3 a -> b
a a -> b
b a -> b
c <*> :: forall a b. V3 (a -> b) -> V3 a -> V3 b
<*> V3 a
d a
e a
f = forall a. a -> a -> a -> V3 a
V3 (a -> b
a a
d) (a -> b
b a
e) (a -> b
c a
f)
  {-# INLINE (<*>) #-}

instance Additive V3 where
  zero :: forall a. Num a => V3 a
zero = forall (f :: * -> *) a. Applicative f => a -> f a
pure a
0
  {-# INLINE zero #-}
  liftU2 :: forall a. (a -> a -> a) -> V3 a -> V3 a -> V3 a
liftU2 = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2
  {-# INLINE liftU2 #-}
  liftI2 :: forall a b c. (a -> b -> c) -> V3 a -> V3 b -> V3 c
liftI2 = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2
  {-# INLINE liftI2 #-}

instance Bind V3 where
  V3 a
a a
b a
c >>- :: forall a b. V3 a -> (a -> V3 b) -> V3 b
>>- a -> V3 b
f = forall a. a -> a -> a -> V3 a
V3 b
a' b
b' b
c' where
    V3 b
a' b
_ b
_ = a -> V3 b
f a
a
    V3 b
_ b
b' b
_ = a -> V3 b
f a
b
    V3 b
_ b
_ b
c' = a -> V3 b
f a
c
  {-# INLINE (>>-) #-}

instance Monad V3 where
#if !(MIN_VERSION_base(4,11,0))
  return a = V3 a a a
  {-# INLINE return #-}
#endif
  V3 a
a a
b a
c >>= :: forall a b. V3 a -> (a -> V3 b) -> V3 b
>>= a -> V3 b
f = forall a. a -> a -> a -> V3 a
V3 b
a' b
b' b
c' where
    V3 b
a' b
_ b
_ = a -> V3 b
f a
a
    V3 b
_ b
b' b
_ = a -> V3 b
f a
b
    V3 b
_ b
_ b
c' = a -> V3 b
f a
c
  {-# INLINE (>>=) #-}

instance Num a => Num (V3 a) where
  + :: V3 a -> V3 a -> V3 a
(+) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Num a => a -> a -> a
(+)
  {-# INLINE (+) #-}
  (-) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (-)
  {-# INLINE (-) #-}
  * :: V3 a -> V3 a -> V3 a
(*) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Num a => a -> a -> a
(*)
  {-# INLINE (*) #-}
  negate :: V3 a -> V3 a
negate = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Num a => a -> a
negate
  {-# INLINE negate #-}
  abs :: V3 a -> V3 a
abs = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Num a => a -> a
abs
  {-# INLINE abs #-}
  signum :: V3 a -> V3 a
signum = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Num a => a -> a
signum
  {-# INLINE signum #-}
  fromInteger :: Integer -> V3 a
fromInteger = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => Integer -> a
fromInteger
  {-# INLINE fromInteger #-}

instance Fractional a => Fractional (V3 a) where
  recip :: V3 a -> V3 a
recip = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Fractional a => a -> a
recip
  {-# INLINE recip #-}
  / :: V3 a -> V3 a -> V3 a
(/) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Fractional a => a -> a -> a
(/)
  {-# INLINE (/) #-}
  fromRational :: Rational -> V3 a
fromRational = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Fractional a => Rational -> a
fromRational
  {-# INLINE fromRational #-}

instance Floating a => Floating (V3 a) where
    pi :: V3 a
pi = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Floating a => a
pi
    {-# INLINE pi #-}
    exp :: V3 a -> V3 a
exp = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
exp
    {-# INLINE exp #-}
    sqrt :: V3 a -> V3 a
sqrt = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
sqrt
    {-# INLINE sqrt #-}
    log :: V3 a -> V3 a
log = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
log
    {-# INLINE log #-}
    ** :: V3 a -> V3 a -> V3 a
(**) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Floating a => a -> a -> a
(**)
    {-# INLINE (**) #-}
    logBase :: V3 a -> V3 a -> V3 a
logBase = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Floating a => a -> a -> a
logBase
    {-# INLINE logBase #-}
    sin :: V3 a -> V3 a
sin = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
sin
    {-# INLINE sin #-}
    tan :: V3 a -> V3 a
tan = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
tan
    {-# INLINE tan #-}
    cos :: V3 a -> V3 a
cos = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
cos
    {-# INLINE cos #-}
    asin :: V3 a -> V3 a
asin = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
asin
    {-# INLINE asin #-}
    atan :: V3 a -> V3 a
atan = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
atan
    {-# INLINE atan #-}
    acos :: V3 a -> V3 a
acos = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
acos
    {-# INLINE acos #-}
    sinh :: V3 a -> V3 a
sinh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
sinh
    {-# INLINE sinh #-}
    tanh :: V3 a -> V3 a
tanh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
tanh
    {-# INLINE tanh #-}
    cosh :: V3 a -> V3 a
cosh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
cosh
    {-# INLINE cosh #-}
    asinh :: V3 a -> V3 a
asinh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
asinh
    {-# INLINE asinh #-}
    atanh :: V3 a -> V3 a
atanh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
atanh
    {-# INLINE atanh #-}
    acosh :: V3 a -> V3 a
acosh = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Floating a => a -> a
acosh
    {-# INLINE acosh #-}

instance Hashable a => Hashable (V3 a) where
  hashWithSalt :: Int -> V3 a -> Int
hashWithSalt Int
s (V3 a
a a
b a
c) = Int
s forall a. Hashable a => Int -> a -> Int
`hashWithSalt` a
a forall a. Hashable a => Int -> a -> Int
`hashWithSalt` a
b forall a. Hashable a => Int -> a -> Int
`hashWithSalt` a
c
  {-# INLINE hashWithSalt #-}

instance Hashable1 V3 where
  liftHashWithSalt :: forall a. (Int -> a -> Int) -> Int -> V3 a -> Int
liftHashWithSalt Int -> a -> Int
h Int
s (V3 a
a a
b a
c) = Int
s Int -> a -> Int
`h` a
a Int -> a -> Int
`h` a
b Int -> a -> Int
`h` a
c
  {-# INLINE liftHashWithSalt #-}

instance Metric V3 where
  dot :: forall a. Num a => V3 a -> V3 a -> a
dot (V3 a
a a
b a
c) (V3 a
d a
e a
f) = a
a forall a. Num a => a -> a -> a
* a
d forall a. Num a => a -> a -> a
+ a
b forall a. Num a => a -> a -> a
* a
e forall a. Num a => a -> a -> a
+ a
c forall a. Num a => a -> a -> a
* a
f
  {-# INLINABLE dot #-}

instance Distributive V3 where
  distribute :: forall (f :: * -> *) a. Functor f => f (V3 a) -> V3 (f a)
distribute f (V3 a)
f = forall a. a -> a -> a -> V3 a
V3 (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(V3 a
x a
_ a
_) -> a
x) f (V3 a)
f) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(V3 a
_ a
y a
_) -> a
y) f (V3 a)
f) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(V3 a
_ a
_ a
z) -> a
z) f (V3 a)
f)
  {-# INLINE distribute #-}

-- | A space that distinguishes 3 orthogonal basis vectors: '_x', '_y', and '_z'. (It may have more)

class R2 t => R3 t where
  -- |

  -- >>> V3 1 2 3 ^. _z

  -- 3

  _z :: Lens' (t a) a

  _xyz :: Lens' (t a) (V3 a)

_xz, _yz, _zx, _zy :: R3 t => Lens' (t a) (V2 a)

_xz :: forall (t :: * -> *) a. R3 t => Lens' (t a) (V2 a)
_xz V2 a -> f (V2 a)
f = forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_xyz forall a b. (a -> b) -> a -> b
$ \(V3 a
a a
b a
c) -> V2 a -> f (V2 a)
f (forall a. a -> a -> V2 a
V2 a
a a
c) forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(V2 a
a' a
c') -> forall a. a -> a -> a -> V3 a
V3 a
a' a
b a
c'
{-# INLINE _xz #-}

_yz :: forall (t :: * -> *) a. R3 t => Lens' (t a) (V2 a)
_yz V2 a -> f (V2 a)
f = forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_xyz forall a b. (a -> b) -> a -> b
$ \(V3 a
a a
b a
c) -> V2 a -> f (V2 a)
f (forall a. a -> a -> V2 a
V2 a
b a
c) forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(V2 a
b' a
c') -> forall a. a -> a -> a -> V3 a
V3 a
a a
b' a
c'
{-# INLINE _yz #-}

_zx :: forall (t :: * -> *) a. R3 t => Lens' (t a) (V2 a)
_zx V2 a -> f (V2 a)
f = forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_xyz forall a b. (a -> b) -> a -> b
$ \(V3 a
a a
b a
c) -> V2 a -> f (V2 a)
f (forall a. a -> a -> V2 a
V2 a
c a
a) forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(V2 a
c' a
a') -> forall a. a -> a -> a -> V3 a
V3 a
a' a
b a
c'
{-# INLINE _zx #-}

_zy :: forall (t :: * -> *) a. R3 t => Lens' (t a) (V2 a)
_zy V2 a -> f (V2 a)
f = forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_xyz forall a b. (a -> b) -> a -> b
$ \(V3 a
a a
b a
c) -> V2 a -> f (V2 a)
f (forall a. a -> a -> V2 a
V2 a
c a
b) forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(V2 a
c' a
b') -> forall a. a -> a -> a -> V3 a
V3 a
a a
b' a
c'
{-# INLINE _zy #-}

_xzy, _yxz, _yzx, _zxy, _zyx :: R3 t => Lens' (t a) (V3 a)

_xzy :: forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_xzy V3 a -> f (V3 a)
f = forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_xyz forall a b. (a -> b) -> a -> b
$ \(V3 a
a a
b a
c) -> V3 a -> f (V3 a)
f (forall a. a -> a -> a -> V3 a
V3 a
a a
c a
b) forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(V3 a
a' a
c' a
b') -> forall a. a -> a -> a -> V3 a
V3 a
a' a
b' a
c'
{-# INLINE _xzy #-}

_yxz :: forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_yxz V3 a -> f (V3 a)
f = forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_xyz forall a b. (a -> b) -> a -> b
$ \(V3 a
a a
b a
c) -> V3 a -> f (V3 a)
f (forall a. a -> a -> a -> V3 a
V3 a
b a
a a
c) forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(V3 a
b' a
a' a
c') -> forall a. a -> a -> a -> V3 a
V3 a
a' a
b' a
c'
{-# INLINE _yxz #-}

_yzx :: forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_yzx V3 a -> f (V3 a)
f = forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_xyz forall a b. (a -> b) -> a -> b
$ \(V3 a
a a
b a
c) -> V3 a -> f (V3 a)
f (forall a. a -> a -> a -> V3 a
V3 a
b a
c a
a) forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(V3 a
b' a
c' a
a') -> forall a. a -> a -> a -> V3 a
V3 a
a' a
b' a
c'
{-# INLINE _yzx #-}

_zxy :: forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_zxy V3 a -> f (V3 a)
f = forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_xyz forall a b. (a -> b) -> a -> b
$ \(V3 a
a a
b a
c) -> V3 a -> f (V3 a)
f (forall a. a -> a -> a -> V3 a
V3 a
c a
a a
b) forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(V3 a
c' a
a' a
b') -> forall a. a -> a -> a -> V3 a
V3 a
a' a
b' a
c'
{-# INLINE _zxy #-}

_zyx :: forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_zyx V3 a -> f (V3 a)
f = forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_xyz forall a b. (a -> b) -> a -> b
$ \(V3 a
a a
b a
c) -> V3 a -> f (V3 a)
f (forall a. a -> a -> a -> V3 a
V3 a
c a
b a
a) forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(V3 a
c' a
b' a
a') -> forall a. a -> a -> a -> V3 a
V3 a
a' a
b' a
c'
{-# INLINE _zyx #-}

ez :: R3 t => E t
ez :: forall (t :: * -> *). R3 t => E t
ez = forall (t :: * -> *). (forall x. Lens' (t x) x) -> E t
E forall (t :: * -> *) a. R3 t => Lens' (t a) a
_z

instance R1 V3 where
  _x :: forall a. Lens' (V3 a) a
_x a -> f a
f (V3 a
a a
b a
c) = (\a
a' -> forall a. a -> a -> a -> V3 a
V3 a
a' a
b a
c) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
f a
a
  {-# INLINE _x #-}

instance R2 V3 where
  _y :: forall a. Lens' (V3 a) a
_y a -> f a
f (V3 a
a a
b a
c) = (\a
b' -> forall a. a -> a -> a -> V3 a
V3 a
a a
b' a
c) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
f a
b
  {-# INLINE _y #-}
  _xy :: forall a. Lens' (V3 a) (V2 a)
_xy V2 a -> f (V2 a)
f (V3 a
a a
b a
c) = (\(V2 a
a' a
b') -> forall a. a -> a -> a -> V3 a
V3 a
a' a
b' a
c) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> V2 a -> f (V2 a)
f (forall a. a -> a -> V2 a
V2 a
a a
b)
  {-# INLINE _xy #-}

instance R3 V3 where
  _z :: forall a. Lens' (V3 a) a
_z a -> f a
f (V3 a
a a
b a
c) = forall a. a -> a -> a -> V3 a
V3 a
a a
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
f a
c
  {-# INLINE _z #-}
  _xyz :: forall a. Lens' (V3 a) (V3 a)
_xyz = forall a. a -> a
id
  {-# INLINE _xyz #-}

instance Storable a => Storable (V3 a) where
  sizeOf :: V3 a -> Int
sizeOf V3 a
_ = Int
3 forall a. Num a => a -> a -> a
* forall a. Storable a => a -> Int
sizeOf (forall a. HasCallStack => a
undefined::a)
  {-# INLINE sizeOf #-}
  alignment :: V3 a -> Int
alignment V3 a
_ = forall a. Storable a => a -> Int
alignment (forall a. HasCallStack => a
undefined::a)
  {-# INLINE alignment #-}
  poke :: Ptr (V3 a) -> V3 a -> IO ()
poke Ptr (V3 a)
ptr (V3 a
x a
y a
z) = do forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr a
ptr' a
x
                           forall a. Storable a => Ptr a -> Int -> a -> IO ()
pokeElemOff Ptr a
ptr' Int
1 a
y
                           forall a. Storable a => Ptr a -> Int -> a -> IO ()
pokeElemOff Ptr a
ptr' Int
2 a
z
    where ptr' :: Ptr a
ptr' = forall a b. Ptr a -> Ptr b
castPtr Ptr (V3 a)
ptr
  {-# INLINE poke #-}
  peek :: Ptr (V3 a) -> IO (V3 a)
peek Ptr (V3 a)
ptr = forall a. a -> a -> a -> V3 a
V3 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek Ptr a
ptr' forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> Int -> IO a
peekElemOff Ptr a
ptr' Int
1 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> Int -> IO a
peekElemOff Ptr a
ptr' Int
2
    where ptr' :: Ptr a
ptr' = forall a b. Ptr a -> Ptr b
castPtr Ptr (V3 a)
ptr
  {-# INLINE peek #-}

-- | cross product

cross :: Num a => V3 a -> V3 a -> V3 a
cross :: forall a. Num a => V3 a -> V3 a -> V3 a
cross (V3 a
a a
b a
c) (V3 a
d a
e a
f) = forall a. a -> a -> a -> V3 a
V3 (a
bforall a. Num a => a -> a -> a
*a
fforall a. Num a => a -> a -> a
-a
cforall a. Num a => a -> a -> a
*a
e) (a
cforall a. Num a => a -> a -> a
*a
dforall a. Num a => a -> a -> a
-a
aforall a. Num a => a -> a -> a
*a
f) (a
aforall a. Num a => a -> a -> a
*a
eforall a. Num a => a -> a -> a
-a
bforall a. Num a => a -> a -> a
*a
d)
{-# INLINABLE cross #-}

-- | scalar triple product

triple :: Num a => V3 a -> V3 a -> V3 a -> a
triple :: forall a. Num a => V3 a -> V3 a -> V3 a -> a
triple V3 a
a V3 a
b V3 a
c = forall (f :: * -> *) a. (Metric f, Num a) => f a -> f a -> a
dot V3 a
a (forall a. Num a => V3 a -> V3 a -> V3 a
cross V3 a
b V3 a
c)
{-# INLINE triple #-}

instance Epsilon a => Epsilon (V3 a) where
  nearZero :: V3 a -> Bool
nearZero = forall a. Epsilon a => a -> Bool
nearZero forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. (Metric f, Num a) => f a -> a
quadrance
  {-# INLINE nearZero #-}

instance Ix a => Ix (V3 a) where
  {-# SPECIALISE instance Ix (V3 Int) #-}

  range :: (V3 a, V3 a) -> [V3 a]
range (V3 a
l1 a
l2 a
l3,V3 a
u1 a
u2 a
u3) =
      [forall a. a -> a -> a -> V3 a
V3 a
i1 a
i2 a
i3 | a
i1 <- forall a. Ix a => (a, a) -> [a]
range (a
l1,a
u1)
                   , a
i2 <- forall a. Ix a => (a, a) -> [a]
range (a
l2,a
u2)
                   , a
i3 <- forall a. Ix a => (a, a) -> [a]
range (a
l3,a
u3)
                   ]
  {-# INLINE range #-}

  unsafeIndex :: (V3 a, V3 a) -> V3 a -> Int
unsafeIndex (V3 a
l1 a
l2 a
l3,V3 a
u1 a
u2 a
u3) (V3 a
i1 a
i2 a
i3) =
    forall a. Ix a => (a, a) -> a -> Int
unsafeIndex (a
l3,a
u3) a
i3 forall a. Num a => a -> a -> a
+ forall a. Ix a => (a, a) -> Int
unsafeRangeSize (a
l3,a
u3) forall a. Num a => a -> a -> a
* (
    forall a. Ix a => (a, a) -> a -> Int
unsafeIndex (a
l2,a
u2) a
i2 forall a. Num a => a -> a -> a
+ forall a. Ix a => (a, a) -> Int
unsafeRangeSize (a
l2,a
u2) forall a. Num a => a -> a -> a
*
    forall a. Ix a => (a, a) -> a -> Int
unsafeIndex (a
l1,a
u1) a
i1)
  {-# INLINE unsafeIndex #-}

  inRange :: (V3 a, V3 a) -> V3 a -> Bool
inRange (V3 a
l1 a
l2 a
l3,V3 a
u1 a
u2 a
u3) (V3 a
i1 a
i2 a
i3) =
    forall a. Ix a => (a, a) -> a -> Bool
inRange (a
l1,a
u1) a
i1 Bool -> Bool -> Bool
&& forall a. Ix a => (a, a) -> a -> Bool
inRange (a
l2,a
u2) a
i2 Bool -> Bool -> Bool
&&
    forall a. Ix a => (a, a) -> a -> Bool
inRange (a
l3,a
u3) a
i3
  {-# INLINE inRange #-}

instance Representable V3 where
  type Rep V3 = E V3
  tabulate :: forall a. (Rep V3 -> a) -> V3 a
tabulate Rep V3 -> a
f = forall a. a -> a -> a -> V3 a
V3 (Rep V3 -> a
f forall (t :: * -> *). R1 t => E t
ex) (Rep V3 -> a
f forall (t :: * -> *). R2 t => E t
ey) (Rep V3 -> a
f forall (t :: * -> *). R3 t => E t
ez)
  {-# INLINE tabulate #-}
  index :: forall a. V3 a -> Rep V3 -> a
index V3 a
xs (E forall a. Lens' (V3 a) a
l) = forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall a. Lens' (V3 a) a
l V3 a
xs
  {-# INLINE index #-}

instance WithIndex.FunctorWithIndex (E V3) V3 where
  imap :: forall a b. (E V3 -> a -> b) -> V3 a -> V3 b
imap E V3 -> a -> b
f (V3 a
a a
b a
c) = forall a. a -> a -> a -> V3 a
V3 (E V3 -> a -> b
f forall (t :: * -> *). R1 t => E t
ex a
a) (E V3 -> a -> b
f forall (t :: * -> *). R2 t => E t
ey a
b) (E V3 -> a -> b
f forall (t :: * -> *). R3 t => E t
ez a
c)
  {-# INLINE imap #-}

instance WithIndex.FoldableWithIndex (E V3) V3 where
  ifoldMap :: forall m a. Monoid m => (E V3 -> a -> m) -> V3 a -> m
ifoldMap E V3 -> a -> m
f (V3 a
a a
b a
c) = E V3 -> a -> m
f forall (t :: * -> *). R1 t => E t
ex a
a forall a. Monoid a => a -> a -> a
`mappend` E V3 -> a -> m
f forall (t :: * -> *). R2 t => E t
ey a
b forall a. Monoid a => a -> a -> a
`mappend` E V3 -> a -> m
f forall (t :: * -> *). R3 t => E t
ez a
c
  {-# INLINE ifoldMap #-}

instance WithIndex.TraversableWithIndex (E V3) V3 where
  itraverse :: forall (f :: * -> *) a b.
Applicative f =>
(E V3 -> a -> f b) -> V3 a -> f (V3 b)
itraverse E V3 -> a -> f b
f (V3 a
a a
b a
c) = forall a. a -> a -> a -> V3 a
V3 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> E V3 -> a -> f b
f forall (t :: * -> *). R1 t => E t
ex a
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> E V3 -> a -> f b
f forall (t :: * -> *). R2 t => E t
ey a
b forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> E V3 -> a -> f b
f forall (t :: * -> *). R3 t => E t
ez a
c
  {-# INLINE itraverse #-}

#if !MIN_VERSION_lens(5,0,0)
instance Lens.FunctorWithIndex     (E V3) V3 where imap      = WithIndex.imap
instance Lens.FoldableWithIndex    (E V3) V3 where ifoldMap  = WithIndex.ifoldMap
instance Lens.TraversableWithIndex (E V3) V3 where itraverse = WithIndex.itraverse
#endif

type instance Index (V3 a) = E V3
type instance IxValue (V3 a) = a

instance Ixed (V3 a) where
  ix :: Index (V3 a) -> Traversal' (V3 a) (IxValue (V3 a))
ix Index (V3 a)
i = forall (t :: * -> *). E t -> forall x. Lens' (t x) x
el Index (V3 a)
i
  {-# INLINE ix #-}

instance Each (V3 a) (V3 b) a b where
  each :: Traversal (V3 a) (V3 b) a b
each = forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse
  {-# INLINE each #-}

data instance U.Vector    (V3 a) =  V_V3 {-# UNPACK #-} !Int !(U.Vector    a)
data instance U.MVector s (V3 a) = MV_V3 {-# UNPACK #-} !Int !(U.MVector s a)
instance U.Unbox a => U.Unbox (V3 a)

instance U.Unbox a => M.MVector U.MVector (V3 a) where
  {-# INLINE basicLength #-}
  {-# INLINE basicUnsafeSlice #-}
  {-# INLINE basicOverlaps #-}
  {-# INLINE basicUnsafeNew #-}
  {-# INLINE basicUnsafeRead #-}
  {-# INLINE basicUnsafeWrite #-}
  basicLength :: forall s. MVector s (V3 a) -> Int
basicLength (MV_V3 Int
n MVector s a
_) = Int
n
  basicUnsafeSlice :: forall s. Int -> Int -> MVector s (V3 a) -> MVector s (V3 a)
basicUnsafeSlice Int
m Int
n (MV_V3 Int
_ MVector s a
v) = forall s a. Int -> MVector s a -> MVector s (V3 a)
MV_V3 Int
n (forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
M.basicUnsafeSlice (Int
3forall a. Num a => a -> a -> a
*Int
m) (Int
3forall a. Num a => a -> a -> a
*Int
n) MVector s a
v)
  basicOverlaps :: forall s. MVector s (V3 a) -> MVector s (V3 a) -> Bool
basicOverlaps (MV_V3 Int
_ MVector s a
v) (MV_V3 Int
_ MVector s a
u) = forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> v s a -> Bool
M.basicOverlaps MVector s a
v MVector s a
u
  basicUnsafeNew :: forall s. Int -> ST s (MVector s (V3 a))
basicUnsafeNew Int
n = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (forall s a. Int -> MVector s a -> MVector s (V3 a)
MV_V3 Int
n) (forall (v :: * -> * -> *) a s. MVector v a => Int -> ST s (v s a)
M.basicUnsafeNew (Int
3forall a. Num a => a -> a -> a
*Int
n))
  basicUnsafeRead :: forall s. MVector s (V3 a) -> Int -> ST s (V3 a)
basicUnsafeRead (MV_V3 Int
_ MVector s a
v) Int
i =
    do let o :: Int
o = Int
3forall a. Num a => a -> a -> a
*Int
i
       a
x <- forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s a
M.basicUnsafeRead MVector s a
v Int
o
       a
y <- forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s a
M.basicUnsafeRead MVector s a
v (Int
oforall a. Num a => a -> a -> a
+Int
1)
       a
z <- forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> ST s a
M.basicUnsafeRead MVector s a
v (Int
oforall a. Num a => a -> a -> a
+Int
2)
       forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> a -> a -> V3 a
V3 a
x a
y a
z)
  basicUnsafeWrite :: forall s. MVector s (V3 a) -> Int -> V3 a -> ST s ()
basicUnsafeWrite (MV_V3 Int
_ MVector s a
v) Int
i (V3 a
x a
y a
z) =
    do let o :: Int
o = Int
3forall a. Num a => a -> a -> a
*Int
i
       forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> a -> ST s ()
M.basicUnsafeWrite MVector s a
v Int
o     a
x
       forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> a -> ST s ()
M.basicUnsafeWrite MVector s a
v (Int
oforall a. Num a => a -> a -> a
+Int
1) a
y
       forall (v :: * -> * -> *) a s.
MVector v a =>
v s a -> Int -> a -> ST s ()
M.basicUnsafeWrite MVector s a
v (Int
oforall a. Num a => a -> a -> a
+Int
2) a
z
  basicInitialize :: forall s. MVector s (V3 a) -> ST s ()
basicInitialize (MV_V3 Int
_ MVector s a
v) = forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
M.basicInitialize MVector s a
v
  {-# INLINE basicInitialize #-}

instance U.Unbox a => G.Vector U.Vector (V3 a) where
  {-# INLINE basicUnsafeFreeze #-}
  {-# INLINE basicUnsafeThaw   #-}
  {-# INLINE basicLength       #-}
  {-# INLINE basicUnsafeSlice  #-}
  {-# INLINE basicUnsafeIndexM #-}
  basicUnsafeFreeze :: forall s. Mutable Vector s (V3 a) -> ST s (Vector (V3 a))
basicUnsafeFreeze (MV_V3 Int
n MVector s a
v) = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ( forall a. Int -> Vector a -> Vector (V3 a)
V_V3 Int
n) (forall (v :: * -> *) a s. Vector v a => Mutable v s a -> ST s (v a)
G.basicUnsafeFreeze MVector s a
v)
  basicUnsafeThaw :: forall s. Vector (V3 a) -> ST s (Mutable Vector s (V3 a))
basicUnsafeThaw   ( V_V3 Int
n Vector a
v) = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (forall s a. Int -> MVector s a -> MVector s (V3 a)
MV_V3 Int
n) (forall (v :: * -> *) a s. Vector v a => v a -> ST s (Mutable v s a)
G.basicUnsafeThaw   Vector a
v)
  basicLength :: Vector (V3 a) -> Int
basicLength       ( V_V3 Int
n Vector a
_) = Int
n
  basicUnsafeSlice :: Int -> Int -> Vector (V3 a) -> Vector (V3 a)
basicUnsafeSlice Int
m Int
n (V_V3 Int
_ Vector a
v) = forall a. Int -> Vector a -> Vector (V3 a)
V_V3 Int
n (forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
G.basicUnsafeSlice (Int
3forall a. Num a => a -> a -> a
*Int
m) (Int
3forall a. Num a => a -> a -> a
*Int
n) Vector a
v)
  basicUnsafeIndexM :: Vector (V3 a) -> Int -> Box (V3 a)
basicUnsafeIndexM (V_V3 Int
_ Vector a
v) Int
i =
    do let o :: Int
o = Int
3forall a. Num a => a -> a -> a
*Int
i
       a
x <- forall (v :: * -> *) a. Vector v a => v a -> Int -> Box a
G.basicUnsafeIndexM Vector a
v Int
o
       a
y <- forall (v :: * -> *) a. Vector v a => v a -> Int -> Box a
G.basicUnsafeIndexM Vector a
v (Int
oforall a. Num a => a -> a -> a
+Int
1)
       a
z <- forall (v :: * -> *) a. Vector v a => v a -> Int -> Box a
G.basicUnsafeIndexM Vector a
v (Int
oforall a. Num a => a -> a -> a
+Int
2)
       forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> a -> a -> V3 a
V3 a
x a
y a
z)

instance MonadZip V3 where
  mzipWith :: forall a b c. (a -> b -> c) -> V3 a -> V3 b -> V3 c
mzipWith = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2

instance MonadFix V3 where
  mfix :: forall a. (a -> V3 a) -> V3 a
mfix a -> V3 a
f = forall a. a -> a -> a -> V3 a
V3 (let V3 a
a a
_ a
_ = a -> V3 a
f a
a in a
a)
              (let V3 a
_ a
a a
_ = a -> V3 a
f a
a in a
a)
              (let V3 a
_ a
_ a
a = a -> V3 a
f a
a in a
a)

instance Bounded a => Bounded (V3 a) where
  minBound :: V3 a
minBound = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Bounded a => a
minBound
  {-# INLINE minBound #-}
  maxBound :: V3 a
maxBound = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Bounded a => a
maxBound
  {-# INLINE maxBound #-}

instance NFData a => NFData (V3 a) where
  rnf :: V3 a -> ()
rnf (V3 a
a a
b a
c) = forall a. NFData a => a -> ()
rnf a
a seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf a
b seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf a
c

instance Serial1 V3 where
  serializeWith :: forall (m :: * -> *) a. MonadPut m => (a -> m ()) -> V3 a -> m ()
serializeWith = forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_
  deserializeWith :: forall (m :: * -> *) a. MonadGet m => m a -> m (V3 a)
deserializeWith m a
k = forall a. a -> a -> a -> V3 a
V3 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
k forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m a
k forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m a
k

instance Serial a => Serial (V3 a) where
  serialize :: forall (m :: * -> *). MonadPut m => V3 a -> m ()
serialize = forall (f :: * -> *) (m :: * -> *) a.
(Serial1 f, MonadPut m) =>
(a -> m ()) -> f a -> m ()
serializeWith forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
serialize
  deserialize :: forall (m :: * -> *). MonadGet m => m (V3 a)
deserialize = forall (f :: * -> *) (m :: * -> *) a.
(Serial1 f, MonadGet m) =>
m a -> m (f a)
deserializeWith forall a (m :: * -> *). (Serial a, MonadGet m) => m a
deserialize

instance Binary a => Binary (V3 a) where
  put :: V3 a -> Put
put = forall (f :: * -> *) (m :: * -> *) a.
(Serial1 f, MonadPut m) =>
(a -> m ()) -> f a -> m ()
serializeWith forall t. Binary t => t -> Put
Binary.put
  get :: Get (V3 a)
get = forall (f :: * -> *) (m :: * -> *) a.
(Serial1 f, MonadGet m) =>
m a -> m (f a)
deserializeWith forall t. Binary t => Get t
Binary.get

instance Serialize a => Serialize (V3 a) where
  put :: Putter (V3 a)
put = forall (f :: * -> *) (m :: * -> *) a.
(Serial1 f, MonadPut m) =>
(a -> m ()) -> f a -> m ()
serializeWith forall t. Serialize t => Putter t
Cereal.put
  get :: Get (V3 a)
get = forall (f :: * -> *) (m :: * -> *) a.
(Serial1 f, MonadGet m) =>
m a -> m (f a)
deserializeWith forall t. Serialize t => Get t
Cereal.get

instance Eq1 V3 where
  liftEq :: forall a b. (a -> b -> Bool) -> V3 a -> V3 b -> Bool
liftEq a -> b -> Bool
k (V3 a
a a
b a
c) (V3 b
d b
e b
f) = a -> b -> Bool
k a
a b
d Bool -> Bool -> Bool
&& a -> b -> Bool
k a
b b
e Bool -> Bool -> Bool
&& a -> b -> Bool
k a
c b
f
instance Ord1 V3 where
  liftCompare :: forall a b. (a -> b -> Ordering) -> V3 a -> V3 b -> Ordering
liftCompare a -> b -> Ordering
k (V3 a
a a
b a
c) (V3 b
d b
e b
f) = a -> b -> Ordering
k a
a b
d forall a. Monoid a => a -> a -> a
`mappend` a -> b -> Ordering
k a
b b
e forall a. Monoid a => a -> a -> a
`mappend` a -> b -> Ordering
k a
c b
f
instance Read1 V3 where
  liftReadsPrec :: forall a. (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (V3 a)
liftReadsPrec Int -> ReadS a
k ReadS [a]
_ Int
d = forall a. Bool -> ReadS a -> ReadS a
readParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ \String
r ->
     [ (forall a. a -> a -> a -> V3 a
V3 a
a a
b a
c, String
r4)
     | (String
"V3",String
r1) <- ReadS String
lex String
r
     , (a
a,String
r2) <- Int -> ReadS a
k Int
11 String
r1
     , (a
b,String
r3) <- Int -> ReadS a
k Int
11 String
r2
     , (a
c,String
r4) <- Int -> ReadS a
k Int
11 String
r3
     ]
instance Show1 V3 where
  liftShowsPrec :: forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> V3 a -> ShowS
liftShowsPrec Int -> a -> ShowS
f [a] -> ShowS
_ Int
d (V3 a
a a
b a
c) = Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$
     String -> ShowS
showString String
"V3 " forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> ShowS
f Int
11 a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' ' forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> ShowS
f Int
11 a
b forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' ' forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> ShowS
f Int
11 a
c

instance Field1 (V3 a) (V3 a) a a where
  _1 :: Lens (V3 a) (V3 a) a a
_1 a -> f a
f (V3 a
x a
y a
z) = a -> f a
f a
x forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \a
x' -> forall a. a -> a -> a -> V3 a
V3 a
x' a
y a
z

instance Field2 (V3 a) (V3 a) a a where
  _2 :: Lens (V3 a) (V3 a) a a
_2 a -> f a
f (V3 a
x a
y a
z) = a -> f a
f a
y forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \a
y' -> forall a. a -> a -> a -> V3 a
V3 a
x a
y' a
z

instance Field3 (V3 a) (V3 a) a a where
  _3 :: Lens (V3 a) (V3 a) a a
_3 a -> f a
f (V3 a
x a
y a
z) = a -> f a
f a
z forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \a
z' -> forall a. a -> a -> a -> V3 a
V3 a
x a
y a
z'

instance Semigroup a => Semigroup (V3 a) where
 <> :: V3 a -> V3 a -> V3 a
(<>) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Semigroup a => a -> a -> a
(<>)

instance Monoid a => Monoid (V3 a) where
  mempty :: V3 a
mempty = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
#if !(MIN_VERSION_base(4,11,0))
  mappend = liftA2 mappend
#endif