{-# 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
(V3 a -> V3 a -> Bool) -> (V3 a -> V3 a -> Bool) -> Eq (V3 a)
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,Eq (V3 a)
Eq (V3 a)
-> (V3 a -> V3 a -> Ordering)
-> (V3 a -> V3 a -> Bool)
-> (V3 a -> V3 a -> Bool)
-> (V3 a -> V3 a -> Bool)
-> (V3 a -> V3 a -> Bool)
-> (V3 a -> V3 a -> V3 a)
-> (V3 a -> V3 a -> V3 a)
-> Ord (V3 a)
V3 a -> V3 a -> Bool
V3 a -> V3 a -> Ordering
V3 a -> V3 a -> V3 a
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
$cp1Ord :: forall a. Ord a => Eq (V3 a)
Ord,Int -> V3 a -> ShowS
[V3 a] -> ShowS
V3 a -> String
(Int -> V3 a -> ShowS)
-> (V3 a -> String) -> ([V3 a] -> ShowS) -> Show (V3 a)
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)
Int -> ReadS (V3 a)
ReadS [V3 a]
(Int -> ReadS (V3 a))
-> ReadS [V3 a]
-> ReadPrec (V3 a)
-> ReadPrec [V3 a]
-> Read (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,Typeable (V3 a)
DataType
Constr
Typeable (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 (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (V3 a))
-> (V3 a -> Constr)
-> (V3 a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (V3 a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (V3 a)))
-> ((forall b. Data b => b -> b) -> V3 a -> V3 a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> V3 a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> V3 a -> r)
-> (forall u. (forall d. Data d => d -> u) -> V3 a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> V3 a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> V3 a -> m (V3 a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> V3 a -> m (V3 a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> V3 a -> m (V3 a))
-> Data (V3 a)
V3 a -> DataType
V3 a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (V3 a))
(forall b. Data b => b -> b) -> V3 a -> V3 a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> V3 a -> c (V3 a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (V3 a)
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 u. Int -> (forall d. Data d => d -> u) -> V3 a -> u
forall u. (forall d. Data d => d -> u) -> V3 a -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> V3 a -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> V3 a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> V3 a -> m (V3 a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> V3 a -> m (V3 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))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (V3 a))
$cV3 :: Constr
$tV3 :: DataType
gmapMo :: (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 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 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 :: 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 d. Data d => d -> u) -> V3 a -> [u]
$cgmapQ :: forall a u. Data a => (forall d. Data d => d -> u) -> V3 a -> [u]
gmapQr :: (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 :: (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 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 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 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 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)
$cp1Data :: forall a. Data a => Typeable (V3 a)
Data
                                 ,(forall x. V3 a -> Rep (V3 a) x)
-> (forall x. Rep (V3 a) x -> V3 a) -> Generic (V3 a)
forall x. Rep (V3 a) x -> V3 a
forall x. V3 a -> Rep (V3 a) x
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. V3 a -> Rep1 V3 a)
-> (forall a. Rep1 V3 a -> V3 a) -> Generic1 V3
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)
                                 ,V3 a -> Q Exp
V3 a -> Q (TExp (V3 a))
(V3 a -> Q Exp) -> (V3 a -> Q (TExp (V3 a))) -> Lift (V3 a)
forall a. Lift a => V3 a -> Q Exp
forall a. Lift a => V3 a -> Q (TExp (V3 a))
forall t. (t -> Q Exp) -> (t -> Q (TExp t)) -> Lift t
liftTyped :: V3 a -> Q (TExp (V3 a))
$cliftTyped :: forall a. Lift a => V3 a -> Q (TExp (V3 a))
lift :: V3 a -> Q Exp
$clift :: forall a. Lift a => V3 a -> Q Exp
Lift
#endif
                                 )

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

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

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

instance Random a => Random (V3 a) where
  random :: g -> (V3 a, g)
random g
g = case g -> (a, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random g
g of
    (a
a, g
g') -> case g -> (a, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random g
g' of
      (a
b, g
g'') -> case g -> (a, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random g
g'' of
        (a
c, g
g''') -> (a -> a -> a -> V3 a
forall a. a -> a -> a -> V3 a
V3 a
a a
b a
c, g
g''')
  randomR :: (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 (a, a) -> g -> (a, g)
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 (a, a) -> g -> (a, g)
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 (a, a) -> g -> (a, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a
c,a
c') g
g'' of
        (a
c'', g
g''') -> (a -> a -> a -> V3 a
forall a. a -> a -> a -> V3 a
V3 a
a'' a
b'' a
c'', g
g''')

instance Traversable V3 where
  traverse :: (a -> f b) -> V3 a -> f (V3 b)
traverse a -> f b
f (V3 a
a a
b a
c) = b -> b -> b -> V3 b
forall a. a -> a -> a -> V3 a
V3 (b -> b -> b -> V3 b) -> f b -> f (b -> b -> V3 b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b -> b -> V3 b) -> f b -> f (b -> V3 b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
b f (b -> V3 b) -> f b -> f (V3 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 :: (a -> m) -> V3 a -> m
foldMap1 a -> m
f (V3 a
a a
b a
c) = a -> m
f a
a m -> m -> m
forall a. Semigroup a => a -> a -> a
<> a -> m
f a
b m -> m -> m
forall a. Semigroup a => a -> a -> a
<> a -> m
f a
c
  {-# INLINE foldMap1 #-}

instance Traversable1 V3 where
  traverse1 :: (a -> f b) -> V3 a -> f (V3 b)
traverse1 a -> f b
f (V3 a
a a
b a
c) = b -> b -> b -> V3 b
forall a. a -> a -> a -> V3 a
V3 (b -> b -> b -> V3 b) -> f b -> f (b -> b -> V3 b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a f (b -> b -> V3 b) -> f b -> f (b -> V3 b)
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> a -> f b
f a
b f (b -> V3 b) -> f b -> f (V3 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 <.> :: V3 (a -> b) -> V3 a -> V3 b
<.> V3 a
d a
e a
f = b -> b -> b -> V3 b
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 :: a -> V3 a
pure a
a = a -> a -> a -> V3 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 <*> :: V3 (a -> b) -> V3 a -> V3 b
<*> V3 a
d a
e a
f = b -> b -> b -> V3 b
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 :: V3 a
zero = a -> V3 a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
0
  {-# INLINE zero #-}
  liftU2 :: (a -> a -> a) -> V3 a -> V3 a -> V3 a
liftU2 = (a -> a -> a) -> V3 a -> V3 a -> V3 a
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2
  {-# INLINE liftU2 #-}
  liftI2 :: (a -> b -> c) -> V3 a -> V3 b -> V3 c
liftI2 = (a -> b -> c) -> V3 a -> V3 b -> V3 c
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 >>- :: V3 a -> (a -> V3 b) -> V3 b
>>- a -> V3 b
f = b -> b -> b -> V3 b
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 >>= :: V3 a -> (a -> V3 b) -> V3 b
>>= a -> V3 b
f = b -> b -> b -> V3 b
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
(+) = (a -> a -> a) -> V3 a -> V3 a -> V3 a
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Num a => a -> a -> a
(+)
  {-# INLINE (+) #-}
  (-) = (a -> a -> a) -> V3 a -> V3 a -> V3 a
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (-)
  {-# INLINE (-) #-}
  * :: V3 a -> V3 a -> V3 a
(*) = (a -> a -> a) -> V3 a -> V3 a -> V3 a
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Num a => a -> a -> a
(*)
  {-# INLINE (*) #-}
  negate :: V3 a -> V3 a
negate = (a -> a) -> V3 a -> V3 a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. Num a => a -> a
negate
  {-# INLINE negate #-}
  abs :: V3 a -> V3 a
abs = (a -> a) -> V3 a -> V3 a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. Num a => a -> a
abs
  {-# INLINE abs #-}
  signum :: V3 a -> V3 a
signum = (a -> a) -> V3 a -> V3 a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. Num a => a -> a
signum
  {-# INLINE signum #-}
  fromInteger :: Integer -> V3 a
fromInteger = a -> V3 a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> V3 a) -> (Integer -> a) -> Integer -> V3 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> a
forall a. Num a => Integer -> a
fromInteger
  {-# INLINE fromInteger #-}

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

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

instance Hashable1 V3 where
  liftHashWithSalt :: (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 :: V3 a -> V3 a -> a
dot (V3 a
a a
b a
c) (V3 a
d a
e a
f) = a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
d a -> a -> a
forall a. Num a => a -> a -> a
+ a
b a -> a -> a
forall a. Num a => a -> a -> a
* a
e a -> a -> a
forall a. Num a => a -> a -> a
+ a
c a -> a -> a
forall a. Num a => a -> a -> a
* a
f
  {-# INLINABLE dot #-}

instance Distributive V3 where
  distribute :: f (V3 a) -> V3 (f a)
distribute f (V3 a)
f = f a -> f a -> f a -> V3 (f a)
forall a. a -> a -> a -> V3 a
V3 ((V3 a -> a) -> f (V3 a) -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(V3 a
x a
_ a
_) -> a
x) f (V3 a)
f) ((V3 a -> a) -> f (V3 a) -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(V3 a
_ a
y a
_) -> a
y) f (V3 a)
f) ((V3 a -> a) -> f (V3 a) -> f a
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 :: Lens' (t a) (V2 a)
_xz V2 a -> f (V2 a)
f = (V3 a -> f (V3 a)) -> t a -> f (t a)
forall (t :: * -> *) a. R3 t => Lens' (t a) (V3 a)
_xyz ((V3 a -> f (V3 a)) -> t a -> f (t a))
-> (V3 a -> f (V3 a)) -> t a -> f (t a)
forall a b. (a -> b) -> a -> b
$ \(V3 a
a a
b a
c) -> V2 a -> f (V2 a)
f (a -> a -> V2 a
forall a. a -> a -> V2 a
V2 a
a a
c) f (V2 a) -> (V2 a -> V3 a) -> f (V3 a)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(V2 a
a' a
c') -> a -> a -> a -> V3 a
forall a. a -> a -> a -> V3 a
V3 a
a' a
b a
c'
{-# INLINE _xz #-}

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

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

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

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

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

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

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

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

instance R1 V3 where
  _x :: (a -> f a) -> V3 a -> f (V3 a)
_x a -> f a
f (V3 a
a a
b a
c) = (\a
a' -> a -> a -> a -> V3 a
forall a. a -> a -> a -> V3 a
V3 a
a' a
b a
c) (a -> V3 a) -> f a -> f (V3 a)
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 :: (a -> f a) -> V3 a -> f (V3 a)
_y a -> f a
f (V3 a
a a
b a
c) = (\a
b' -> a -> a -> a -> V3 a
forall a. a -> a -> a -> V3 a
V3 a
a a
b' a
c) (a -> V3 a) -> f a -> f (V3 a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
f a
b
  {-# INLINE _y #-}
  _xy :: (V2 a -> f (V2 a)) -> V3 a -> f (V3 a)
_xy V2 a -> f (V2 a)
f (V3 a
a a
b a
c) = (\(V2 a
a' a
b') -> a -> a -> a -> V3 a
forall a. a -> a -> a -> V3 a
V3 a
a' a
b' a
c) (V2 a -> V3 a) -> f (V2 a) -> f (V3 a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> V2 a -> f (V2 a)
f (a -> a -> V2 a
forall a. a -> a -> V2 a
V2 a
a a
b)
  {-# INLINE _xy #-}

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

instance Storable a => Storable (V3 a) where
  sizeOf :: V3 a -> Int
sizeOf V3 a
_ = Int
3 Int -> Int -> Int
forall a. Num a => a -> a -> a
* a -> Int
forall a. Storable a => a -> Int
sizeOf (a
forall a. HasCallStack => a
undefined::a)
  {-# INLINE sizeOf #-}
  alignment :: V3 a -> Int
alignment V3 a
_ = a -> Int
forall a. Storable a => a -> Int
alignment (a
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 Ptr a -> a -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr a
ptr' a
x
                           Ptr a -> Int -> a -> IO ()
forall a. Storable a => Ptr a -> Int -> a -> IO ()
pokeElemOff Ptr a
ptr' Int
1 a
y
                           Ptr a -> Int -> a -> IO ()
forall a. Storable a => Ptr a -> Int -> a -> IO ()
pokeElemOff Ptr a
ptr' Int
2 a
z
    where ptr' :: Ptr a
ptr' = Ptr (V3 a) -> Ptr a
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 = a -> a -> a -> V3 a
forall a. a -> a -> a -> V3 a
V3 (a -> a -> a -> V3 a) -> IO a -> IO (a -> a -> V3 a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ptr a -> IO a
forall a. Storable a => Ptr a -> IO a
peek Ptr a
ptr' IO (a -> a -> V3 a) -> IO a -> IO (a -> V3 a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ptr a -> Int -> IO a
forall a. Storable a => Ptr a -> Int -> IO a
peekElemOff Ptr a
ptr' Int
1 IO (a -> V3 a) -> IO a -> IO (V3 a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ptr a -> Int -> IO a
forall a. Storable a => Ptr a -> Int -> IO a
peekElemOff Ptr a
ptr' Int
2
    where ptr' :: Ptr a
ptr' = Ptr (V3 a) -> Ptr a
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 :: V3 a -> V3 a -> V3 a
cross (V3 a
a a
b a
c) (V3 a
d a
e a
f) = a -> a -> a -> V3 a
forall a. a -> a -> a -> V3 a
V3 (a
ba -> a -> a
forall a. Num a => a -> a -> a
*a
fa -> a -> a
forall a. Num a => a -> a -> a
-a
ca -> a -> a
forall a. Num a => a -> a -> a
*a
e) (a
ca -> a -> a
forall a. Num a => a -> a -> a
*a
da -> a -> a
forall a. Num a => a -> a -> a
-a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
f) (a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
ea -> a -> a
forall a. Num a => a -> a -> a
-a
ba -> a -> a
forall a. Num a => a -> a -> a
*a
d)
{-# INLINABLE cross #-}

-- | scalar triple product
triple :: Num a => V3 a -> V3 a -> V3 a -> a
triple :: V3 a -> V3 a -> V3 a -> a
triple V3 a
a V3 a
b V3 a
c = V3 a -> V3 a -> a
forall (f :: * -> *) a. (Metric f, Num a) => f a -> f a -> a
dot V3 a
a (V3 a -> V3 a -> V3 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 = a -> Bool
forall a. Epsilon a => a -> Bool
nearZero (a -> Bool) -> (V3 a -> a) -> V3 a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. V3 a -> a
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) =
      [a -> a -> a -> V3 a
forall a. a -> a -> a -> V3 a
V3 a
i1 a
i2 a
i3 | a
i1 <- (a, a) -> [a]
forall a. Ix a => (a, a) -> [a]
range (a
l1,a
u1)
                   , a
i2 <- (a, a) -> [a]
forall a. Ix a => (a, a) -> [a]
range (a
l2,a
u2)
                   , a
i3 <- (a, a) -> [a]
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) =
    (a, a) -> a -> Int
forall a. Ix a => (a, a) -> a -> Int
unsafeIndex (a
l3,a
u3) a
i3 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (a, a) -> Int
forall a. Ix a => (a, a) -> Int
unsafeRangeSize (a
l3,a
u3) Int -> Int -> Int
forall a. Num a => a -> a -> a
* (
    (a, a) -> a -> Int
forall a. Ix a => (a, a) -> a -> Int
unsafeIndex (a
l2,a
u2) a
i2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (a, a) -> Int
forall a. Ix a => (a, a) -> Int
unsafeRangeSize (a
l2,a
u2) Int -> Int -> Int
forall a. Num a => a -> a -> a
*
    (a, a) -> a -> Int
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) =
    (a, a) -> a -> Bool
forall a. Ix a => (a, a) -> a -> Bool
inRange (a
l1,a
u1) a
i1 Bool -> Bool -> Bool
&& (a, a) -> a -> Bool
forall a. Ix a => (a, a) -> a -> Bool
inRange (a
l2,a
u2) a
i2 Bool -> Bool -> Bool
&&
    (a, a) -> a -> 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 :: (Rep V3 -> a) -> V3 a
tabulate Rep V3 -> a
f = a -> a -> a -> V3 a
forall a. a -> a -> a -> V3 a
V3 (Rep V3 -> a
f Rep V3
forall (t :: * -> *). R1 t => E t
ex) (Rep V3 -> a
f Rep V3
forall (t :: * -> *). R2 t => E t
ey) (Rep V3 -> a
f Rep V3
forall (t :: * -> *). R3 t => E t
ez)
  {-# INLINE tabulate #-}
  index :: V3 a -> Rep V3 -> a
index V3 a
xs (E l) = Getting a (V3 a) a -> V3 a -> a
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting a (V3 a) a
forall a. Lens' (V3 a) a
l V3 a
xs
  {-# INLINE index #-}

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

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

instance WithIndex.TraversableWithIndex (E V3) V3 where
  itraverse :: (E V3 -> a -> f b) -> V3 a -> f (V3 b)
itraverse E V3 -> a -> f b
f (V3 a
a a
b a
c) = b -> b -> b -> V3 b
forall a. a -> a -> a -> V3 a
V3 (b -> b -> b -> V3 b) -> f b -> f (b -> b -> V3 b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> E V3 -> a -> f b
f E V3
forall (t :: * -> *). R1 t => E t
ex a
a f (b -> b -> V3 b) -> f b -> f (b -> V3 b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> E V3 -> a -> f b
f E V3
forall (t :: * -> *). R2 t => E t
ey a
b f (b -> V3 b) -> f b -> f (V3 b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> E V3 -> a -> f b
f E V3
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 = E V3 -> forall a. Lens' (V3 a) a
forall (t :: * -> *). E t -> forall x. Lens' (t x) x
el Index (V3 a)
E V3
i
  {-# INLINE ix #-}

instance Each (V3 a) (V3 b) a b where
  each :: (a -> f b) -> V3 a -> f (V3 b)
each = (a -> f b) -> V3 a -> f (V3 b)
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 :: MVector s (V3 a) -> Int
basicLength (MV_V3 n _) = Int
n
  basicUnsafeSlice :: Int -> Int -> MVector s (V3 a) -> MVector s (V3 a)
basicUnsafeSlice Int
m Int
n (MV_V3 _ v) = Int -> MVector s a -> MVector s (V3 a)
forall s a. Int -> MVector s a -> MVector s (V3 a)
MV_V3 Int
n (Int -> Int -> MVector s a -> MVector s a
forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
M.basicUnsafeSlice (Int
3Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
m) (Int
3Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
n) MVector s a
v)
  basicOverlaps :: MVector s (V3 a) -> MVector s (V3 a) -> Bool
basicOverlaps (MV_V3 _ v) (MV_V3 _ u) = MVector s a -> MVector s a -> Bool
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 :: Int -> m (MVector (PrimState m) (V3 a))
basicUnsafeNew Int
n = (MVector (PrimState m) a -> MVector (PrimState m) (V3 a))
-> m (MVector (PrimState m) a) -> m (MVector (PrimState m) (V3 a))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Int -> MVector (PrimState m) a -> MVector (PrimState m) (V3 a)
forall s a. Int -> MVector s a -> MVector s (V3 a)
MV_V3 Int
n) (Int -> m (MVector (PrimState m) a)
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
Int -> m (v (PrimState m) a)
M.basicUnsafeNew (Int
3Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
n))
  basicUnsafeRead :: MVector (PrimState m) (V3 a) -> Int -> m (V3 a)
basicUnsafeRead (MV_V3 _ v) Int
i =
    do let o :: Int
o = Int
3Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
i
       a
x <- MVector (PrimState m) a -> Int -> m a
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> m a
M.basicUnsafeRead MVector (PrimState m) a
v Int
o
       a
y <- MVector (PrimState m) a -> Int -> m a
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> m a
M.basicUnsafeRead MVector (PrimState m) a
v (Int
oInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
       a
z <- MVector (PrimState m) a -> Int -> m a
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> m a
M.basicUnsafeRead MVector (PrimState m) a
v (Int
oInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
2)
       V3 a -> m (V3 a)
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> a -> a -> V3 a
forall a. a -> a -> a -> V3 a
V3 a
x a
y a
z)
  basicUnsafeWrite :: MVector (PrimState m) (V3 a) -> Int -> V3 a -> m ()
basicUnsafeWrite (MV_V3 _ v) Int
i (V3 a
x a
y a
z) =
    do let o :: Int
o = Int
3Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
i
       MVector (PrimState m) a -> Int -> a -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> a -> m ()
M.basicUnsafeWrite MVector (PrimState m) a
v Int
o     a
x
       MVector (PrimState m) a -> Int -> a -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> a -> m ()
M.basicUnsafeWrite MVector (PrimState m) a
v (Int
oInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) a
y
       MVector (PrimState m) a -> Int -> a -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> Int -> a -> m ()
M.basicUnsafeWrite MVector (PrimState m) a
v (Int
oInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
2) a
z
  basicInitialize :: MVector (PrimState m) (V3 a) -> m ()
basicInitialize (MV_V3 _ v) = MVector (PrimState m) a -> m ()
forall (v :: * -> * -> *) a (m :: * -> *).
(MVector v a, PrimMonad m) =>
v (PrimState m) a -> m ()
M.basicInitialize MVector (PrimState m) 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 :: Mutable Vector (PrimState m) (V3 a) -> m (Vector (V3 a))
basicUnsafeFreeze (MV_V3 n v) = (Vector a -> Vector (V3 a)) -> m (Vector a) -> m (Vector (V3 a))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ( Int -> Vector a -> Vector (V3 a)
forall a. Int -> Vector a -> Vector (V3 a)
V_V3 Int
n) (Mutable Vector (PrimState m) a -> m (Vector a)
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
Mutable v (PrimState m) a -> m (v a)
G.basicUnsafeFreeze MVector (PrimState m) a
Mutable Vector (PrimState m) a
v)
  basicUnsafeThaw :: Vector (V3 a) -> m (Mutable Vector (PrimState m) (V3 a))
basicUnsafeThaw   ( V_V3 n v) = (MVector (PrimState m) a -> MVector (PrimState m) (V3 a))
-> m (MVector (PrimState m) a) -> m (MVector (PrimState m) (V3 a))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Int -> MVector (PrimState m) a -> MVector (PrimState m) (V3 a)
forall s a. Int -> MVector s a -> MVector s (V3 a)
MV_V3 Int
n) (Vector a -> m (Mutable Vector (PrimState m) a)
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
v a -> m (Mutable v (PrimState m) a)
G.basicUnsafeThaw   Vector a
v)
  basicLength :: Vector (V3 a) -> Int
basicLength       ( V_V3 n _) = Int
n
  basicUnsafeSlice :: Int -> Int -> Vector (V3 a) -> Vector (V3 a)
basicUnsafeSlice Int
m Int
n (V_V3 _ v) = Int -> Vector a -> Vector (V3 a)
forall a. Int -> Vector a -> Vector (V3 a)
V_V3 Int
n (Int -> Int -> Vector a -> Vector a
forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
G.basicUnsafeSlice (Int
3Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
m) (Int
3Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
n) Vector a
v)
  basicUnsafeIndexM :: Vector (V3 a) -> Int -> m (V3 a)
basicUnsafeIndexM (V_V3 _ v) Int
i =
    do let o :: Int
o = Int
3Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
i
       a
x <- Vector a -> Int -> m a
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, Monad m) =>
v a -> Int -> m a
G.basicUnsafeIndexM Vector a
v Int
o
       a
y <- Vector a -> Int -> m a
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, Monad m) =>
v a -> Int -> m a
G.basicUnsafeIndexM Vector a
v (Int
oInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
       a
z <- Vector a -> Int -> m a
forall (v :: * -> *) a (m :: * -> *).
(Vector v a, Monad m) =>
v a -> Int -> m a
G.basicUnsafeIndexM Vector a
v (Int
oInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
2)
       V3 a -> m (V3 a)
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> a -> a -> V3 a
forall a. a -> a -> a -> V3 a
V3 a
x a
y a
z)

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

instance MonadFix V3 where
  mfix :: (a -> V3 a) -> V3 a
mfix a -> V3 a
f = a -> a -> a -> V3 a
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 = a -> V3 a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
forall a. Bounded a => a
minBound
  {-# INLINE minBound #-}
  maxBound :: V3 a
maxBound = a -> V3 a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
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) = a -> ()
forall a. NFData a => a -> ()
rnf a
a () -> () -> ()
`seq` a -> ()
forall a. NFData a => a -> ()
rnf a
b () -> () -> ()
`seq` a -> ()
forall a. NFData a => a -> ()
rnf a
c

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

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

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

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

instance Eq1 V3 where
  liftEq :: (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 :: (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 Ordering -> Ordering -> Ordering
forall a. Monoid a => a -> a -> a
`mappend` a -> b -> Ordering
k a
b b
e Ordering -> Ordering -> Ordering
forall a. Monoid a => a -> a -> a
`mappend` a -> b -> Ordering
k a
c b
f
instance Read1 V3 where
  liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (V3 a)
liftReadsPrec Int -> ReadS a
k ReadS [a]
_ Int
d = Bool -> ReadS (V3 a) -> ReadS (V3 a)
forall a. Bool -> ReadS a -> ReadS a
readParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ReadS (V3 a) -> ReadS (V3 a)) -> ReadS (V3 a) -> ReadS (V3 a)
forall a b. (a -> b) -> a -> b
$ \String
r ->
     [ (a -> a -> a -> V3 a
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 :: (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 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
     String -> ShowS
showString String
"V3 " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> ShowS
f Int
11 a
a ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' ' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> ShowS
f Int
11 a
b ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
' ' ShowS -> ShowS -> ShowS
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 :: (a -> f a) -> V3 a -> f (V3 a)
_1 a -> f a
f (V3 a
x a
y a
z) = a -> f a
f a
x f a -> (a -> V3 a) -> f (V3 a)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \a
x' -> a -> a -> a -> V3 a
forall a. a -> a -> a -> V3 a
V3 a
x' a
y a
z

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

instance Field3 (V3 a) (V3 a) a a where
  _3 :: (a -> f a) -> V3 a -> f (V3 a)
_3 a -> f a
f (V3 a
x a
y a
z) = a -> f a
f a
z f a -> (a -> V3 a) -> f (V3 a)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \a
z' -> a -> a -> a -> V3 a
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
(<>) = (a -> a -> a) -> V3 a -> V3 a -> V3 a
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Semigroup a => a -> a -> a
(<>)

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