0 | module Data.NumIdr.Transform.Translation
 1 |
 2 | import Data.Vect
 3 | import Data.NumIdr.Interfaces
 4 | import Data.NumIdr.Array
 5 | import Data.NumIdr.Vector
 6 | import Data.NumIdr.Matrix
 7 | import Data.NumIdr.Homogeneous
 8 | import Data.NumIdr.Transform.Point
 9 | import Data.NumIdr.Transform.Transform
10 |
11 | %default total
12 |
13 |
14 | ||| A translation is a transform that adds a constant vector value
15 | ||| to its input point.
16 | public export
17 | Translation : Nat -> Type -> Type
18 | Translation = Transform TTranslation
19 |
20 |
21 | ||| Determine if a homogeneous matrix encodes a translation.
22 | export
23 | isTranslation : Eq a => Num a => HMatrix' n a -> Bool
24 | isTranslation {n} mat with (viewShape mat)
25 |   _ | Shape [S n,S n] = isHMatrix mat && getMatrix mat == identity
26 |
27 | ||| Try to construct a translation from a homogeneous matrix.
28 | export
29 | fromHMatrix : Eq a => Num a => HMatrix' n a -> Maybe (Translation n a)
30 | fromHMatrix mat = if isTranslation mat then Just (unsafeMkTrans mat) else Nothing
31 |
32 |
33 | ||| Construct a translation given a vector.
34 | export
35 | translate : Num a => Vector n a -> Translation n a
36 | translate v = unsafeMkTrans (translationH v)
37 |