packages feed

linear 0.2.0.2 → 0.4.1

raw patch · 7 files changed

+51/−20 lines, 7 filesdep +template-haskelldep ~basedep ~lens

Dependencies added: template-haskell

Dependency ranges changed: base, lens

Files

.travis.yml view
@@ -4,5 +4,3 @@   - mkdir -p ~/.cabal   - cp config ~/.cabal/config   - cabal update-notifications:-  irc: "irc.freenode.org#haskell-lens"
README.markdown view
@@ -1,8 +1,6 @@ linear ====== -[![Build Status](https://secure.travis-ci.org/ekmett/linear.png?branch=master)](http://travis-ci.org/ekmett/linear)- Contact Information ------------------- 
linear.cabal view
@@ -1,6 +1,6 @@ name:          linear category:      Math, Algebra-version:       0.2.0.2+version:       0.4.1 license:       BSD3 cabal-version: >= 1.8 license-file:  LICENSE@@ -13,7 +13,7 @@ synopsis:      Linear Algebra description:   Types and combinators for low-dimension-count linear algebra on free vector spaces build-type:    Simple-tested-with:   GHC == 7.4.1, GHC == 7.6.1+tested-with:   GHC == 7.4.2, GHC == 7.6.1 extra-source-files:   .travis.yml   .ghci@@ -29,11 +29,13 @@  library   build-depends:-    base == 4.*,-    distributive >= 0.2.2 && < 0.3,-    lens >= 2.9 && < 3.1+    base             >= 4.5 && < 5,+    distributive     >= 0.2.2 && < 0.3,+    lens             >= 3.6 && < 3.8,+    template-haskell >= 2.7 && < 2.9    exposed-modules:+    Linear     Linear.Conjugate     Linear.Epsilon     Linear.Matrix@@ -53,10 +55,10 @@   type:    exitcode-stdio-1.0   main-is: doctests.hs   build-depends:-    base == 4.*,+    base,     directory >= 1.0 && < 1.2,-    doctest >= 0.8 && < 0.10,-    filepath >= 1.3 && < 1.4+    doctest   >= 0.8 && < 0.10,+    filepath  >= 1.3 && < 1.4   ghc-options: -Wall -Werror -threaded   hs-source-dirs: tests 
+ src/Linear.hs view
@@ -0,0 +1,13 @@+-- |This module simply re-exports everything from the various modules+-- that make up the linear package.+module Linear (module X) where+import Linear.Conjugate as X+import Linear.Epsilon as X+import Linear.Matrix as X+import Linear.Metric as X+import Linear.Plucker as X+import Linear.Quaternion as X+import Linear.V2 as X+import Linear.V3 as X+import Linear.V4 as X+import Linear.Vector as X
src/Linear/Matrix.hs view
@@ -50,12 +50,15 @@ type M44 a = V4 (V4 a) type M43 a = V4 (V3 a) --- | Build a rotation matrix from a 'Quaternion'.+-- | Build a rotation matrix from a unit 'Quaternion'. fromQuaternion :: Num a => Quaternion a -> M33 a-fromQuaternion (Quaternion a (V3 b c d)) =-  V3 (V3 (a*a+b*b-c*c-d*d) (2*b*c-2*a*d) (2*b*d+2*a*c))-     (V3 (2*b*c+2*a*d) (a*a-b*b+c*c-d*d) (2*c*d-2*a*b))-     (V3 (2*b*d-2*a*c) (2*c*d+2*a*b) (a*a-b*b-c*c+d*d))+fromQuaternion (Quaternion w (V3 x y z)) =+  V3 (V3 (1-2*(y2+z2)) (2*(x*y-z*w)) (2*(x*z+y*w)))+     (V3 (2*(x*y+z*w)) (1-2*(x2+z2)) (2*(y*z-x*w)))+     (V3 (2*(x*z-y*w)) (2*(y*z+x*w)) (1-2*(x2+y2)))+  where x2 = x * x+        y2 = y * y+        z2 = z * z  mkTransformationMat :: Num a => M33 a -> V3 a -> M44 a mkTransformationMat (V3 r1 r2 r3) (V3 tx ty tz) =
src/Linear/Quaternion.hs view
@@ -129,7 +129,7 @@  instance Complicated Quaternion where   _e f (Quaternion a v) = (\a' -> Quaternion a' v) <$> f a-  _i f (Quaternion a v) = Quaternion a <$> traverseOf _x f v+  _i f (Quaternion a v) = Quaternion a <$> _x f v   --_i f (Quaternion a (V3 b c d)) = (\b' -> Quaternion a (V3 b' c d)) <$> f b  class Complicated t => Hamiltonian t where@@ -138,8 +138,8 @@   _ijk :: Functor f => (V3 a -> f (V3 a)) -> t a -> f (t a)  instance Hamiltonian Quaternion where-  _j f (Quaternion a v) = Quaternion a <$> traverseOf _y f v-  _k f (Quaternion a v) = Quaternion a <$> traverseOf _z f v+  _j f (Quaternion a v) = Quaternion a <$> _y f v+  _k f (Quaternion a v) = Quaternion a <$> _z f v   -- _j f (Quaternion a (V3 b c d)) = (\c' -> Quaternion a (V3 b c' d)) <$> f c   -- _k f (Quaternion a (V3 b c d)) = Quaternion a . V3 b c <$> f d 
src/Linear/Vector.hs view
@@ -17,9 +17,12 @@   , (*^)   , (^/)   , lerp+  , basis+  , basisFor   ) where  import Control.Applicative+import Control.Lens  infixl 6 ^+^, ^-^ infixl 7 ^*, *^, ^/@@ -58,3 +61,17 @@ lerp :: (Applicative f, Num a) => a -> f a -> f a -> f a lerp alpha u v = alpha *^ u ^+^ (1 - alpha) *^ v {-# INLINE lerp #-}++-- | Produce a default basis for a vector space. If the dimensionality+-- of the vector space is not statically known, see 'basisFor'.+basis :: (Applicative t, Traversable t, Num a) => [t a]+basis = [ set (element k) 1 zero | k <- [0..lengthOf folded zero - 1]]+  where zero = pure 0++-- | Produce a default basis for a vector space from which the+-- argument is drawn.+basisFor :: (Traversable t, Enum a, Num a) => t a -> [t a]+basisFor v = map aux [0..n-1]+  where z = 0 <$ v+        n = lengthOf folded z+        aux i = z & element i .~ 1