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