diff --git a/src/Data/NumIdr/Interfaces.idr b/src/Data/NumIdr/Interfaces.idr index 8e6cb78..1c5efe1 100644 --- a/src/Data/NumIdr/Interfaces.idr +++ b/src/Data/NumIdr/Interfaces.idr @@ -31,16 +31,16 @@ export FieldCmp Double where abslt = (<) `on` abs --- Alternative implementations of `Eq` and `FieldCmp` that compare floating --- point numbers approximately, useful when working with transforms +-- Alternative implementations of `Eq` and `FieldCmp` that compare approximately, +-- useful when working with flating point numbers namespace Eq export - WithEpsilon : Double -> Eq Double + WithEpsilon : (Neg a, Abs a, Ord a) => a -> Eq a WithEpsilon ep = MkEq (\x,y => abs (x - y) < ep) (\x,y => abs (x - y) >= ep) namespace FieldCmp export - WithEpsilon : Double -> FieldCmp Double + WithEpsilon : (Neg a, Fractional a, Abs a, Ord a) => a -> FieldCmp a WithEpsilon ep = MkFieldCmp @{WithEpsilon ep} ((<) `on` abs) -------------------------------------------------------------------------------- diff --git a/src/Data/NumIdr/Transform/Translation.idr b/src/Data/NumIdr/Transform/Translation.idr index 6ebdbcb..abc9ebb 100644 --- a/src/Data/NumIdr/Transform/Translation.idr +++ b/src/Data/NumIdr/Transform/Translation.idr @@ -25,12 +25,13 @@ isTranslation : Eq a => Num a => HMatrix' n a -> Bool isTranslation {n} mat with (viewShape mat) _ | Shape [S n,S n] = isHMatrix mat && getMatrix mat == identity -||| Construct a translation given a vector. -export -translate : Num a => Vector n a -> Translation n a -translate v = unsafeMkTrans (translationH v) - ||| Try to construct a translation from a homogeneous matrix. export fromHMatrix : Eq a => Num a => HMatrix' n a -> Maybe (Translation n a) fromHMatrix mat = if isTranslation mat then Just (unsafeMkTrans mat) else Nothing + + +||| Construct a translation given a vector. +export +translate : Num a => Vector n a -> Translation n a +translate v = unsafeMkTrans (translationH v)