Make WithEpsilon
named implementations generic
This commit is contained in:
parent
f6809697e8
commit
d8c22d7ed6
|
@ -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)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue