Create Data.NumIdr.Transform.Transform
This commit is contained in:
parent
8839dd049a
commit
33f64c69d9
3 changed files with 125 additions and 8 deletions
|
|
@ -27,6 +27,10 @@ export
|
|||
fromVector : Vector n a -> Point n a
|
||||
fromVector = MkPoint
|
||||
|
||||
export
|
||||
toVector : Point n a -> Vector n a
|
||||
toVector = vec
|
||||
|
||||
export
|
||||
point : Vect n a -> Point n a
|
||||
point = fromVector . vector
|
||||
|
|
@ -83,20 +87,22 @@ export
|
|||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Interface implementations
|
||||
-- Arithmetic operations
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace Right
|
||||
export
|
||||
(+) : Num a => Point n a -> Vector n a -> Point n a
|
||||
MkPoint a + b = MkPoint (zipWith (+) a b)
|
||||
-- Affine space operations
|
||||
|
||||
namespace Left
|
||||
export
|
||||
(+) : Num a => Vector n a -> Point n a -> Point n a
|
||||
a + MkPoint b = MkPoint (zipWith (+) a b)
|
||||
|
||||
namespace Right
|
||||
export
|
||||
(+) : Num a => Point n a -> Vector n a -> Point n a
|
||||
MkPoint a + b = MkPoint (zipWith (+) a b)
|
||||
|
||||
|
||||
export
|
||||
(-) : Neg a => Point n a -> Point n a -> Vector n a
|
||||
|
|
@ -108,6 +114,39 @@ MkPoint a - MkPoint b = zipWith (-) a b
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
export
|
||||
Zippable (Point n) where
|
||||
zipWith f (MkPoint v1) (MkPoint v2) = MkPoint (zipWith f v1 v2)
|
||||
zipWith3 f (MkPoint v1) (MkPoint v2) (MkPoint v3) = MkPoint (zipWith3 f v1 v2 v3)
|
||||
unzipWith f (MkPoint v) = bimap MkPoint MkPoint (unzipWith f v)
|
||||
unzipWith3 f (MkPoint v) = bimap MkPoint (bimap MkPoint MkPoint) (unzipWith3 f v)
|
||||
|
||||
export
|
||||
Functor (Point n) where
|
||||
map f (MkPoint v) = MkPoint (map f v)
|
||||
|
||||
export
|
||||
{n : _} -> Applicative (Point n) where
|
||||
pure = MkPoint . pure
|
||||
MkPoint f <*> MkPoint v = MkPoint (f <*> v)
|
||||
|
||||
{n : _} -> Monad (Point n) where
|
||||
join (MkPoint v) = MkPoint $ join $ map unwrap v
|
||||
where
|
||||
unwrap : Point n a -> Vector n a
|
||||
unwrap (MkPoint x) = x
|
||||
|
||||
export
|
||||
Foldable (Point n) where
|
||||
foldl f z (MkPoint v) = foldl f z v
|
||||
foldr f z (MkPoint v) = foldr f z v
|
||||
null (MkPoint v) = null v
|
||||
toList (MkPoint v) = toList v
|
||||
|
||||
export
|
||||
Traversable (Point n) where
|
||||
traverse f (MkPoint v) = map MkPoint (traverse f v)
|
||||
|
||||
export
|
||||
Show a => Show (Point n a) where
|
||||
showPrec d (MkPoint v) = showCon d "point " $
|
||||
|
|
@ -117,7 +156,6 @@ export
|
|||
Cast a b => Cast (Point n a) (Point n b) where
|
||||
cast (MkPoint v) = MkPoint (cast v)
|
||||
|
||||
|
||||
export
|
||||
Num a => Mult (Matrix m n a) (Point n a) (Point m a) where
|
||||
mat *. MkPoint v = MkPoint (mat *. v)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue