{-# LANGUAGE UndecidableSuperClasses #-}
module Goal.Geometry.Vector
(
(.>)
, (/>)
, convexCombination
, Primal (Dual)
, type (#*)
, (<.>)
, dotMap
) where
import Goal.Core
import Goal.Geometry.Manifold
import qualified Goal.Core.Vector.Storable as S
(.>) :: Double -> c # x -> c # x
{-# INLINE (.>) #-}
.> :: Double -> (c # x) -> c # x
(.>) Double
a (Point Vector (Dimension x) Double
xs) = Vector (Dimension x) Double -> c # x
forall c x. Vector (Dimension x) Double -> Point c x
Point (Vector (Dimension x) Double -> c # x)
-> Vector (Dimension x) Double -> c # x
forall a b. (a -> b) -> a -> b
$ Double
-> Vector (Dimension x) Double -> Vector (Dimension x) Double
forall x (n :: Nat). Numeric x => x -> Vector n x -> Vector n x
S.scale Double
a Vector (Dimension x) Double
xs
infix 7 .>
(/>) :: Double -> c # x -> c # x
{-# INLINE (/>) #-}
/> :: Double -> (c # x) -> c # x
(/>) Double
a (Point Vector (Dimension x) Double
xs) = Vector (Dimension x) Double -> c # x
forall c x. Vector (Dimension x) Double -> Point c x
Point (Vector (Dimension x) Double -> c # x)
-> Vector (Dimension x) Double -> c # x
forall a b. (a -> b) -> a -> b
$ Double
-> Vector (Dimension x) Double -> Vector (Dimension x) Double
forall x (n :: Nat). Numeric x => x -> Vector n x -> Vector n x
S.scale (Double -> Double
forall a. Fractional a => a -> a
recip Double
a) Vector (Dimension x) Double
xs
infix 7 />
convexCombination :: Manifold x => Double -> c # x -> c # x -> c # x
convexCombination :: Double -> (c # x) -> (c # x) -> c # x
convexCombination Double
x c # x
p1 c # x
p2 = Double
x Double -> (c # x) -> c # x
forall c x. Double -> (c # x) -> c # x
.> c # x
p1 (c # x) -> (c # x) -> c # x
forall a. Num a => a -> a -> a
+ (Double
1Double -> Double -> Double
forall a. Num a => a -> a -> a
-Double
x) Double -> (c # x) -> c # x
forall c x. Double -> (c # x) -> c # x
.> c # x
p2
class (Dual (Dual c) ~ c, Primal (Dual c)) => Primal c where
type Dual c :: Type
type (c #* x) = Point (Dual c) x
infix 3 #*
(<.>) :: c # x -> c #* x -> Double
{-# INLINE (<.>) #-}
<.> :: (c # x) -> (c #* x) -> Double
(<.>) c # x
p c #* x
q = Vector (Dimension x) Double
-> Vector (Dimension x) Double -> Double
forall x (n :: Nat). Numeric x => Vector n x -> Vector n x -> x
S.dotProduct ((c # x) -> Vector (Dimension x) Double
forall c x. Point c x -> Vector (Dimension x) Double
coordinates c # x
p) ((c #* x) -> Vector (Dimension x) Double
forall c x. Point c x -> Vector (Dimension x) Double
coordinates c #* x
q)
infix 7 <.>
dotMap :: Manifold x => c # x -> [c #* x] -> [Double]
{-# INLINE dotMap #-}
dotMap :: (c # x) -> [c #* x] -> [Double]
dotMap c # x
p [c #* x]
qs = Vector (Dimension x) Double
-> [Vector (Dimension x) Double] -> [Double]
forall (n :: Nat) x.
(KnownNat n, Numeric x) =>
Vector n x -> [Vector n x] -> [x]
S.dotMap ((c # x) -> Vector (Dimension x) Double
forall c x. Point c x -> Vector (Dimension x) Double
coordinates c # x
p) ((c #* x) -> Vector (Dimension x) Double
forall c x. Point c x -> Vector (Dimension x) Double
coordinates ((c #* x) -> Vector (Dimension x) Double)
-> [c #* x] -> [Vector (Dimension x) Double]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> [c #* x]
qs)
instance Primal Cartesian where
type Dual Cartesian = Cartesian