packages feed

vect 0.4.5 → 0.4.5.2

raw patch · 11 files changed

+580/−13 lines, 11 filesdep ~base

Dependency ranges changed: base

Files

Data/Vect/Double/Base.hs view
@@ -137,7 +137,7 @@   fromNormalRadius :: Flt -> u -> v   fromNormalRadius t n = t *& fromNormal n  --- | Projects the first vector onto the direction of the second (unit) vector+-- | Projects the first vector down to the hyperplane orthogonal to the second (unit) vector project' :: (Vector v, UnitVector v u, DotProd v) => v -> u -> v project' what dir = projectUnsafe what (fromNormal dir) @@ -603,6 +603,9 @@       normsqr r1 +        normsqr r2      +instance Pointwise Mat2 where+  pointwise (Mat2 x1 y1) (Mat2 x2 y2) = Mat2 (x1 &! x2) (y1 &! y2)+        --------------------------------------------------------------------------------      -- Vec3 instances @@ -785,6 +788,9 @@       normsqr r1 +        normsqr r2 +        normsqr r3 ++instance Pointwise Mat3 where+  pointwise (Mat3 x1 y1 z1) (Mat3 x2 y2 z2) = Mat3 (x1 &! x2) (y1 &! y2) (z1 &! z2)      -------------------------------------------------------------------------------- -- Vec4 instances@@ -953,6 +959,9 @@       normsqr r2 +        normsqr r3 +        normsqr r4  +    +instance Pointwise Mat4 where+  pointwise (Mat4 x1 y1 z1 w1) (Mat4 x2 y2 z2 w2) = Mat4 (x1 &! x2) (y1 &! y2) (z1 &! z2) (w1 &! w2)      -------------------------------------------------------------------------------- -- Extend instances
+ Data/Vect/Double/Instances.hs view
@@ -0,0 +1,167 @@+{-# OPTIONS_GHC -DFlt=Double -DVECT_Double #-}++-- | 'Eq', 'Num' and 'Fractional' instances for vectors and matrices.+-- These make writing code much more convenient, but also much more +-- dangerous; thus you have to import this module explicitely.+--+-- In the case of Vector instances, all operations are pointwise+-- (including multiplication and division), and scalars are implicitly+-- converted to vectors so that all components of the resulting vectors+-- are the equal to the given scalar. This gives a set of consistent+-- instances.+--+-- In the case of Matrices, multiplication is usual matrix multiplication,+-- division is not implemented, and scalars are converted to diagonal +-- matrices.+--+-- 'abs' and 'signum' are implemented to be 'normalize' and 'norm'+-- (in the case of matrices, Frobenius norm).++module Data.Vect.Flt.Instances where++--------------------------------------------------------------------------------  +  +import Data.Vect.Flt.Base ++--------------------------------------------------------------------------------  +-- * Vectors++instance Eq Vec2 where+  Vec2 x y == Vec2 a b = (x==a && y==b)++instance Num Vec2 where+  (+) = (&+)+  (-) = (&-)+  negate = neg+  (*) = pointwise +  fromInteger a = let x = fromInteger a in Vec2 x x+  abs = normalize+  signum v = let x = norm v in Vec2 x x+  +instance Fractional Vec2 where+  (Vec2 x y) / (Vec2 a b) = Vec2 (x/a) (y/b) +  fromRational a = let x = fromRational a in Vec2 x x ++--------------------------------------------------------------------------------  ++instance Eq Vec3 where+  Vec3 x y z == Vec3 a b c = (x==a && y==b && z==c)++instance Num Vec3 where+  (+) = (&+)+  (-) = (&-)+  negate = neg+  (*) = pointwise +  fromInteger a = let x = fromInteger a in Vec3 x x x+  abs = normalize+  signum v = let x = norm v in Vec3 x x x+  +instance Fractional Vec3 where+  (Vec3 x y z) / (Vec3 a b c) = Vec3 (x/a) (y/b) (z/c)+  fromRational a = let x = fromRational a in Vec3 x x x  +  +--------------------------------------------------------------------------------  ++instance Eq Vec4 where+  Vec4 x y z w == Vec4 a b c d = (x==a && y==b && z==c && w==d)++instance Num Vec4 where+  (+) = (&+)+  (-) = (&-)+  negate = neg+  (*) = pointwise +  fromInteger a = let x = fromInteger a in Vec4 x x x x+  abs = normalize+  signum v = let x = norm v in Vec4 x x x x+  +instance Fractional Vec4 where+  (Vec4 x y z w) / (Vec4 a b c d) = Vec4 (x/a) (y/b) (z/c) (w/d)+  fromRational a = let x = fromRational a in Vec4 x x x x  ++--------------------------------------------------------------------------------  +-- * Matrices  ++instance Eq Mat2 where+  Mat2 x y == Mat2 a b = (x==a && y==b)++instance Num Mat2 where+  (+) = (&+)+  (-) = (&-)+  negate = neg+  +  (*) = (.*.)+  fromInteger = diag . fromInteger+  abs m = m &* (1.0 / frobeniusNorm m)+  signum = diag . (\x -> Vec2 x x) . frobeniusNorm+  +  -- (*) = pointwise +  -- fromInteger a = let x = fromInteger a in Mat2 x x+  -- abs m = m &* (1.0 / frobeniusNorm m)+  -- signum m = Mat2 v v where+  --   x = frobeniusNorm m +  --   v = Vec2 x x+    +instance Fractional Mat2 where+  -- (Mat2 x y) / (Mat2 a b) = Mat2 (x/a) (y/b) +  -- fromRational a = let x = fromRational a in Mat2 x x  +  (/) = error "Mat2/division: not implemented"+  fromRational = diag . fromRational+  +--------------------------------------------------------------------------------  +    +instance Eq Mat3 where+  Mat3 x y z == Mat3 a b c = (x==a && y==b && z==c)++instance Num Mat3 where+  (+) = (&+)+  (-) = (&-)+  negate = neg++  (*) = (.*.)+  fromInteger = diag . fromInteger+  abs m = m &* (1.0 / frobeniusNorm m)+  signum = diag . (\x -> Vec3 x x x) . frobeniusNorm++  -- (*) = pointwise +  -- fromInteger a = let x = fromInteger a in Mat3 x x x+  -- abs m = m &* (1.0 / frobeniusNorm m)+  -- signum m = Mat3 v v v where+  --   x = frobeniusNorm m +  --   v = Vec3 x x x+    +instance Fractional Mat3 where+  -- (Mat3 x y z) / (Mat3 a b c) = Mat3 (x/a) (y/b) (z/c)+  -- fromRational a = let x = fromRational a in Mat3 x x x  +  (/) = error "Mat3/division: not implemented"+  fromRational = diag . fromRational+    +--------------------------------------------------------------------------------  +  +instance Eq Mat4 where+  Mat4 x y z w == Mat4 a b c d = (x==a && y==b && z==c && w==d)++instance Num Mat4 where+  (+) = (&+)+  (-) = (&-)+  negate = neg++  (*) = (.*.)+  fromInteger = diag . fromInteger+  abs m = m &* (1.0 / frobeniusNorm m)+  signum = diag . (\x -> Vec4 x x x x) . frobeniusNorm++  -- (*) = pointwise +  -- fromInteger a = let x = fromInteger a in Mat4 x x x x+  -- abs m = m &* (1.0 / frobeniusNorm m)+  -- signum m = Mat4 v v v v where+  --   x = frobeniusNorm m +  --   v = Vec4 x x x x+    +instance Fractional Mat4 where+  -- (Mat4 x y z w) / (Mat4 a b c d) = Mat4 (x/a) (y/b) (z/c) (w/d)+  -- fromRational a = let x = fromRational a in Mat4 x x x x+  (/) = error "Mat4/division: not implemented"+  fromRational = diag . fromRational++--------------------------------------------------------------------------------  +    
Data/Vect/Double/OpenGL.hs view
@@ -144,7 +144,7 @@   (Vec4 (2*n/(r-l)) 0 0 0)   (Vec4 0 (2*n/(t-b)) 0 0)   (Vec4 ((r+l)/(r-l)) ((t+b)/(t-b)) (-(f+n)/(f-n)) (-1))-  (Vec4 0 0 (-2*f*n*(f-n)) 0)+  (Vec4 0 0 (-2*f*n/(f-n)) 0)    -- | The same as "frustumMatrix", but with a different parametrization. frustumMatrix2 {- ' CPP is sensitive to primes -}@@ -152,6 +152,18 @@   -> Vec3     -- ^ (right,bottom,far)   -> Mat4  frustumMatrix2 (Vec3 l t n) (Vec3 r b f) = frustumMatrix (l,r) (b,t) (n,f)++-- | Inverse of "frustumMatrix".+inverseFrustumMatrix+  :: (Flt,Flt)   -- ^ (left,right)+  -> (Flt,Flt)   -- ^ (bottom,top)+  -> (Flt,Flt)   -- ^ (near,far)+  -> Mat4 +inverseFrustumMatrix (l,r) (b,t) (n,f) = Mat4+  (Vec4 (0.5*(r-l)/n) 0 0 0)+  (Vec4 0 (0.5*(t-b)/n) 0 0)+  (Vec4 0 0 0 (0.5*(n-f)/(f*n)))+  (Vec4 (0.5*(r+l)/n) (0.5*(t+b)/n) (-1) (0.5*(f+n)/(f*n)))  -------------------------------------------------------------------------------- -- Vertex instances
Data/Vect/Float/Base.hs view
@@ -137,7 +137,7 @@   fromNormalRadius :: Flt -> u -> v   fromNormalRadius t n = t *& fromNormal n  --- | Projects the first vector onto the direction of the second (unit) vector+-- | Projects the first vector down to the hyperplane orthogonal to the second (unit) vector project' :: (Vector v, UnitVector v u, DotProd v) => v -> u -> v project' what dir = projectUnsafe what (fromNormal dir) @@ -603,6 +603,9 @@       normsqr r1 +        normsqr r2      +instance Pointwise Mat2 where+  pointwise (Mat2 x1 y1) (Mat2 x2 y2) = Mat2 (x1 &! x2) (y1 &! y2)+        --------------------------------------------------------------------------------      -- Vec3 instances @@ -785,6 +788,9 @@       normsqr r1 +        normsqr r2 +        normsqr r3 ++instance Pointwise Mat3 where+  pointwise (Mat3 x1 y1 z1) (Mat3 x2 y2 z2) = Mat3 (x1 &! x2) (y1 &! y2) (z1 &! z2)      -------------------------------------------------------------------------------- -- Vec4 instances@@ -953,6 +959,9 @@       normsqr r2 +        normsqr r3 +        normsqr r4  +    +instance Pointwise Mat4 where+  pointwise (Mat4 x1 y1 z1 w1) (Mat4 x2 y2 z2 w2) = Mat4 (x1 &! x2) (y1 &! y2) (z1 &! z2) (w1 &! w2)      -------------------------------------------------------------------------------- -- Extend instances
+ Data/Vect/Float/Instances.hs view
@@ -0,0 +1,167 @@+{-# OPTIONS_GHC -DFlt=Float -DVECT_Float #-}++-- | 'Eq', 'Num' and 'Fractional' instances for vectors and matrices.+-- These make writing code much more convenient, but also much more +-- dangerous; thus you have to import this module explicitely.+--+-- In the case of Vector instances, all operations are pointwise+-- (including multiplication and division), and scalars are implicitly+-- converted to vectors so that all components of the resulting vectors+-- are the equal to the given scalar. This gives a set of consistent+-- instances.+--+-- In the case of Matrices, multiplication is usual matrix multiplication,+-- division is not implemented, and scalars are converted to diagonal +-- matrices.+--+-- 'abs' and 'signum' are implemented to be 'normalize' and 'norm'+-- (in the case of matrices, Frobenius norm).++module Data.Vect.Flt.Instances where++--------------------------------------------------------------------------------  +  +import Data.Vect.Flt.Base ++--------------------------------------------------------------------------------  +-- * Vectors++instance Eq Vec2 where+  Vec2 x y == Vec2 a b = (x==a && y==b)++instance Num Vec2 where+  (+) = (&+)+  (-) = (&-)+  negate = neg+  (*) = pointwise +  fromInteger a = let x = fromInteger a in Vec2 x x+  abs = normalize+  signum v = let x = norm v in Vec2 x x+  +instance Fractional Vec2 where+  (Vec2 x y) / (Vec2 a b) = Vec2 (x/a) (y/b) +  fromRational a = let x = fromRational a in Vec2 x x ++--------------------------------------------------------------------------------  ++instance Eq Vec3 where+  Vec3 x y z == Vec3 a b c = (x==a && y==b && z==c)++instance Num Vec3 where+  (+) = (&+)+  (-) = (&-)+  negate = neg+  (*) = pointwise +  fromInteger a = let x = fromInteger a in Vec3 x x x+  abs = normalize+  signum v = let x = norm v in Vec3 x x x+  +instance Fractional Vec3 where+  (Vec3 x y z) / (Vec3 a b c) = Vec3 (x/a) (y/b) (z/c)+  fromRational a = let x = fromRational a in Vec3 x x x  +  +--------------------------------------------------------------------------------  ++instance Eq Vec4 where+  Vec4 x y z w == Vec4 a b c d = (x==a && y==b && z==c && w==d)++instance Num Vec4 where+  (+) = (&+)+  (-) = (&-)+  negate = neg+  (*) = pointwise +  fromInteger a = let x = fromInteger a in Vec4 x x x x+  abs = normalize+  signum v = let x = norm v in Vec4 x x x x+  +instance Fractional Vec4 where+  (Vec4 x y z w) / (Vec4 a b c d) = Vec4 (x/a) (y/b) (z/c) (w/d)+  fromRational a = let x = fromRational a in Vec4 x x x x  ++--------------------------------------------------------------------------------  +-- * Matrices  ++instance Eq Mat2 where+  Mat2 x y == Mat2 a b = (x==a && y==b)++instance Num Mat2 where+  (+) = (&+)+  (-) = (&-)+  negate = neg+  +  (*) = (.*.)+  fromInteger = diag . fromInteger+  abs m = m &* (1.0 / frobeniusNorm m)+  signum = diag . (\x -> Vec2 x x) . frobeniusNorm+  +  -- (*) = pointwise +  -- fromInteger a = let x = fromInteger a in Mat2 x x+  -- abs m = m &* (1.0 / frobeniusNorm m)+  -- signum m = Mat2 v v where+  --   x = frobeniusNorm m +  --   v = Vec2 x x+    +instance Fractional Mat2 where+  -- (Mat2 x y) / (Mat2 a b) = Mat2 (x/a) (y/b) +  -- fromRational a = let x = fromRational a in Mat2 x x  +  (/) = error "Mat2/division: not implemented"+  fromRational = diag . fromRational+  +--------------------------------------------------------------------------------  +    +instance Eq Mat3 where+  Mat3 x y z == Mat3 a b c = (x==a && y==b && z==c)++instance Num Mat3 where+  (+) = (&+)+  (-) = (&-)+  negate = neg++  (*) = (.*.)+  fromInteger = diag . fromInteger+  abs m = m &* (1.0 / frobeniusNorm m)+  signum = diag . (\x -> Vec3 x x x) . frobeniusNorm++  -- (*) = pointwise +  -- fromInteger a = let x = fromInteger a in Mat3 x x x+  -- abs m = m &* (1.0 / frobeniusNorm m)+  -- signum m = Mat3 v v v where+  --   x = frobeniusNorm m +  --   v = Vec3 x x x+    +instance Fractional Mat3 where+  -- (Mat3 x y z) / (Mat3 a b c) = Mat3 (x/a) (y/b) (z/c)+  -- fromRational a = let x = fromRational a in Mat3 x x x  +  (/) = error "Mat3/division: not implemented"+  fromRational = diag . fromRational+    +--------------------------------------------------------------------------------  +  +instance Eq Mat4 where+  Mat4 x y z w == Mat4 a b c d = (x==a && y==b && z==c && w==d)++instance Num Mat4 where+  (+) = (&+)+  (-) = (&-)+  negate = neg++  (*) = (.*.)+  fromInteger = diag . fromInteger+  abs m = m &* (1.0 / frobeniusNorm m)+  signum = diag . (\x -> Vec4 x x x x) . frobeniusNorm++  -- (*) = pointwise +  -- fromInteger a = let x = fromInteger a in Mat4 x x x x+  -- abs m = m &* (1.0 / frobeniusNorm m)+  -- signum m = Mat4 v v v v where+  --   x = frobeniusNorm m +  --   v = Vec4 x x x x+    +instance Fractional Mat4 where+  -- (Mat4 x y z w) / (Mat4 a b c d) = Mat4 (x/a) (y/b) (z/c) (w/d)+  -- fromRational a = let x = fromRational a in Mat4 x x x x+  (/) = error "Mat4/division: not implemented"+  fromRational = diag . fromRational++--------------------------------------------------------------------------------  +    
Data/Vect/Float/OpenGL.hs view
@@ -144,7 +144,7 @@   (Vec4 (2*n/(r-l)) 0 0 0)   (Vec4 0 (2*n/(t-b)) 0 0)   (Vec4 ((r+l)/(r-l)) ((t+b)/(t-b)) (-(f+n)/(f-n)) (-1))-  (Vec4 0 0 (-2*f*n*(f-n)) 0)+  (Vec4 0 0 (-2*f*n/(f-n)) 0)    -- | The same as "frustumMatrix", but with a different parametrization. frustumMatrix2 {- ' CPP is sensitive to primes -}@@ -152,6 +152,18 @@   -> Vec3     -- ^ (right,bottom,far)   -> Mat4  frustumMatrix2 (Vec3 l t n) (Vec3 r b f) = frustumMatrix (l,r) (b,t) (n,f)++-- | Inverse of "frustumMatrix".+inverseFrustumMatrix+  :: (Flt,Flt)   -- ^ (left,right)+  -> (Flt,Flt)   -- ^ (bottom,top)+  -> (Flt,Flt)   -- ^ (near,far)+  -> Mat4 +inverseFrustumMatrix (l,r) (b,t) (n,f) = Mat4+  (Vec4 (0.5*(r-l)/n) 0 0 0)+  (Vec4 0 (0.5*(t-b)/n) 0 0)+  (Vec4 0 0 0 (0.5*(n-f)/(f*n)))+  (Vec4 (0.5*(r+l)/n) (0.5*(t+b)/n) (-1) (0.5*(f+n)/(f*n)))  -------------------------------------------------------------------------------- -- Vertex instances
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2008-2009, Balazs Komuves+Copyright (c) 2008-2010, Balazs Komuves All rights reserved.  Redistribution and use in source and binary forms, with or without
src/flt/Base.hs view
@@ -136,7 +136,7 @@   fromNormalRadius :: Flt -> u -> v   fromNormalRadius t n = t *& fromNormal n  --- | Projects the first vector onto the direction of the second (unit) vector+-- | Projects the first vector down to the hyperplane orthogonal to the second (unit) vector project' :: (Vector v, UnitVector v u, DotProd v) => v -> u -> v project' what dir = projectUnsafe what (fromNormal dir) @@ -602,6 +602,9 @@       normsqr r1 +        normsqr r2      +instance Pointwise Mat2 where+  pointwise (Mat2 x1 y1) (Mat2 x2 y2) = Mat2 (x1 &! x2) (y1 &! y2)+        --------------------------------------------------------------------------------      -- Vec3 instances @@ -784,6 +787,9 @@       normsqr r1 +        normsqr r2 +        normsqr r3 ++instance Pointwise Mat3 where+  pointwise (Mat3 x1 y1 z1) (Mat3 x2 y2 z2) = Mat3 (x1 &! x2) (y1 &! y2) (z1 &! z2)      -------------------------------------------------------------------------------- -- Vec4 instances@@ -952,6 +958,9 @@       normsqr r2 +        normsqr r3 +        normsqr r4  +    +instance Pointwise Mat4 where+  pointwise (Mat4 x1 y1 z1 w1) (Mat4 x2 y2 z2 w2) = Mat4 (x1 &! x2) (y1 &! y2) (z1 &! z2) (w1 &! w2)      -------------------------------------------------------------------------------- -- Extend instances
+ src/flt/Instances.hs view
@@ -0,0 +1,166 @@++-- | 'Eq', 'Num' and 'Fractional' instances for vectors and matrices.+-- These make writing code much more convenient, but also much more +-- dangerous; thus you have to import this module explicitely.+--+-- In the case of Vector instances, all operations are pointwise+-- (including multiplication and division), and scalars are implicitly+-- converted to vectors so that all components of the resulting vectors+-- are the equal to the given scalar. This gives a set of consistent+-- instances.+--+-- In the case of Matrices, multiplication is usual matrix multiplication,+-- division is not implemented, and scalars are converted to diagonal +-- matrices.+--+-- 'abs' and 'signum' are implemented to be 'normalize' and 'norm'+-- (in the case of matrices, Frobenius norm).++module Data.Vect.Flt.Instances where++--------------------------------------------------------------------------------  +  +import Data.Vect.Flt.Base ++--------------------------------------------------------------------------------  +-- * Vectors++instance Eq Vec2 where+  Vec2 x y == Vec2 a b = (x==a && y==b)++instance Num Vec2 where+  (+) = (&+)+  (-) = (&-)+  negate = neg+  (*) = pointwise +  fromInteger a = let x = fromInteger a in Vec2 x x+  abs = normalize+  signum v = let x = norm v in Vec2 x x+  +instance Fractional Vec2 where+  (Vec2 x y) / (Vec2 a b) = Vec2 (x/a) (y/b) +  fromRational a = let x = fromRational a in Vec2 x x ++--------------------------------------------------------------------------------  ++instance Eq Vec3 where+  Vec3 x y z == Vec3 a b c = (x==a && y==b && z==c)++instance Num Vec3 where+  (+) = (&+)+  (-) = (&-)+  negate = neg+  (*) = pointwise +  fromInteger a = let x = fromInteger a in Vec3 x x x+  abs = normalize+  signum v = let x = norm v in Vec3 x x x+  +instance Fractional Vec3 where+  (Vec3 x y z) / (Vec3 a b c) = Vec3 (x/a) (y/b) (z/c)+  fromRational a = let x = fromRational a in Vec3 x x x  +  +--------------------------------------------------------------------------------  ++instance Eq Vec4 where+  Vec4 x y z w == Vec4 a b c d = (x==a && y==b && z==c && w==d)++instance Num Vec4 where+  (+) = (&+)+  (-) = (&-)+  negate = neg+  (*) = pointwise +  fromInteger a = let x = fromInteger a in Vec4 x x x x+  abs = normalize+  signum v = let x = norm v in Vec4 x x x x+  +instance Fractional Vec4 where+  (Vec4 x y z w) / (Vec4 a b c d) = Vec4 (x/a) (y/b) (z/c) (w/d)+  fromRational a = let x = fromRational a in Vec4 x x x x  ++--------------------------------------------------------------------------------  +-- * Matrices  ++instance Eq Mat2 where+  Mat2 x y == Mat2 a b = (x==a && y==b)++instance Num Mat2 where+  (+) = (&+)+  (-) = (&-)+  negate = neg+  +  (*) = (.*.)+  fromInteger = diag . fromInteger+  abs m = m &* (1.0 / frobeniusNorm m)+  signum = diag . (\x -> Vec2 x x) . frobeniusNorm+  +  -- (*) = pointwise +  -- fromInteger a = let x = fromInteger a in Mat2 x x+  -- abs m = m &* (1.0 / frobeniusNorm m)+  -- signum m = Mat2 v v where+  --   x = frobeniusNorm m +  --   v = Vec2 x x+    +instance Fractional Mat2 where+  -- (Mat2 x y) / (Mat2 a b) = Mat2 (x/a) (y/b) +  -- fromRational a = let x = fromRational a in Mat2 x x  +  (/) = error "Mat2/division: not implemented"+  fromRational = diag . fromRational+  +--------------------------------------------------------------------------------  +    +instance Eq Mat3 where+  Mat3 x y z == Mat3 a b c = (x==a && y==b && z==c)++instance Num Mat3 where+  (+) = (&+)+  (-) = (&-)+  negate = neg++  (*) = (.*.)+  fromInteger = diag . fromInteger+  abs m = m &* (1.0 / frobeniusNorm m)+  signum = diag . (\x -> Vec3 x x x) . frobeniusNorm++  -- (*) = pointwise +  -- fromInteger a = let x = fromInteger a in Mat3 x x x+  -- abs m = m &* (1.0 / frobeniusNorm m)+  -- signum m = Mat3 v v v where+  --   x = frobeniusNorm m +  --   v = Vec3 x x x+    +instance Fractional Mat3 where+  -- (Mat3 x y z) / (Mat3 a b c) = Mat3 (x/a) (y/b) (z/c)+  -- fromRational a = let x = fromRational a in Mat3 x x x  +  (/) = error "Mat3/division: not implemented"+  fromRational = diag . fromRational+    +--------------------------------------------------------------------------------  +  +instance Eq Mat4 where+  Mat4 x y z w == Mat4 a b c d = (x==a && y==b && z==c && w==d)++instance Num Mat4 where+  (+) = (&+)+  (-) = (&-)+  negate = neg++  (*) = (.*.)+  fromInteger = diag . fromInteger+  abs m = m &* (1.0 / frobeniusNorm m)+  signum = diag . (\x -> Vec4 x x x x) . frobeniusNorm++  -- (*) = pointwise +  -- fromInteger a = let x = fromInteger a in Mat4 x x x x+  -- abs m = m &* (1.0 / frobeniusNorm m)+  -- signum m = Mat4 v v v v where+  --   x = frobeniusNorm m +  --   v = Vec4 x x x x+    +instance Fractional Mat4 where+  -- (Mat4 x y z w) / (Mat4 a b c d) = Mat4 (x/a) (y/b) (z/c) (w/d)+  -- fromRational a = let x = fromRational a in Mat4 x x x x+  (/) = error "Mat4/division: not implemented"+  fromRational = diag . fromRational++--------------------------------------------------------------------------------  +    
src/flt/OpenGL.hs view
@@ -143,7 +143,7 @@   (Vec4 (2*n/(r-l)) 0 0 0)   (Vec4 0 (2*n/(t-b)) 0 0)   (Vec4 ((r+l)/(r-l)) ((t+b)/(t-b)) (-(f+n)/(f-n)) (-1))-  (Vec4 0 0 (-2*f*n*(f-n)) 0)+  (Vec4 0 0 (-2*f*n/(f-n)) 0)    -- | The same as "frustumMatrix", but with a different parametrization. frustumMatrix2 {- ' CPP is sensitive to primes -}@@ -151,6 +151,18 @@   -> Vec3     -- ^ (right,bottom,far)   -> Mat4  frustumMatrix2 (Vec3 l t n) (Vec3 r b f) = frustumMatrix (l,r) (b,t) (n,f)++-- | Inverse of "frustumMatrix".+inverseFrustumMatrix+  :: (Flt,Flt)   -- ^ (left,right)+  -> (Flt,Flt)   -- ^ (bottom,top)+  -> (Flt,Flt)   -- ^ (near,far)+  -> Mat4 +inverseFrustumMatrix (l,r) (b,t) (n,f) = Mat4+  (Vec4 (0.5*(r-l)/n) 0 0 0)+  (Vec4 0 (0.5*(t-b)/n) 0 0)+  (Vec4 0 0 0 (0.5*(n-f)/(f*n)))+  (Vec4 (0.5*(r+l)/n) (0.5*(t+b)/n) (-1) (0.5*(f+n)/(f*n)))  -------------------------------------------------------------------------------- -- Vertex instances
vect.cabal view
@@ -1,5 +1,5 @@ Name:                vect-Version:             0.4.5+Version:             0.4.5.2 Synopsis:            A low-dimensional linear algebra library, tailored to computer graphics. Description:         A low-dimensional (2, 3 and 4) linear algebra library,                       with lots of useful functions. Intended usage is primarily @@ -10,7 +10,7 @@ License:             BSD3 License-file:        LICENSE Author:              Balazs Komuves-Copyright:           (c) 2008-2009 Balazs Komuves+Copyright:           (c) 2008-2010 Balazs Komuves Maintainer:          bkomuves (plus) hackage (at) gmail (dot) com Homepage:            http://code.haskell.org/~bkomuves/ Stability:           Experimental@@ -27,7 +27,8 @@                      src/flt/Util/Dim2.hs,                      src/flt/Util/Dim3.hs,                      src/flt/Util/Dim4.hs,-                     src/flt/Util/Projective.hs+                     src/flt/Util/Projective.hs,+                     src/flt/Instances.hs                       Flag splitBase   Description: Choose the new smaller, split-up base package.@@ -38,9 +39,10 @@    Library   if flag(splitBase)-    Build-Depends:       base >= 3, random +    Build-Depends:       base >= 3 && < 5+    Build-Depends:       random    else-    Build-Depends:       base <  3+    Build-Depends:       base >= 2 && < 3    if flag(OpenGL)     Build-Depends:       OpenGL@@ -58,6 +60,7 @@                        Data.Vect.Float.Util.Dim3,                         Data.Vect.Float.Util.Dim4,                        Data.Vect.Float.Util.Projective,+                       Data.Vect.Float.Instances                         Data.Vect.Double,                        Data.Vect.Double.Base, @@ -66,7 +69,8 @@                        Data.Vect.Double.Util.Dim2,                         Data.Vect.Double.Util.Dim3,                         Data.Vect.Double.Util.Dim4,-                       Data.Vect.Double.Util.Projective+                       Data.Vect.Double.Util.Projective,+                       Data.Vect.Double.Instances    Hs-Source-Dirs:      .   Extensions:          ForeignFunctionInterface, CPP,