vector-space 0.8.6 → 0.8.7
raw patch · 4 files changed
+25/−8 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.AffineSpace: affineCombo :: (AffineSpace p, v ~ Diff p, VectorSpace v) => p -> [(p, Scalar v)] -> p
+ Data.VectorSpace: linearCombo :: VectorSpace v => [(v, Scalar v)] -> v
Files
- src/Data/AffineSpace.hs +19/−1
- src/Data/Basis.hs +0/−5
- src/Data/VectorSpace.hs +5/−1
- vector-space.cabal +1/−1
src/Data/AffineSpace.hs view
@@ -13,12 +13,13 @@ module Data.AffineSpace (- AffineSpace(..), (.-^), distanceSq, distance, alerp+ AffineSpace(..), (.-^), distanceSq, distance, alerp, affineCombo ) where import Control.Applicative (liftA2) import Data.Ratio import Foreign.C.Types (CFloat, CDouble)+import Control.Arrow(first) import Data.VectorSpace @@ -66,6 +67,23 @@ p -> p -> Scalar (Diff p) -> p alerp p p' s = p .+^ (s *^ (p' .-. p)) +-- | Compute an affine combination (weighted average) of points.+-- The first element is used as origin and is weighted+-- such that all coefficients sum to 1. For example,+--+-- > affineCombo a [(0.3,b), (0.2,c)]+--+-- is equal to+--+-- > a .+^ (0.3 *^ (b .-. a) ^+^ 0.2 *^ (c .-. a))+--+-- and if @a@, @b@, and @c@ were in a vector space would also be equal to+--+-- > 0.5 *^ a ^+^ 0.3 *^ b ^+^ 0.2 *^ c+--+-- See also 'linearCombo' (on vector spaces).+affineCombo :: (AffineSpace p, v ~ Diff p, VectorSpace v) => p -> [(p,Scalar v)] -> p+affineCombo z l = z .+^ linearCombo (map (first (.-. z)) l) #define ScalarTypeCon(con,t) \ instance con => AffineSpace (t) where \
src/Data/Basis.hs view
@@ -41,16 +41,11 @@ -- Defining property: recompose . decompose == id --- | Linear combination-linearCombo :: VectorSpace v => [(v,Scalar v)] -> v-linearCombo ps = sumV [s *^ v | (v,s) <- ps]- -- Turn a basis decomposition back into a vector. recompose :: HasBasis v => [(Basis v, Scalar v)] -> v recompose = linearCombo . fmap (first basisValue) -- recompose ps = linearCombo (first basisValue <$> ps)- -- I don't know how to define --
src/Data/VectorSpace.hs view
@@ -28,7 +28,7 @@ ( module Data.AdditiveGroup , VectorSpace(..), (^/), (^*) , InnerSpace(..)- , lerp, magnitudeSq, magnitude, normalized, project+ , lerp, linearCombo, magnitudeSq, magnitude, normalized, project ) where import Control.Applicative (liftA2)@@ -70,6 +70,10 @@ -- lerp :: (VectorSpace v, s ~ Scalar v, Num s) => v -> v -> s -> v lerp :: VectorSpace v => v -> v -> Scalar v -> v lerp a b t = a ^+^ t *^ (b ^-^ a)++-- | Linear combination of vectors+linearCombo :: VectorSpace v => [(v,Scalar v)] -> v+linearCombo ps = sumV [v ^* s | (v,s) <- ps] -- | Square of the length of a vector. Sometimes useful for efficiency. -- See also 'magnitude'.
vector-space.cabal view
@@ -1,5 +1,5 @@ Name: vector-space-Version: 0.8.6+Version: 0.8.7 Cabal-Version: >= 1.6 Synopsis: Vector & affine spaces, linear maps, and derivatives Category: math