{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeFamilies #-}
{-# 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_base
#define MIN_VERSION_base(x,y,z) 1
#endif
module Linear.Quaternion
( Quaternion(..)
, Complicated(..)
, Hamiltonian(..)
, ee, ei, ej, ek
, slerp
, asinq
, acosq
, atanq
, asinhq
, acoshq
, atanhq
, absi
, pow
, rotate
, axisAngle
) 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
import Data.Bytes.Serial
import Data.Complex (Complex((:+)))
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 (Semigroup(..))
#endif
import Data.Serialize as Cereal
import GHC.Arr (Ix(..))
import qualified Data.Foldable as F
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, plusPtr)
import Foreign.Storable (Storable(..))
import GHC.Generics (Generic, Generic1)
#if defined(MIN_VERSION_template_haskell)
import Language.Haskell.TH.Syntax (Lift)
#endif
import Linear.Epsilon
import Linear.Conjugate
import Linear.Metric
import Linear.V
import Linear.V2
import Linear.V3
import Linear.V4
import Linear.Vector
import Prelude hiding (any)
import System.Random (Random(..))
data Quaternion a = Quaternion !a {-# UNPACK #-}!(V3 a)
deriving (Quaternion a -> Quaternion a -> Bool
forall a. Eq a => Quaternion a -> Quaternion a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Quaternion a -> Quaternion a -> Bool
$c/= :: forall a. Eq a => Quaternion a -> Quaternion a -> Bool
== :: Quaternion a -> Quaternion a -> Bool
$c== :: forall a. Eq a => Quaternion a -> Quaternion a -> Bool
Eq,Quaternion a -> Quaternion a -> Bool
Quaternion a -> Quaternion 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 (Quaternion a)
forall a. Ord a => Quaternion a -> Quaternion a -> Bool
forall a. Ord a => Quaternion a -> Quaternion a -> Ordering
forall a. Ord a => Quaternion a -> Quaternion a -> Quaternion a
min :: Quaternion a -> Quaternion a -> Quaternion a
$cmin :: forall a. Ord a => Quaternion a -> Quaternion a -> Quaternion a
max :: Quaternion a -> Quaternion a -> Quaternion a
$cmax :: forall a. Ord a => Quaternion a -> Quaternion a -> Quaternion a
>= :: Quaternion a -> Quaternion a -> Bool
$c>= :: forall a. Ord a => Quaternion a -> Quaternion a -> Bool
> :: Quaternion a -> Quaternion a -> Bool
$c> :: forall a. Ord a => Quaternion a -> Quaternion a -> Bool
<= :: Quaternion a -> Quaternion a -> Bool
$c<= :: forall a. Ord a => Quaternion a -> Quaternion a -> Bool
< :: Quaternion a -> Quaternion a -> Bool
$c< :: forall a. Ord a => Quaternion a -> Quaternion a -> Bool
compare :: Quaternion a -> Quaternion a -> Ordering
$ccompare :: forall a. Ord a => Quaternion a -> Quaternion a -> Ordering
Ord,ReadPrec [Quaternion a]
ReadPrec (Quaternion a)
ReadS [Quaternion a]
forall a. Read a => ReadPrec [Quaternion a]
forall a. Read a => ReadPrec (Quaternion a)
forall a. Read a => Int -> ReadS (Quaternion a)
forall a. Read a => ReadS [Quaternion a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Quaternion a]
$creadListPrec :: forall a. Read a => ReadPrec [Quaternion a]
readPrec :: ReadPrec (Quaternion a)
$creadPrec :: forall a. Read a => ReadPrec (Quaternion a)
readList :: ReadS [Quaternion a]
$creadList :: forall a. Read a => ReadS [Quaternion a]
readsPrec :: Int -> ReadS (Quaternion a)
$creadsPrec :: forall a. Read a => Int -> ReadS (Quaternion a)
Read,Int -> Quaternion a -> ShowS
forall a. Show a => Int -> Quaternion a -> ShowS
forall a. Show a => [Quaternion a] -> ShowS
forall a. Show a => Quaternion a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Quaternion a] -> ShowS
$cshowList :: forall a. Show a => [Quaternion a] -> ShowS
show :: Quaternion a -> String
$cshow :: forall a. Show a => Quaternion a -> String
showsPrec :: Int -> Quaternion a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Quaternion a -> ShowS
Show,Quaternion a -> DataType
Quaternion a -> Constr
forall {a}. Data a => Typeable (Quaternion a)
forall a. Data a => Quaternion a -> DataType
forall a. Data a => Quaternion a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> Quaternion a -> Quaternion a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Quaternion a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> Quaternion a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Quaternion a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Quaternion a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Quaternion a -> m (Quaternion a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Quaternion a -> m (Quaternion a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Quaternion a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Quaternion a -> c (Quaternion a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Quaternion a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Quaternion 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 (Quaternion a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Quaternion a -> c (Quaternion a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Quaternion a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Quaternion a -> m (Quaternion a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Quaternion a -> m (Quaternion a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Quaternion a -> m (Quaternion a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Quaternion a -> m (Quaternion a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Quaternion a -> m (Quaternion a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Quaternion a -> m (Quaternion a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Quaternion a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> Quaternion a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Quaternion a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> Quaternion a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Quaternion a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Quaternion a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Quaternion a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Quaternion a -> r
gmapT :: (forall b. Data b => b -> b) -> Quaternion a -> Quaternion a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> Quaternion a -> Quaternion a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Quaternion a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Quaternion a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Quaternion a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Quaternion a))
dataTypeOf :: Quaternion a -> DataType
$cdataTypeOf :: forall a. Data a => Quaternion a -> DataType
toConstr :: Quaternion a -> Constr
$ctoConstr :: forall a. Data a => Quaternion a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Quaternion a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Quaternion a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Quaternion a -> c (Quaternion a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Quaternion a -> c (Quaternion a)
Data
,forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Quaternion a) x -> Quaternion a
forall a x. Quaternion a -> Rep (Quaternion a) x
$cto :: forall a x. Rep (Quaternion a) x -> Quaternion a
$cfrom :: forall a x. Quaternion a -> Rep (Quaternion a) x
Generic,forall a. Rep1 Quaternion a -> Quaternion a
forall a. Quaternion a -> Rep1 Quaternion 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 Quaternion a -> Quaternion a
$cfrom1 :: forall a. Quaternion a -> Rep1 Quaternion a
Generic1
#if defined(MIN_VERSION_template_haskell)
,forall a (m :: * -> *). (Lift a, Quote m) => Quaternion a -> m Exp
forall a (m :: * -> *).
(Lift a, Quote m) =>
Quaternion a -> Code m (Quaternion a)
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => Quaternion a -> m Exp
forall (m :: * -> *).
Quote m =>
Quaternion a -> Code m (Quaternion a)
liftTyped :: forall (m :: * -> *).
Quote m =>
Quaternion a -> Code m (Quaternion a)
$cliftTyped :: forall a (m :: * -> *).
(Lift a, Quote m) =>
Quaternion a -> Code m (Quaternion a)
lift :: forall (m :: * -> *). Quote m => Quaternion a -> m Exp
$clift :: forall a (m :: * -> *). (Lift a, Quote m) => Quaternion a -> m Exp
Lift
#endif
)
instance Finite Quaternion where
type Size Quaternion = 4
toV :: forall a. Quaternion a -> V (Size Quaternion) a
toV (Quaternion a
a (V3 a
b a
c a
d)) = forall {k} (n :: k) a. Vector a -> V n a
V (forall a. Int -> [a] -> Vector a
V.fromListN Int
4 [a
a, a
b, a
c, a
d])
fromV :: forall a. V (Size Quaternion) a -> Quaternion a
fromV (V Vector a
v) = forall a. a -> V3 a -> Quaternion a
Quaternion (Vector a
v forall a. Vector a -> Int -> a
V.! Int
0) (forall a. a -> a -> a -> V3 a
V3 (Vector a
v forall a. Vector a -> Int -> a
V.! Int
1) (Vector a
v forall a. Vector a -> Int -> a
V.! Int
2) (Vector a
v forall a. Vector a -> Int -> a
V.! Int
3))
instance Random a => Random (Quaternion a) where
random :: forall g. RandomGen g => g -> (Quaternion 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
(V3 a
b, g
g'') -> (forall a. a -> V3 a -> Quaternion a
Quaternion a
a V3 a
b, g
g'')
randomR :: forall g.
RandomGen g =>
(Quaternion a, Quaternion a) -> g -> (Quaternion a, g)
randomR (Quaternion a
a V3 a
b, Quaternion a
c V3 a
d) g
g = case forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a
a,a
c) g
g of
(a
e, g
g') -> case forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (V3 a
b,V3 a
d) g
g' of
(V3 a
f, g
g'') -> (forall a. a -> V3 a -> Quaternion a
Quaternion a
e V3 a
f, g
g'')
instance Functor Quaternion where
fmap :: forall a b. (a -> b) -> Quaternion a -> Quaternion b
fmap a -> b
f (Quaternion a
e V3 a
v) = forall a. a -> V3 a -> Quaternion a
Quaternion (a -> b
f a
e) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f V3 a
v)
{-# INLINE fmap #-}
a
a <$ :: forall a b. a -> Quaternion b -> Quaternion a
<$ Quaternion b
_ = forall a. a -> V3 a -> Quaternion a
Quaternion a
a (forall a. a -> a -> a -> V3 a
V3 a
a a
a a
a)
{-# INLINE (<$) #-}
instance Apply Quaternion where
Quaternion a -> b
f V3 (a -> b)
fv <.> :: forall a b. Quaternion (a -> b) -> Quaternion a -> Quaternion b
<.> Quaternion a
a V3 a
v = forall a. a -> V3 a -> Quaternion a
Quaternion (a -> b
f a
a) (V3 (a -> b)
fv forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> V3 a
v)
{-# INLINE (<.>) #-}
instance Applicative Quaternion where
pure :: forall a. a -> Quaternion a
pure a
a = forall a. a -> V3 a -> Quaternion a
Quaternion a
a (forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a)
{-# INLINE pure #-}
Quaternion a -> b
f V3 (a -> b)
fv <*> :: forall a b. Quaternion (a -> b) -> Quaternion a -> Quaternion b
<*> Quaternion a
a V3 a
v = forall a. a -> V3 a -> Quaternion a
Quaternion (a -> b
f a
a) (V3 (a -> b)
fv forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> V3 a
v)
{-# INLINE (<*>) #-}
instance Additive Quaternion where
zero :: forall a. Num a => Quaternion a
zero = forall (f :: * -> *) a. Applicative f => a -> f a
pure a
0
{-# INLINE zero #-}
liftU2 :: forall a.
(a -> a -> a) -> Quaternion a -> Quaternion a -> Quaternion 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) -> Quaternion a -> Quaternion b -> Quaternion c
liftI2 = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2
{-# INLINE liftI2 #-}
instance Bind Quaternion where
Quaternion a
a (V3 a
b a
c a
d) >>- :: forall a b. Quaternion a -> (a -> Quaternion b) -> Quaternion b
>>- a -> Quaternion b
f = forall a. a -> V3 a -> Quaternion a
Quaternion b
a' (forall a. a -> a -> a -> V3 a
V3 b
b' b
c' b
d') where
Quaternion b
a' V3 b
_ = a -> Quaternion b
f a
a
Quaternion b
_ (V3 b
b' b
_ b
_) = a -> Quaternion b
f a
b
Quaternion b
_ (V3 b
_ b
c' b
_) = a -> Quaternion b
f a
c
Quaternion b
_ (V3 b
_ b
_ b
d') = a -> Quaternion b
f a
d
{-# INLINE (>>-) #-}
instance Monad Quaternion where
return :: forall a. a -> Quaternion a
return = forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE return #-}
Quaternion a
a (V3 a
b a
c a
d) >>= :: forall a b. Quaternion a -> (a -> Quaternion b) -> Quaternion b
>>= a -> Quaternion b
f = forall a. a -> V3 a -> Quaternion a
Quaternion b
a' (forall a. a -> a -> a -> V3 a
V3 b
b' b
c' b
d') where
Quaternion b
a' V3 b
_ = a -> Quaternion b
f a
a
Quaternion b
_ (V3 b
b' b
_ b
_) = a -> Quaternion b
f a
b
Quaternion b
_ (V3 b
_ b
c' b
_) = a -> Quaternion b
f a
c
Quaternion b
_ (V3 b
_ b
_ b
d') = a -> Quaternion b
f a
d
{-# INLINE (>>=) #-}
instance Ix a => Ix (Quaternion a) where
{-# SPECIALISE instance Ix (Quaternion Int) #-}
range :: (Quaternion a, Quaternion a) -> [Quaternion a]
range (Quaternion a
l1 V3 a
l2, Quaternion a
u1 V3 a
u2) =
[ forall a. a -> V3 a -> Quaternion a
Quaternion a
i1 V3 a
i2 | a
i1 <- forall a. Ix a => (a, a) -> [a]
range (a
l1,a
u1), V3 a
i2 <- forall a. Ix a => (a, a) -> [a]
range (V3 a
l2,V3 a
u2) ]
{-# INLINE range #-}
unsafeIndex :: (Quaternion a, Quaternion a) -> Quaternion a -> Int
unsafeIndex (Quaternion a
l1 V3 a
l2, Quaternion a
u1 V3 a
u2) (Quaternion a
i1 V3 a
i2) =
forall a. Ix a => (a, a) -> a -> Int
unsafeIndex (a
l1,a
u1) a
i1 forall a. Num a => a -> a -> a
* forall a. Ix a => (a, a) -> Int
unsafeRangeSize (V3 a
l2,V3 a
u2) forall a. Num a => a -> a -> a
+ forall a. Ix a => (a, a) -> a -> Int
unsafeIndex (V3 a
l2,V3 a
u2) V3 a
i2
{-# INLINE unsafeIndex #-}
inRange :: (Quaternion a, Quaternion a) -> Quaternion a -> Bool
inRange (Quaternion a
l1 V3 a
l2, Quaternion a
u1 V3 a
u2) (Quaternion a
i1 V3 a
i2) =
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 (V3 a
l2,V3 a
u2) V3 a
i2
{-# INLINE inRange #-}
instance Representable Quaternion where
type Rep Quaternion = E Quaternion
tabulate :: forall a. (Rep Quaternion -> a) -> Quaternion a
tabulate Rep Quaternion -> a
f = forall a. a -> V3 a -> Quaternion a
Quaternion (Rep Quaternion -> a
f forall (t :: * -> *). Complicated t => E t
ee) (forall a. a -> a -> a -> V3 a
V3 (Rep Quaternion -> a
f forall (t :: * -> *). Complicated t => E t
ei) (Rep Quaternion -> a
f forall (t :: * -> *). Hamiltonian t => E t
ej) (Rep Quaternion -> a
f forall (t :: * -> *). Hamiltonian t => E t
ek))
{-# INLINE tabulate #-}
index :: forall a. Quaternion a -> Rep Quaternion -> a
index Quaternion a
xs (E forall x. Lens' (Quaternion x) x
l) = forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall x. Lens' (Quaternion x) x
l Quaternion a
xs
{-# INLINE index #-}
instance WithIndex.FunctorWithIndex (E Quaternion) Quaternion where
imap :: forall a b.
(E Quaternion -> a -> b) -> Quaternion a -> Quaternion b
imap E Quaternion -> a -> b
f (Quaternion a
a (V3 a
b a
c a
d)) = forall a. a -> V3 a -> Quaternion a
Quaternion (E Quaternion -> a -> b
f forall (t :: * -> *). Complicated t => E t
ee a
a) forall a b. (a -> b) -> a -> b
$ forall a. a -> a -> a -> V3 a
V3 (E Quaternion -> a -> b
f forall (t :: * -> *). Complicated t => E t
ei a
b) (E Quaternion -> a -> b
f forall (t :: * -> *). Hamiltonian t => E t
ej a
c) (E Quaternion -> a -> b
f forall (t :: * -> *). Hamiltonian t => E t
ek a
d)
{-# INLINE imap #-}
instance WithIndex.FoldableWithIndex (E Quaternion) Quaternion where
ifoldMap :: forall m a.
Monoid m =>
(E Quaternion -> a -> m) -> Quaternion a -> m
ifoldMap E Quaternion -> a -> m
f (Quaternion a
a (V3 a
b a
c a
d)) = E Quaternion -> a -> m
f forall (t :: * -> *). Complicated t => E t
ee a
a forall a. Monoid a => a -> a -> a
`mappend` E Quaternion -> a -> m
f forall (t :: * -> *). Complicated t => E t
ei a
b forall a. Monoid a => a -> a -> a
`mappend` E Quaternion -> a -> m
f forall (t :: * -> *). Hamiltonian t => E t
ej a
c forall a. Monoid a => a -> a -> a
`mappend` E Quaternion -> a -> m
f forall (t :: * -> *). Hamiltonian t => E t
ek a
d
{-# INLINE ifoldMap #-}
instance WithIndex.TraversableWithIndex (E Quaternion) Quaternion where
itraverse :: forall (f :: * -> *) a b.
Applicative f =>
(E Quaternion -> a -> f b) -> Quaternion a -> f (Quaternion b)
itraverse E Quaternion -> a -> f b
f (Quaternion a
a (V3 a
b a
c a
d)) = forall a. a -> V3 a -> Quaternion a
Quaternion forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> E Quaternion -> a -> f b
f forall (t :: * -> *). Complicated t => E t
ee a
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall a. a -> a -> a -> V3 a
V3 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> E Quaternion -> a -> f b
f forall (t :: * -> *). Complicated t => E t
ei a
b forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> E Quaternion -> a -> f b
f forall (t :: * -> *). Hamiltonian t => E t
ej a
c forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> E Quaternion -> a -> f b
f forall (t :: * -> *). Hamiltonian t => E t
ek a
d)
{-# INLINE itraverse #-}
#if !MIN_VERSION_lens(5,0,0)
instance Lens.FunctorWithIndex (E Quaternion) Quaternion where imap = WithIndex.imap
instance Lens.FoldableWithIndex (E Quaternion) Quaternion where ifoldMap = WithIndex.ifoldMap
instance Lens.TraversableWithIndex (E Quaternion) Quaternion where itraverse = WithIndex.itraverse
#endif
type instance Index (Quaternion a) = E Quaternion
type instance IxValue (Quaternion a) = a
instance Ixed (Quaternion a) where
ix :: Index (Quaternion a)
-> Traversal' (Quaternion a) (IxValue (Quaternion a))
ix Index (Quaternion a)
i = forall (t :: * -> *). E t -> forall x. Lens' (t x) x
el Index (Quaternion a)
i
{-# INLINE ix #-}
instance Each (Quaternion a) (Quaternion b) a b where
each :: Traversal (Quaternion a) (Quaternion b) a b
each = forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse
{-# INLINE each #-}
instance Foldable Quaternion where
foldMap :: forall m a. Monoid m => (a -> m) -> Quaternion a -> m
foldMap a -> m
f (Quaternion a
e V3 a
v) = a -> m
f a
e forall a. Monoid a => a -> a -> a
`mappend` forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f V3 a
v
{-# INLINE foldMap #-}
foldr :: forall a b. (a -> b -> b) -> b -> Quaternion a -> b
foldr a -> b -> b
f b
z (Quaternion a
e V3 a
v) = a -> b -> b
f a
e (forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr a -> b -> b
f b
z V3 a
v)
{-# INLINE foldr #-}
null :: forall a. Quaternion a -> Bool
null Quaternion a
_ = Bool
False
length :: forall a. Quaternion a -> Int
length Quaternion a
_ = Int
4
instance Traversable Quaternion where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Quaternion a -> f (Quaternion b)
traverse a -> f b
f (Quaternion a
e V3 a
v) = forall a. a -> V3 a -> Quaternion a
Quaternion forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
e forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> f b
f V3 a
v
{-# INLINE traverse #-}
instance Storable a => Storable (Quaternion a) where
sizeOf :: Quaternion a -> Int
sizeOf Quaternion a
_ = Int
4 forall a. Num a => a -> a -> a
* forall a. Storable a => a -> Int
sizeOf (forall a. HasCallStack => a
undefined::a)
{-# INLINE sizeOf #-}
alignment :: Quaternion a -> Int
alignment Quaternion a
_ = forall a. Storable a => a -> Int
alignment (forall a. HasCallStack => a
undefined::a)
{-# INLINE alignment #-}
poke :: Ptr (Quaternion a) -> Quaternion a -> IO ()
poke Ptr (Quaternion a)
ptr (Quaternion a
e V3 a
v) = forall a. Storable a => Ptr a -> a -> IO ()
poke (forall a b. Ptr a -> Ptr b
castPtr Ptr (Quaternion a)
ptr) a
e forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
forall a. Storable a => Ptr a -> a -> IO ()
poke (forall a b. Ptr a -> Ptr b
castPtr (Ptr (Quaternion a)
ptr forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
sz)) V3 a
v
where sz :: Int
sz = forall a. Storable a => a -> Int
sizeOf (forall a. HasCallStack => a
undefined::a)
{-# INLINE poke #-}
peek :: Ptr (Quaternion a) -> IO (Quaternion a)
peek Ptr (Quaternion a)
ptr = forall a. a -> V3 a -> Quaternion a
Quaternion forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Storable a => Ptr a -> IO a
peek (forall a b. Ptr a -> Ptr b
castPtr Ptr (Quaternion a)
ptr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Storable a => Ptr a -> IO a
peek (forall a b. Ptr a -> Ptr b
castPtr (Ptr (Quaternion a)
ptr forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
sz))
where sz :: Int
sz = forall a. Storable a => a -> Int
sizeOf (forall a. HasCallStack => a
undefined::a)
{-# INLINE peek #-}
instance RealFloat a => Num (Quaternion a) where
{-# SPECIALIZE instance Num (Quaternion Float) #-}
{-# SPECIALIZE instance Num (Quaternion Double) #-}
+ :: Quaternion a -> Quaternion a -> Quaternion 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 (-) #-}
negate :: Quaternion a -> Quaternion a
negate = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Num a => a -> a
negate
{-# INLINE negate #-}
Quaternion a
s1 V3 a
v1 * :: Quaternion a -> Quaternion a -> Quaternion a
* Quaternion a
s2 V3 a
v2 = forall a. a -> V3 a -> Quaternion a
Quaternion (a
s1forall a. Num a => a -> a -> a
*a
s2 forall a. Num a => a -> a -> a
- (V3 a
v1 forall (f :: * -> *) a. (Metric f, Num a) => f a -> f a -> a
`dot` V3 a
v2)) forall a b. (a -> b) -> a -> b
$
(V3 a
v1 forall a. Num a => V3 a -> V3 a -> V3 a
`cross` V3 a
v2) forall a. Num a => a -> a -> a
+ a
s1forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
*^V3 a
v2 forall a. Num a => a -> a -> a
+ a
s2forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
*^V3 a
v1
{-# INLINE (*) #-}
fromInteger :: Integer -> Quaternion a
fromInteger Integer
x = forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Num a => Integer -> a
fromInteger Integer
x) V3 a
0
{-# INLINE fromInteger #-}
abs :: Quaternion a -> Quaternion a
abs Quaternion a
z = forall a. a -> V3 a -> Quaternion a
Quaternion (forall (f :: * -> *) a. (Metric f, Floating a) => f a -> a
norm Quaternion a
z) V3 a
0
{-# INLINE abs #-}
signum :: Quaternion a -> Quaternion a
signum q :: Quaternion a
q@(Quaternion a
e (V3 a
i a
j a
k))
| a
m forall a. Eq a => a -> a -> Bool
== a
0.0 = Quaternion a
q
| Bool -> Bool
not (forall a. RealFloat a => a -> Bool
isInfinite a
m Bool -> Bool -> Bool
|| forall a. RealFloat a => a -> Bool
isNaN a
m) = Quaternion a
q forall (f :: * -> *) a.
(Functor f, Fractional a) =>
f a -> a -> f a
^/ forall a. Floating a => a -> a
sqrt a
m
| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any forall a. RealFloat a => a -> Bool
isNaN Quaternion a
q = forall a. RealFloat a => Quaternion a
qNaN
| Bool -> Bool
not (Bool
ii Bool -> Bool -> Bool
|| Bool
ij Bool -> Bool -> Bool
|| Bool
ik) = forall a. a -> V3 a -> Quaternion a
Quaternion a
1 (forall a. a -> a -> a -> V3 a
V3 a
0 a
0 a
0)
| Bool -> Bool
not (Bool
ie Bool -> Bool -> Bool
|| Bool
ij Bool -> Bool -> Bool
|| Bool
ik) = forall a. a -> V3 a -> Quaternion a
Quaternion a
0 (forall a. a -> a -> a -> V3 a
V3 a
1 a
0 a
0)
| Bool -> Bool
not (Bool
ie Bool -> Bool -> Bool
|| Bool
ii Bool -> Bool -> Bool
|| Bool
ik) = forall a. a -> V3 a -> Quaternion a
Quaternion a
0 (forall a. a -> a -> a -> V3 a
V3 a
0 a
1 a
0)
| Bool -> Bool
not (Bool
ie Bool -> Bool -> Bool
|| Bool
ii Bool -> Bool -> Bool
|| Bool
ij) = forall a. a -> V3 a -> Quaternion a
Quaternion a
0 (forall a. a -> a -> a -> V3 a
V3 a
0 a
0 a
1)
| Bool
otherwise = forall a. RealFloat a => Quaternion a
qNaN
where
m :: a
m = forall (f :: * -> *) a. (Metric f, Num a) => f a -> a
quadrance Quaternion a
q
ie :: Bool
ie = forall a. RealFloat a => a -> Bool
isInfinite a
e
ii :: Bool
ii = forall a. RealFloat a => a -> Bool
isInfinite a
i
ij :: Bool
ij = forall a. RealFloat a => a -> Bool
isInfinite a
j
ik :: Bool
ik = forall a. RealFloat a => a -> Bool
isInfinite a
k
{-# INLINE signum #-}
instance Hashable a => Hashable (Quaternion a) where
hashWithSalt :: Int -> Quaternion a -> Int
hashWithSalt Int
s (Quaternion a
a V3 a
b) = Int
s forall a. Hashable a => Int -> a -> Int
`hashWithSalt` a
a forall a. Hashable a => Int -> a -> Int
`hashWithSalt` V3 a
b
{-# INLINE hashWithSalt #-}
instance Hashable1 Quaternion where
liftHashWithSalt :: forall a. (Int -> a -> Int) -> Int -> Quaternion a -> Int
liftHashWithSalt Int -> a -> Int
h Int
s (Quaternion a
a V3 a
b) = forall (t :: * -> *) a.
Hashable1 t =>
(Int -> a -> Int) -> Int -> t a -> Int
liftHashWithSalt Int -> a -> Int
h (Int -> a -> Int
h Int
s a
a) V3 a
b
{-# INLINE liftHashWithSalt #-}
qNaN :: RealFloat a => Quaternion a
qNaN :: forall a. RealFloat a => Quaternion a
qNaN = forall a. a -> V3 a -> Quaternion a
Quaternion a
fNaN (forall a. a -> a -> a -> V3 a
V3 a
fNaN a
fNaN a
fNaN) where fNaN :: a
fNaN = a
0forall a. Fractional a => a -> a -> a
/a
0
{-# INLINE qNaN #-}
instance RealFloat a => Fractional (Quaternion a) where
{-# SPECIALIZE instance Fractional (Quaternion Float) #-}
{-# SPECIALIZE instance Fractional (Quaternion Double) #-}
Quaternion a
q0 (V3 a
q1 a
q2 a
q3) / :: Quaternion a -> Quaternion a -> Quaternion a
/ Quaternion a
r0 (V3 a
r1 a
r2 a
r3) =
forall a. a -> V3 a -> Quaternion a
Quaternion (a
r0forall a. Num a => a -> a -> a
*a
q0forall a. Num a => a -> a -> a
+a
r1forall a. Num a => a -> a -> a
*a
q1forall a. Num a => a -> a -> a
+a
r2forall a. Num a => a -> a -> a
*a
q2forall a. Num a => a -> a -> a
+a
r3forall a. Num a => a -> a -> a
*a
q3)
(forall a. a -> a -> a -> V3 a
V3 (a
r0forall a. Num a => a -> a -> a
*a
q1forall a. Num a => a -> a -> a
-a
r1forall a. Num a => a -> a -> a
*a
q0forall a. Num a => a -> a -> a
-a
r2forall a. Num a => a -> a -> a
*a
q3forall a. Num a => a -> a -> a
+a
r3forall a. Num a => a -> a -> a
*a
q2)
(a
r0forall a. Num a => a -> a -> a
*a
q2forall a. Num a => a -> a -> a
+a
r1forall a. Num a => a -> a -> a
*a
q3forall a. Num a => a -> a -> a
-a
r2forall a. Num a => a -> a -> a
*a
q0forall a. Num a => a -> a -> a
-a
r3forall a. Num a => a -> a -> a
*a
q1)
(a
r0forall a. Num a => a -> a -> a
*a
q3forall a. Num a => a -> a -> a
-a
r1forall a. Num a => a -> a -> a
*a
q2forall a. Num a => a -> a -> a
+a
r2forall a. Num a => a -> a -> a
*a
q1forall a. Num a => a -> a -> a
-a
r3forall a. Num a => a -> a -> a
*a
q0))
forall (f :: * -> *) a.
(Functor f, Fractional a) =>
f a -> a -> f a
^/ (a
r0forall a. Num a => a -> a -> a
*a
r0 forall a. Num a => a -> a -> a
+ a
r1forall a. Num a => a -> a -> a
*a
r1 forall a. Num a => a -> a -> a
+ a
r2forall a. Num a => a -> a -> a
*a
r2 forall a. Num a => a -> a -> a
+ a
r3forall a. Num a => a -> a -> a
*a
r3)
{-# INLINE (/) #-}
recip :: Quaternion a -> Quaternion a
recip q :: Quaternion a
q@(Quaternion a
e V3 a
v) = forall a. a -> V3 a -> Quaternion a
Quaternion a
e (forall a. Num a => a -> a
negate V3 a
v) forall (f :: * -> *) a.
(Functor f, Fractional a) =>
f a -> a -> f a
^/ forall (f :: * -> *) a. (Metric f, Num a) => f a -> a
quadrance Quaternion a
q
{-# INLINE recip #-}
fromRational :: Rational -> Quaternion a
fromRational Rational
x = forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Fractional a => Rational -> a
fromRational Rational
x) V3 a
0
{-# INLINE fromRational #-}
instance Metric Quaternion where
Quaternion a
e V3 a
v dot :: forall a. Num a => Quaternion a -> Quaternion a -> a
`dot` Quaternion a
e' V3 a
v' = a
eforall a. Num a => a -> a -> a
*a
e' forall a. Num a => a -> a -> a
+ (V3 a
v forall (f :: * -> *) a. (Metric f, Num a) => f a -> f a -> a
`dot` V3 a
v')
{-# INLINE dot #-}
class Complicated t where
_e, _i :: Lens' (t a) a
ee, ei :: Complicated t => E t
ee :: forall (t :: * -> *). Complicated t => E t
ee = forall (t :: * -> *). (forall x. Lens' (t x) x) -> E t
E forall (t :: * -> *) a. Complicated t => Lens' (t a) a
_e
ei :: forall (t :: * -> *). Complicated t => E t
ei = forall (t :: * -> *). (forall x. Lens' (t x) x) -> E t
E forall (t :: * -> *) a. Complicated t => Lens' (t a) a
_i
instance Complicated Complex where
_e :: forall a. Lens' (Complex a) a
_e a -> f a
f (a
a :+ a
b) = (forall a. a -> a -> Complex a
:+ a
b) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
f a
a
{-# INLINE _e #-}
_i :: forall a. Lens' (Complex a) a
_i a -> f a
f (a
a :+ a
b) = (a
a forall a. a -> a -> Complex a
:+) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
f a
b
{-# INLINE _i #-}
instance Complicated Quaternion where
_e :: forall x. Lens' (Quaternion x) x
_e a -> f a
f (Quaternion a
a V3 a
v) = (forall a. a -> V3 a -> Quaternion a
`Quaternion` V3 a
v) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
f a
a
{-# INLINE _e #-}
_i :: forall x. Lens' (Quaternion x) x
_i a -> f a
f (Quaternion a
a V3 a
v) = forall a. a -> V3 a -> Quaternion a
Quaternion a
a forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) a. R1 t => Lens' (t a) a
_x a -> f a
f V3 a
v
{-# INLINE _i #-}
class Complicated t => Hamiltonian t where
_j, _k :: Lens' (t a) a
_ijk :: Lens' (t a) (V3 a)
ej, ek :: Hamiltonian t => E t
ej :: forall (t :: * -> *). Hamiltonian t => E t
ej = forall (t :: * -> *). (forall x. Lens' (t x) x) -> E t
E forall (t :: * -> *) a. Hamiltonian t => Lens' (t a) a
_j
ek :: forall (t :: * -> *). Hamiltonian t => E t
ek = forall (t :: * -> *). (forall x. Lens' (t x) x) -> E t
E forall (t :: * -> *) a. Hamiltonian t => Lens' (t a) a
_k
instance Hamiltonian Quaternion where
_j :: forall x. Lens' (Quaternion x) x
_j a -> f a
f (Quaternion a
a V3 a
v) = forall a. a -> V3 a -> Quaternion a
Quaternion a
a forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) a. R2 t => Lens' (t a) a
_y a -> f a
f V3 a
v
{-# INLINE _j #-}
_k :: forall x. Lens' (Quaternion x) x
_k a -> f a
f (Quaternion a
a V3 a
v) = forall a. a -> V3 a -> Quaternion a
Quaternion a
a forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) a. R3 t => Lens' (t a) a
_z a -> f a
f V3 a
v
{-# INLINE _k #-}
_ijk :: forall a. Lens' (Quaternion a) (V3 a)
_ijk V3 a -> f (V3 a)
f (Quaternion a
a V3 a
v) = forall a. a -> V3 a -> Quaternion a
Quaternion a
a forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> V3 a -> f (V3 a)
f V3 a
v
{-# INLINE _ijk #-}
instance Distributive Quaternion where
distribute :: forall (f :: * -> *) a.
Functor f =>
f (Quaternion a) -> Quaternion (f a)
distribute f (Quaternion a)
f = forall a. a -> V3 a -> Quaternion a
Quaternion (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Quaternion a
x V3 a
_) -> a
x) f (Quaternion a)
f) forall a b. (a -> b) -> a -> b
$ forall a. a -> a -> a -> V3 a
V3
(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Quaternion a
_ (V3 a
y a
_ a
_)) -> a
y) f (Quaternion a)
f)
(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Quaternion a
_ (V3 a
_ a
z a
_)) -> a
z) f (Quaternion a)
f)
(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Quaternion a
_ (V3 a
_ a
_ a
w)) -> a
w) f (Quaternion a)
f)
{-# INLINE distribute #-}
instance (Conjugate a, RealFloat a) => Conjugate (Quaternion a) where
conjugate :: Quaternion a -> Quaternion a
conjugate (Quaternion a
e V3 a
v) = forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Conjugate a => a -> a
conjugate a
e) (forall a. Num a => a -> a
negate V3 a
v)
{-# INLINE conjugate #-}
reimagine :: RealFloat a => a -> a -> Quaternion a -> Quaternion a
reimagine :: forall a. RealFloat a => a -> a -> Quaternion a -> Quaternion a
reimagine a
r a
s (Quaternion a
_ V3 a
v)
| forall a. RealFloat a => a -> Bool
isNaN a
s Bool -> Bool -> Bool
|| forall a. RealFloat a => a -> Bool
isInfinite a
s = let aux :: a -> a
aux a
0 = a
0
aux a
x = a
s forall a. Num a => a -> a -> a
* a
x
in forall a. a -> V3 a -> Quaternion a
Quaternion a
r (a -> a
aux forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> V3 a
v)
| Bool
otherwise = forall a. a -> V3 a -> Quaternion a
Quaternion a
r (V3 a
vforall (f :: * -> *) a. (Functor f, Num a) => f a -> a -> f a
^*a
s)
{-# INLINE reimagine #-}
qi :: Num a => Quaternion a -> a
qi :: forall a. Num a => Quaternion a -> a
qi (Quaternion a
_ V3 a
v) = forall (f :: * -> *) a. (Metric f, Num a) => f a -> a
quadrance V3 a
v
{-# INLINE qi #-}
absi :: Floating a => Quaternion a -> a
absi :: forall a. Floating a => Quaternion a -> a
absi = forall a. Floating a => a -> a
sqrt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => Quaternion a -> a
qi
{-# INLINE absi #-}
pow :: RealFloat a => Quaternion a -> a -> Quaternion a
pow :: forall a. RealFloat a => Quaternion a -> a -> Quaternion a
pow Quaternion a
q a
t = forall a. Floating a => a -> a
exp (a
t forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
*^ forall a. Floating a => a -> a
log Quaternion a
q)
{-# INLINE pow #-}
sqrte2pqiq :: (Floating a, Ord a) => a -> a -> a
sqrte2pqiq :: forall a. (Floating a, Ord a) => a -> a -> a
sqrte2pqiq a
e a
qiq
| a
e forall a. Ord a => a -> a -> Bool
< - a
1.5097698010472593e153 = -(a
qiqforall a. Fractional a => a -> a -> a
/a
e) forall a. Num a => a -> a -> a
- a
e
| a
e forall a. Ord a => a -> a -> Bool
< a
5.582399551122541e57 = forall a. Floating a => a -> a
sqrt (a
eforall a. Num a => a -> a -> a
*a
e forall a. Num a => a -> a -> a
+ a
qiq)
| Bool
otherwise = (a
qiqforall a. Fractional a => a -> a -> a
/a
e) forall a. Num a => a -> a -> a
+ a
e
#ifdef HERBIE
{-# ANN sqrte2pqiq "NoHerbie" #-}
#endif
tanrhs :: (Floating a, Ord a) => a -> a -> a -> a
tanrhs :: forall a. (Floating a, Ord a) => a -> a -> a -> a
tanrhs a
sai a
ai a
d
| a
sai forall a. Ord a => a -> a -> Bool
< -a
4.618902267687042e-52 = (a
sai forall a. Fractional a => a -> a -> a
/ a
d forall a. Fractional a => a -> a -> a
/ a
ai) forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
cosh a
ai
| a
sai forall a. Ord a => a -> a -> Bool
< a
1.038530535935153e-39 = (forall a. Floating a => a -> a
cosh a
ai forall a. Num a => a -> a -> a
* a
sai) forall a. Fractional a => a -> a -> a
/ a
ai forall a. Fractional a => a -> a -> a
/ a
d
| Bool
otherwise = (a
sai forall a. Fractional a => a -> a -> a
/ a
d forall a. Fractional a => a -> a -> a
/ a
ai) forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
cosh a
ai
#ifdef HERBIE
{-# ANN tanrhs "NoHerbie" #-}
#endif
instance RealFloat a => Floating (Quaternion a) where
{-# SPECIALIZE instance Floating (Quaternion Float) #-}
{-# SPECIALIZE instance Floating (Quaternion Double) #-}
pi :: Quaternion a
pi = forall a. a -> V3 a -> Quaternion a
Quaternion forall a. Floating a => a
pi V3 a
0
{-# INLINE pi #-}
exp :: Quaternion a -> Quaternion a
exp q :: Quaternion a
q@(Quaternion a
e V3 a
v)
| a
qiq forall a. Eq a => a -> a -> Bool
== a
0 = forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Floating a => a -> a
exp a
e) V3 a
v
| a
ai <- forall a. Floating a => a -> a
sqrt a
qiq, a
exe <- forall a. Floating a => a -> a
exp a
e = forall a. RealFloat a => a -> a -> Quaternion a -> Quaternion a
reimagine (a
exe forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
cos a
ai) (a
exe forall a. Num a => a -> a -> a
* (forall a. Floating a => a -> a
sin a
ai forall a. Fractional a => a -> a -> a
/ a
ai)) Quaternion a
q
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE exp #-}
log :: Quaternion a -> Quaternion a
log q :: Quaternion a
q@(Quaternion a
e V3 a
v)
| a
qiq forall a. Eq a => a -> a -> Bool
== a
0 = if a
e forall a. Ord a => a -> a -> Bool
>= a
0
then forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Floating a => a -> a
log a
e) V3 a
v
else forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Num a => a -> a
negate (forall a. Floating a => a -> a
log (forall a. Num a => a -> a
negate a
e))) V3 a
v
| a
ai <- forall a. Floating a => a -> a
sqrt a
qiq = forall a. RealFloat a => a -> a -> Quaternion a -> Quaternion a
reimagine (forall a. Floating a => a -> a
log a
m) (forall a. Floating a => a -> a
acos (a
e forall a. Fractional a => a -> a -> a
/ a
m) forall a. Fractional a => a -> a -> a
/ a
ai) Quaternion a
q
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
m :: a
m = forall a. (Floating a, Ord a) => a -> a -> a
sqrte2pqiq a
e a
qiq
{-# INLINE log #-}
Quaternion a
x ** :: Quaternion a -> Quaternion a -> Quaternion a
** Quaternion a
y = forall a. Floating a => a -> a
exp (Quaternion a
y forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
log Quaternion a
x)
{-# INLINE (**) #-}
sqrt :: Quaternion a -> Quaternion a
sqrt q :: Quaternion a
q@(Quaternion a
e V3 a
v)
| a
m forall a. Eq a => a -> a -> Bool
== a
0 = Quaternion a
q
| a
qiq forall a. Eq a => a -> a -> Bool
== a
0 = if a
e forall a. Ord a => a -> a -> Bool
> a
0
then forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Floating a => a -> a
sqrt a
e) V3 a
0
else forall a. a -> V3 a -> Quaternion a
Quaternion a
0 (forall a. a -> a -> a -> V3 a
V3 (forall a. Floating a => a -> a
sqrt (forall a. Num a => a -> a
negate a
e)) a
0 a
0)
| a
im <- forall a. Floating a => a -> a
sqrt (a
0.5forall a. Num a => a -> a -> a
*(a
mforall a. Num a => a -> a -> a
-a
e)) forall a. Fractional a => a -> a -> a
/ forall a. Floating a => a -> a
sqrt a
qiq = forall a. a -> V3 a -> Quaternion a
Quaternion (a
0.5forall a. Num a => a -> a -> a
*(a
mforall a. Num a => a -> a -> a
+a
e)) (V3 a
vforall (f :: * -> *) a. (Functor f, Num a) => f a -> a -> f a
^*a
im)
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
m :: a
m = forall a. (Floating a, Ord a) => a -> a -> a
sqrte2pqiq a
e a
qiq
{-# INLINE sqrt #-}
cos :: Quaternion a -> Quaternion a
cos q :: Quaternion a
q@(Quaternion a
e V3 a
v)
| a
qiq forall a. Eq a => a -> a -> Bool
== a
0 = forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Floating a => a -> a
cos a
e) V3 a
v
| a
ai <- forall a. Floating a => a -> a
sqrt a
qiq = forall a. RealFloat a => a -> a -> Quaternion a -> Quaternion a
reimagine (forall a. Floating a => a -> a
cos a
e forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
cosh a
ai) (- forall a. Floating a => a -> a
sin a
e forall a. Fractional a => a -> a -> a
/ a
ai forall a. Fractional a => a -> a -> a
/ forall a. Floating a => a -> a
sinh a
ai) Quaternion a
q
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE cos #-}
sin :: Quaternion a -> Quaternion a
sin q :: Quaternion a
q@(Quaternion a
e V3 a
v)
| a
qiq forall a. Eq a => a -> a -> Bool
== a
0 = forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Floating a => a -> a
sin a
e) V3 a
v
| a
ai <- forall a. Floating a => a -> a
sqrt a
qiq = forall a. RealFloat a => a -> a -> Quaternion a -> Quaternion a
reimagine (forall a. Floating a => a -> a
sin a
e forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
cosh a
ai) (forall a. Floating a => a -> a
cos a
e forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
sinh a
ai forall a. Fractional a => a -> a -> a
/ a
ai) Quaternion a
q
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE sin #-}
tan :: Quaternion a -> Quaternion a
tan q :: Quaternion a
q@(Quaternion a
e V3 a
v)
| a
qiq forall a. Eq a => a -> a -> Bool
== a
0 = forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Floating a => a -> a
tan a
e) V3 a
v
| a
ai <- forall a. Floating a => a -> a
sqrt a
qiq, a
ce <- forall a. Floating a => a -> a
cos a
e, a
sai <- forall a. Floating a => a -> a
sinh a
ai, a
d <- a
ceforall a. Num a => a -> a -> a
*a
ce forall a. Num a => a -> a -> a
+ a
saiforall a. Num a => a -> a -> a
*a
sai =
forall a. RealFloat a => a -> a -> Quaternion a -> Quaternion a
reimagine (a
ce forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
sin a
e forall a. Fractional a => a -> a -> a
/ a
d) (forall a. (Floating a, Ord a) => a -> a -> a -> a
tanrhs a
sai a
ai a
d) Quaternion a
q
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE tan #-}
sinh :: Quaternion a -> Quaternion a
sinh q :: Quaternion a
q@(Quaternion a
e V3 a
v)
| a
qiq forall a. Eq a => a -> a -> Bool
== a
0 = forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Floating a => a -> a
sinh a
e) V3 a
v
| a
ai <- forall a. Floating a => a -> a
sqrt a
qiq = forall a. RealFloat a => a -> a -> Quaternion a -> Quaternion a
reimagine (forall a. Floating a => a -> a
sinh a
e forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
cos a
ai) (forall a. Floating a => a -> a
cosh a
e forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
sin a
ai forall a. Fractional a => a -> a -> a
/ a
ai) Quaternion a
q
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE sinh #-}
cosh :: Quaternion a -> Quaternion a
cosh q :: Quaternion a
q@(Quaternion a
e V3 a
v)
| a
qiq forall a. Eq a => a -> a -> Bool
== a
0 = forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Floating a => a -> a
cosh a
e) V3 a
v
| a
ai <- forall a. Floating a => a -> a
sqrt a
qiq = forall a. RealFloat a => a -> a -> Quaternion a -> Quaternion a
reimagine (forall a. Floating a => a -> a
cosh a
e forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
cos a
ai) (forall a. Floating a => a -> a
sin a
ai forall a. Num a => a -> a -> a
* (forall a. Floating a => a -> a
sinh a
e forall a. Fractional a => a -> a -> a
/ a
ai)) Quaternion a
q
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE cosh #-}
tanh :: Quaternion a -> Quaternion a
tanh q :: Quaternion a
q@(Quaternion a
e V3 a
v)
| a
qiq forall a. Eq a => a -> a -> Bool
== a
0 = forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Floating a => a -> a
tanh a
e) V3 a
v
| a
ai <- forall a. Floating a => a -> a
sqrt a
qiq, a
se <- forall a. Floating a => a -> a
sinh a
e, a
cai <- forall a. Floating a => a -> a
cos a
ai, a
d <- a
seforall a. Num a => a -> a -> a
*a
se forall a. Num a => a -> a -> a
+ a
caiforall a. Num a => a -> a -> a
*a
cai =
forall a. RealFloat a => a -> a -> Quaternion a -> Quaternion a
reimagine (forall a. Floating a => a -> a
cosh a
e forall a. Num a => a -> a -> a
* a
se forall a. Fractional a => a -> a -> a
/ a
d) (forall a. (Floating a, Ord a) => a -> a -> a -> a
tanhrhs a
cai a
ai a
d) Quaternion a
q
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE tanh #-}
asin :: Quaternion a -> Quaternion a
asin = forall a.
RealFloat a =>
(Complex a -> Complex a) -> Quaternion a -> Quaternion a
cut forall a. Floating a => a -> a
asin
{-# INLINE asin #-}
acos :: Quaternion a -> Quaternion a
acos = forall a.
RealFloat a =>
(Complex a -> Complex a) -> Quaternion a -> Quaternion a
cut forall a. Floating a => a -> a
acos
{-# INLINE acos #-}
atan :: Quaternion a -> Quaternion a
atan = forall a.
RealFloat a =>
(Complex a -> Complex a) -> Quaternion a -> Quaternion a
cut forall a. Floating a => a -> a
atan
{-# INLINE atan #-}
asinh :: Quaternion a -> Quaternion a
asinh = forall a.
RealFloat a =>
(Complex a -> Complex a) -> Quaternion a -> Quaternion a
cut forall a. Floating a => a -> a
asinh
{-# INLINE asinh #-}
acosh :: Quaternion a -> Quaternion a
acosh = forall a.
RealFloat a =>
(Complex a -> Complex a) -> Quaternion a -> Quaternion a
cut forall a. Floating a => a -> a
acosh
{-# INLINE acosh #-}
atanh :: Quaternion a -> Quaternion a
atanh = forall a.
RealFloat a =>
(Complex a -> Complex a) -> Quaternion a -> Quaternion a
cut forall a. Floating a => a -> a
atanh
{-# INLINE atanh #-}
tanhrhs :: (Floating a, Ord a) => a -> a -> a -> a
tanhrhs :: forall a. (Floating a, Ord a) => a -> a -> a -> a
tanhrhs a
cai a
ai a
d
| a
d forall a. Ord a => a -> a -> Bool
>= -a
4.2173720203427147e-29 Bool -> Bool -> Bool
&& a
d forall a. Ord a => a -> a -> Bool
< a
4.446702369113811e64 = a
cai forall a. Fractional a => a -> a -> a
/ (a
d forall a. Num a => a -> a -> a
* (a
ai forall a. Fractional a => a -> a -> a
/ forall a. Floating a => a -> a
sin a
ai))
| Bool
otherwise = a
cai forall a. Num a => a -> a -> a
* (a
1 forall a. Fractional a => a -> a -> a
/ a
ai forall a. Fractional a => a -> a -> a
/ forall a. Floating a => a -> a
sin a
ai) forall a. Fractional a => a -> a -> a
/ a
d
#ifdef HERBIE
{-# ANN tanhrhs "NoHerbie" #-}
#endif
cut :: RealFloat a => (Complex a -> Complex a) -> Quaternion a -> Quaternion a
cut :: forall a.
RealFloat a =>
(Complex a -> Complex a) -> Quaternion a -> Quaternion a
cut Complex a -> Complex a
f q :: Quaternion a
q@(Quaternion a
e (V3 a
_ a
y a
z))
| a
qiq forall a. Eq a => a -> a -> Bool
== a
0 = forall a. a -> V3 a -> Quaternion a
Quaternion a
a (forall a. a -> a -> a -> V3 a
V3 a
b a
y a
z)
| Bool
otherwise = forall a. RealFloat a => a -> a -> Quaternion a -> Quaternion a
reimagine a
a (a
b forall a. Fractional a => a -> a -> a
/ a
ai) Quaternion a
q
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
ai :: a
ai = forall a. Floating a => a -> a
sqrt a
qiq
a
a :+ a
b = Complex a -> Complex a
f (a
e forall a. a -> a -> Complex a
:+ a
ai)
{-# INLINE cut #-}
cutWith :: RealFloat a => Complex a -> Quaternion a -> Quaternion a
cutWith :: forall a. RealFloat a => Complex a -> Quaternion a -> Quaternion a
cutWith (a
r :+ a
im) q :: Quaternion a
q@(Quaternion a
e V3 a
v)
| a
e forall a. Eq a => a -> a -> Bool
/= a
0 Bool -> Bool -> Bool
|| a
qiq forall a. Eq a => a -> a -> Bool
== a
0 Bool -> Bool -> Bool
|| forall a. RealFloat a => a -> Bool
isNaN a
qiq Bool -> Bool -> Bool
|| forall a. RealFloat a => a -> Bool
isInfinite a
qiq = forall a. HasCallStack => String -> a
error String
"bad cut"
| a
s <- a
im forall a. Fractional a => a -> a -> a
/ forall a. Floating a => a -> a
sqrt a
qiq = forall a. a -> V3 a -> Quaternion a
Quaternion a
r (V3 a
vforall (f :: * -> *) a. (Functor f, Num a) => f a -> a -> f a
^*a
s)
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE cutWith #-}
asinq :: RealFloat a => Quaternion a -> Quaternion a -> Quaternion a
asinq :: forall a.
RealFloat a =>
Quaternion a -> Quaternion a -> Quaternion a
asinq q :: Quaternion a
q@(Quaternion a
e V3 a
_) Quaternion a
u
| a
qiq forall a. Eq a => a -> a -> Bool
/= a
0.0 Bool -> Bool -> Bool
|| a
e forall a. Ord a => a -> a -> Bool
>= -a
1 Bool -> Bool -> Bool
&& a
e forall a. Ord a => a -> a -> Bool
<= a
1 = forall a. Floating a => a -> a
asin Quaternion a
q
| Bool
otherwise = forall a. RealFloat a => Complex a -> Quaternion a -> Quaternion a
cutWith (forall a. Floating a => a -> a
asin (a
e forall a. a -> a -> Complex a
:+ forall a. Floating a => a -> a
sqrt a
qiq)) Quaternion a
u
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE asinq #-}
acosq :: RealFloat a => Quaternion a -> Quaternion a -> Quaternion a
acosq :: forall a.
RealFloat a =>
Quaternion a -> Quaternion a -> Quaternion a
acosq q :: Quaternion a
q@(Quaternion a
e V3 a
_) Quaternion a
u
| a
qiq forall a. Eq a => a -> a -> Bool
/= a
0.0 Bool -> Bool -> Bool
|| a
e forall a. Ord a => a -> a -> Bool
>= -a
1 Bool -> Bool -> Bool
&& a
e forall a. Ord a => a -> a -> Bool
<= a
1 = forall a. Floating a => a -> a
acos Quaternion a
q
| Bool
otherwise = forall a. RealFloat a => Complex a -> Quaternion a -> Quaternion a
cutWith (forall a. Floating a => a -> a
acos (a
e forall a. a -> a -> Complex a
:+ forall a. Floating a => a -> a
sqrt a
qiq)) Quaternion a
u
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE acosq #-}
atanq :: RealFloat a => Quaternion a -> Quaternion a -> Quaternion a
atanq :: forall a.
RealFloat a =>
Quaternion a -> Quaternion a -> Quaternion a
atanq q :: Quaternion a
q@(Quaternion a
e V3 a
_) Quaternion a
u
| a
e forall a. Eq a => a -> a -> Bool
/= a
0.0 Bool -> Bool -> Bool
|| a
qiq forall a. Ord a => a -> a -> Bool
>= -a
1 Bool -> Bool -> Bool
&& a
qiq forall a. Ord a => a -> a -> Bool
<= a
1 = forall a. Floating a => a -> a
atan Quaternion a
q
| Bool
otherwise = forall a. RealFloat a => Complex a -> Quaternion a -> Quaternion a
cutWith (forall a. Floating a => a -> a
atan (a
e forall a. a -> a -> Complex a
:+ forall a. Floating a => a -> a
sqrt a
qiq)) Quaternion a
u
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE atanq #-}
asinhq :: RealFloat a => Quaternion a -> Quaternion a -> Quaternion a
asinhq :: forall a.
RealFloat a =>
Quaternion a -> Quaternion a -> Quaternion a
asinhq q :: Quaternion a
q@(Quaternion a
e V3 a
_) Quaternion a
u
| a
e forall a. Eq a => a -> a -> Bool
/= a
0.0 Bool -> Bool -> Bool
|| a
qiq forall a. Ord a => a -> a -> Bool
>= -a
1 Bool -> Bool -> Bool
&& a
qiq forall a. Ord a => a -> a -> Bool
<= a
1 = forall a. Floating a => a -> a
asinh Quaternion a
q
| Bool
otherwise = forall a. RealFloat a => Complex a -> Quaternion a -> Quaternion a
cutWith (forall a. Floating a => a -> a
asinh (a
e forall a. a -> a -> Complex a
:+ forall a. Floating a => a -> a
sqrt a
qiq)) Quaternion a
u
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE asinhq #-}
acoshq :: RealFloat a => Quaternion a -> Quaternion a -> Quaternion a
acoshq :: forall a.
RealFloat a =>
Quaternion a -> Quaternion a -> Quaternion a
acoshq q :: Quaternion a
q@(Quaternion a
e V3 a
_) Quaternion a
u
| a
qiq forall a. Eq a => a -> a -> Bool
/= a
0.0 Bool -> Bool -> Bool
|| a
e forall a. Ord a => a -> a -> Bool
>= a
1 = forall a. Floating a => a -> a
asinh Quaternion a
q
| Bool
otherwise = forall a. RealFloat a => Complex a -> Quaternion a -> Quaternion a
cutWith (forall a. Floating a => a -> a
acosh (a
e forall a. a -> a -> Complex a
:+ forall a. Floating a => a -> a
sqrt a
qiq)) Quaternion a
u
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE acoshq #-}
atanhq :: RealFloat a => Quaternion a -> Quaternion a -> Quaternion a
atanhq :: forall a.
RealFloat a =>
Quaternion a -> Quaternion a -> Quaternion a
atanhq q :: Quaternion a
q@(Quaternion a
e V3 a
_) Quaternion a
u
| a
qiq forall a. Eq a => a -> a -> Bool
/= a
0.0 Bool -> Bool -> Bool
|| a
e forall a. Ord a => a -> a -> Bool
> -a
1 Bool -> Bool -> Bool
&& a
e forall a. Ord a => a -> a -> Bool
< a
1 = forall a. Floating a => a -> a
atanh Quaternion a
q
| Bool
otherwise = forall a. RealFloat a => Complex a -> Quaternion a -> Quaternion a
cutWith (forall a. Floating a => a -> a
atanh (a
e forall a. a -> a -> Complex a
:+ forall a. Floating a => a -> a
sqrt a
qiq)) Quaternion a
u
where qiq :: a
qiq = forall a. Num a => Quaternion a -> a
qi Quaternion a
q
{-# INLINE atanhq #-}
slerp :: RealFloat a => Quaternion a -> Quaternion a -> a -> Quaternion a
slerp :: forall a.
RealFloat a =>
Quaternion a -> Quaternion a -> a -> Quaternion a
slerp Quaternion a
q Quaternion a
p a
t
| a
1.0 forall a. Num a => a -> a -> a
- a
cosphi forall a. Ord a => a -> a -> Bool
< a
1e-8 = Quaternion a
q
| Bool
otherwise = ((forall a. Floating a => a -> a
sin ((a
1forall a. Num a => a -> a -> a
-a
t)forall a. Num a => a -> a -> a
*a
phi) forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
*^ Quaternion a
q) forall a. Num a => a -> a -> a
+ forall a. Floating a => a -> a
sin (a
tforall a. Num a => a -> a -> a
*a
phi) forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
*^ Quaternion a -> Quaternion a
f Quaternion a
p) forall (f :: * -> *) a.
(Functor f, Fractional a) =>
f a -> a -> f a
^/ forall a. Floating a => a -> a
sin a
phi
where
dqp :: a
dqp = forall (f :: * -> *) a. (Metric f, Num a) => f a -> f a -> a
dot Quaternion a
q Quaternion a
p
(a
cosphi, Quaternion a -> Quaternion a
f) = if a
dqp forall a. Ord a => a -> a -> Bool
< a
0 then (-a
dqp, forall a. Num a => a -> a
negate) else (a
dqp, forall a. a -> a
id)
phi :: a
phi = forall a. Floating a => a -> a
acos a
cosphi
{-# SPECIALIZE slerp :: Quaternion Float -> Quaternion Float -> Float -> Quaternion Float #-}
{-# SPECIALIZE slerp :: Quaternion Double -> Quaternion Double -> Double -> Quaternion Double #-}
rotate :: (Conjugate a, RealFloat a) => Quaternion a -> V3 a -> V3 a
rotate :: forall a.
(Conjugate a, RealFloat a) =>
Quaternion a -> V3 a -> V3 a
rotate Quaternion a
q V3 a
v = V3 a
ijk where
Quaternion a
_ V3 a
ijk = Quaternion a
q forall a. Num a => a -> a -> a
* forall a. a -> V3 a -> Quaternion a
Quaternion a
0 V3 a
v forall a. Num a => a -> a -> a
* forall a. Conjugate a => a -> a
conjugate Quaternion a
q
{-# SPECIALIZE rotate :: Quaternion Float -> V3 Float -> V3 Float #-}
{-# SPECIALIZE rotate :: Quaternion Double -> V3 Double -> V3 Double #-}
instance (RealFloat a, Epsilon a) => Epsilon (Quaternion a) where
nearZero :: Quaternion 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 #-}
axisAngle :: (Epsilon a, Floating a) => V3 a -> a -> Quaternion a
axisAngle :: forall a. (Epsilon a, Floating a) => V3 a -> a -> Quaternion a
axisAngle V3 a
axis a
theta = forall a. a -> V3 a -> Quaternion a
Quaternion (forall a. Floating a => a -> a
cos a
half) (forall a. Floating a => a -> a
sin a
half forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
*^ forall a (f :: * -> *).
(Floating a, Metric f, Epsilon a) =>
f a -> f a
normalize V3 a
axis)
where half :: a
half = a
theta forall a. Fractional a => a -> a -> a
/ a
2
{-# INLINE axisAngle #-}
data instance U.Vector (Quaternion a) = V_Quaternion !Int (U.Vector a)
data instance U.MVector s (Quaternion a) = MV_Quaternion !Int (U.MVector s a)
instance U.Unbox a => U.Unbox (Quaternion a)
instance U.Unbox a => M.MVector U.MVector (Quaternion a) where
basicLength :: forall s. MVector s (Quaternion a) -> Int
basicLength (MV_Quaternion Int
n MVector s a
_) = Int
n
basicUnsafeSlice :: forall s.
Int -> Int -> MVector s (Quaternion a) -> MVector s (Quaternion a)
basicUnsafeSlice Int
m Int
n (MV_Quaternion Int
_ MVector s a
v) = forall s a. Int -> MVector s a -> MVector s (Quaternion a)
MV_Quaternion Int
n (forall (v :: * -> * -> *) a s.
MVector v a =>
Int -> Int -> v s a -> v s a
M.basicUnsafeSlice (Int
4forall a. Num a => a -> a -> a
*Int
m) (Int
4forall a. Num a => a -> a -> a
*Int
n) MVector s a
v)
basicOverlaps :: forall s.
MVector s (Quaternion a) -> MVector s (Quaternion a) -> Bool
basicOverlaps (MV_Quaternion Int
_ MVector s a
v) (MV_Quaternion 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 (Quaternion 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 (Quaternion a)
MV_Quaternion Int
n) (forall (v :: * -> * -> *) a s. MVector v a => Int -> ST s (v s a)
M.basicUnsafeNew (Int
4forall a. Num a => a -> a -> a
*Int
n))
basicUnsafeRead :: forall s. MVector s (Quaternion a) -> Int -> ST s (Quaternion a)
basicUnsafeRead (MV_Quaternion Int
_ MVector s a
v) Int
i =
do let o :: Int
o = Int
4forall 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)
a
w <- 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
3)
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> V3 a -> Quaternion a
Quaternion a
x (forall a. a -> a -> a -> V3 a
V3 a
y a
z a
w))
basicUnsafeWrite :: forall s.
MVector s (Quaternion a) -> Int -> Quaternion a -> ST s ()
basicUnsafeWrite (MV_Quaternion Int
_ MVector s a
v) Int
i (Quaternion a
x (V3 a
y a
z a
w)) =
do let o :: Int
o = Int
4forall 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
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
3) a
w
basicInitialize :: forall s. MVector s (Quaternion a) -> ST s ()
basicInitialize (MV_Quaternion Int
_ MVector s a
v) = forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
M.basicInitialize MVector s a
v
instance U.Unbox a => G.Vector U.Vector (Quaternion a) where
basicUnsafeFreeze :: forall s.
Mutable Vector s (Quaternion a) -> ST s (Vector (Quaternion a))
basicUnsafeFreeze (MV_Quaternion 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 (Quaternion a)
V_Quaternion 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 (Quaternion a) -> ST s (Mutable Vector s (Quaternion a))
basicUnsafeThaw ( V_Quaternion 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 (Quaternion a)
MV_Quaternion Int
n) (forall (v :: * -> *) a s. Vector v a => v a -> ST s (Mutable v s a)
G.basicUnsafeThaw Vector a
v)
basicLength :: Vector (Quaternion a) -> Int
basicLength ( V_Quaternion Int
n Vector a
_) = Int
n
basicUnsafeSlice :: Int -> Int -> Vector (Quaternion a) -> Vector (Quaternion a)
basicUnsafeSlice Int
m Int
n (V_Quaternion Int
_ Vector a
v) = forall a. Int -> Vector a -> Vector (Quaternion a)
V_Quaternion Int
n (forall (v :: * -> *) a. Vector v a => Int -> Int -> v a -> v a
G.basicUnsafeSlice (Int
4forall a. Num a => a -> a -> a
*Int
m) (Int
4forall a. Num a => a -> a -> a
*Int
n) Vector a
v)
basicUnsafeIndexM :: Vector (Quaternion a) -> Int -> Box (Quaternion a)
basicUnsafeIndexM (V_Quaternion Int
_ Vector a
v) Int
i =
do let o :: Int
o = Int
4forall 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)
a
w <- 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
3)
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> V3 a -> Quaternion a
Quaternion a
x (forall a. a -> a -> a -> V3 a
V3 a
y a
z a
w))
instance MonadZip Quaternion where
mzipWith :: forall a b c.
(a -> b -> c) -> Quaternion a -> Quaternion b -> Quaternion c
mzipWith = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2
instance MonadFix Quaternion where
mfix :: forall a. (a -> Quaternion a) -> Quaternion a
mfix a -> Quaternion a
f = forall a. a -> V3 a -> Quaternion a
Quaternion (let Quaternion a
a V3 a
_ = a -> Quaternion a
f a
a in a
a)
(forall a. a -> a -> a -> V3 a
V3 (let Quaternion a
_ (V3 a
a a
_ a
_) = a -> Quaternion a
f a
a in a
a)
(let Quaternion a
_ (V3 a
_ a
a a
_) = a -> Quaternion a
f a
a in a
a)
(let Quaternion a
_ (V3 a
_ a
_ a
a) = a -> Quaternion a
f a
a in a
a))
instance NFData a => NFData (Quaternion a) where
rnf :: Quaternion a -> ()
rnf (Quaternion a
a V3 a
b) = forall a. NFData a => a -> ()
rnf a
a seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf V3 a
b
instance Serial1 Quaternion where
serializeWith :: forall (m :: * -> *) a.
MonadPut m =>
(a -> m ()) -> Quaternion a -> m ()
serializeWith a -> m ()
f (Quaternion a
a V3 a
b) = a -> m ()
f a
a forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) (m :: * -> *) a.
(Serial1 f, MonadPut m) =>
(a -> m ()) -> f a -> m ()
serializeWith a -> m ()
f V3 a
b
deserializeWith :: forall (m :: * -> *) a. MonadGet m => m a -> m (Quaternion a)
deserializeWith m a
f = forall a. a -> V3 a -> Quaternion a
Quaternion forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
f forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) (m :: * -> *) a.
(Serial1 f, MonadGet m) =>
m a -> m (f a)
deserializeWith m a
f
instance Serial a => Serial (Quaternion a) where
serialize :: forall (m :: * -> *). MonadPut m => Quaternion 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 (Quaternion 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 (Quaternion a) where
put :: Quaternion 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 (Quaternion 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 (Quaternion a) where
put :: Putter (Quaternion 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 (Quaternion 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 Quaternion where
liftEq :: forall a b.
(a -> b -> Bool) -> Quaternion a -> Quaternion b -> Bool
liftEq a -> b -> Bool
f (Quaternion a
a V3 a
b) (Quaternion b
c V3 b
d) = a -> b -> Bool
f a
a b
c Bool -> Bool -> Bool
&& forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
f V3 a
b V3 b
d
instance Ord1 Quaternion where
liftCompare :: forall a b.
(a -> b -> Ordering) -> Quaternion a -> Quaternion b -> Ordering
liftCompare a -> b -> Ordering
f (Quaternion a
a V3 a
b) (Quaternion b
c V3 b
d) = a -> b -> Ordering
f a
a b
c forall a. Monoid a => a -> a -> a
`mappend` forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
f V3 a
b V3 b
d
instance Show1 Quaternion where
liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> Quaternion a -> ShowS
liftShowsPrec Int -> a -> ShowS
f [a] -> ShowS
g Int
d (Quaternion a
a V3 a
b) = forall a b.
(Int -> a -> ShowS)
-> (Int -> b -> ShowS) -> String -> Int -> a -> b -> ShowS
showsBinaryWith Int -> a -> ShowS
f (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
f [a] -> ShowS
g) String
"Quaternion" Int
d a
a V3 a
b
instance Read1 Quaternion where
liftReadsPrec :: forall a.
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Quaternion a)
liftReadsPrec Int -> ReadS a
f ReadS [a]
g = forall a. (String -> ReadS a) -> Int -> ReadS a
readsData forall a b. (a -> b) -> a -> b
$ forall a b t.
(Int -> ReadS a)
-> (Int -> ReadS b) -> String -> (a -> b -> t) -> String -> ReadS t
readsBinaryWith Int -> ReadS a
f (forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS a
f ReadS [a]
g) String
"Quaternion" forall a. a -> V3 a -> Quaternion a
Quaternion
instance Field1 (Quaternion a) (Quaternion a) a a where
_1 :: Lens (Quaternion a) (Quaternion a) a a
_1 a -> f a
f (Quaternion a
w V3 a
xyz) = a -> f a
f a
w forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \a
w' -> forall a. a -> V3 a -> Quaternion a
Quaternion a
w' V3 a
xyz
instance Field2 (Quaternion a) (Quaternion a) a a where
_2 :: Lens (Quaternion a) (Quaternion a) a a
_2 a -> f a
f (Quaternion a
w (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 -> V3 a -> Quaternion a
Quaternion a
w (forall a. a -> a -> a -> V3 a
V3 a
x' a
y a
z)
instance Field3 (Quaternion a) (Quaternion a) a a where
_3 :: Lens (Quaternion a) (Quaternion a) a a
_3 a -> f a
f (Quaternion a
w (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 -> V3 a -> Quaternion a
Quaternion a
w (forall a. a -> a -> a -> V3 a
V3 a
x a
y' a
z)
instance Field4 (Quaternion a) (Quaternion a) a a where
_4 :: Lens (Quaternion a) (Quaternion a) a a
_4 a -> f a
f (Quaternion a
w (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 -> V3 a -> Quaternion a
Quaternion a
w (forall a. a -> a -> a -> V3 a
V3 a
x a
y a
z')
instance Semigroup a => Semigroup (Quaternion a) where
<> :: Quaternion a -> Quaternion a -> Quaternion 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 (Quaternion a) where
mempty :: Quaternion 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
instance R1 Quaternion where
_x :: forall x. Lens' (Quaternion x) x
_x a -> f a
f (Quaternion a
w (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 -> V3 a -> Quaternion a
Quaternion a
w (forall a. a -> a -> a -> V3 a
V3 a
x' a
y a
z)
instance R2 Quaternion where
_y :: forall x. Lens' (Quaternion x) x
_y a -> f a
f (Quaternion a
w (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 -> V3 a -> Quaternion a
Quaternion a
w (forall a. a -> a -> a -> V3 a
V3 a
x a
y' a
z)
_xy :: forall a. Lens' (Quaternion a) (V2 a)
_xy V2 a -> f (V2 a)
f (Quaternion a
w (V3 a
x a
y a
z)) = V2 a -> f (V2 a)
f (forall a. a -> a -> V2 a
V2 a
x a
y) forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(V2 a
x' a
y') -> forall a. a -> V3 a -> Quaternion a
Quaternion a
w (forall a. a -> a -> a -> V3 a
V3 a
x' a
y' a
z)
instance R3 Quaternion where
_z :: forall x. Lens' (Quaternion x) x
_z a -> f a
f (Quaternion a
w (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 -> V3 a -> Quaternion a
Quaternion a
w (forall a. a -> a -> a -> V3 a
V3 a
x a
y a
z')
_xyz :: forall a. Lens' (Quaternion a) (V3 a)
_xyz V3 a -> f (V3 a)
f (Quaternion a
w V3 a
xyz) = forall a. a -> V3 a -> Quaternion a
Quaternion a
w forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> V3 a -> f (V3 a)
f V3 a
xyz
instance R4 Quaternion where
_w :: forall x. Lens' (Quaternion x) x
_w a -> f a
f (Quaternion a
w V3 a
xyz) = a -> f a
f a
w forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \a
w' -> forall a. a -> V3 a -> Quaternion a
Quaternion a
w' V3 a
xyz
_xyzw :: forall a. Lens' (Quaternion a) (V4 a)
_xyzw V4 a -> f (V4 a)
f (Quaternion a
w (V3 a
x a
y a
z)) = V4 a -> f (V4 a)
f (forall a. a -> a -> a -> a -> V4 a
V4 a
x a
y a
z a
w) forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(V4 a
x' a
y' a
z' a
w') -> forall a. a -> V3 a -> Quaternion a
Quaternion a
w' (forall a. a -> a -> a -> V3 a
V3 a
x' a
y' a
z')