Make WithEpsilon named implementations generic

This commit is contained in:
Kiana Sheibani 2024-05-06 04:36:43 -04:00
parent f6809697e8
commit d8c22d7ed6
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
2 changed files with 10 additions and 9 deletions

View file

@ -31,16 +31,16 @@ export
FieldCmp Double where FieldCmp Double where
abslt = (<) `on` abs abslt = (<) `on` abs
-- Alternative implementations of `Eq` and `FieldCmp` that compare floating -- Alternative implementations of `Eq` and `FieldCmp` that compare approximately,
-- point numbers approximately, useful when working with transforms -- useful when working with flating point numbers
namespace Eq namespace Eq
export 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) WithEpsilon ep = MkEq (\x,y => abs (x - y) < ep) (\x,y => abs (x - y) >= ep)
namespace FieldCmp namespace FieldCmp
export export
WithEpsilon : Double -> FieldCmp Double WithEpsilon : (Neg a, Fractional a, Abs a, Ord a) => a -> FieldCmp a
WithEpsilon ep = MkFieldCmp @{WithEpsilon ep} ((<) `on` abs) WithEpsilon ep = MkFieldCmp @{WithEpsilon ep} ((<) `on` abs)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View file

@ -25,12 +25,13 @@ isTranslation : Eq a => Num a => HMatrix' n a -> Bool
isTranslation {n} mat with (viewShape mat) isTranslation {n} mat with (viewShape mat)
_ | Shape [S n,S n] = isHMatrix mat && getMatrix mat == identity _ | 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. ||| Try to construct a translation from a homogeneous matrix.
export export
fromHMatrix : Eq a => Num a => HMatrix' n a -> Maybe (Translation n a) fromHMatrix : Eq a => Num a => HMatrix' n a -> Maybe (Translation n a)
fromHMatrix mat = if isTranslation mat then Just (unsafeMkTrans mat) else Nothing 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)