packages feed

boundingboxes 0.2.1 → 0.2.2

raw patch · 3 files changed

+11/−3 lines, 3 files

Files

Data/BoundingBox.hs view
@@ -38,9 +38,17 @@ isInside :: (Applicative f, Foldable f, Ord a) => f a -> Box f a -> Bool
 isInside v (Box p q) = Foldable.and (liftA2 (<=) p v) && Foldable.and (liftA2 (<=) v q)
 
+-- | Extend each side.
+inflate :: (Functor f, Num a) => a -> Box f a -> Box f a
+inflate t (Box p q) = Box (fmap (subtract t) p) (fmap (+t) q)
+
 -- | Returns True if the bounding box is valid.
 isCanonical :: (Applicative f, Foldable f, Ord a) => Box f a -> Bool
 isCanonical (Box p q) = Foldable.and (liftA2 (<=) p q)
+
+-- | Calculate an union between two boundingboxes.
+union :: (Applicative f, Ord a) => Box f a -> Box f a -> Box f a
+union (Box p q) (Box r s) = Box (liftA2 min p r) (liftA2 max q s)
 
 -- | Calculate an intersect between two boundingboxes.
 intersect :: (Applicative f, Ord a) => Box f a -> Box f a -> Box f a
boundingboxes.cabal view
@@ -1,5 +1,5 @@ name:                boundingboxes
-version:             0.2.1
+version:             0.2.2
 synopsis:            A generic boundingbox for an arbitrary vector
 -- description:         
 homepage:            https://github.com/fumieval/boundingboxes
tests/properties.hs view
@@ -30,8 +30,8 @@ prop_rearrange (getReference -> ref) bb pos = norm (bb ^. size 0 - bb' ^. size 0) < 10e-4 where
     bb' = bb & position ref .~ pos :: Box V2 Float
 
-prop_construct (getReference -> ref) pos (getPositive -> sz) = nearZero (bb ^. size 0 - sz)
-    .&&. nearZero (bb ^. position ref - pos) where
+prop_construct (getReference -> ref) pos (getPositive -> sz) = norm (bb ^. size 0 - sz) < 10e-4
+    .&&. norm (bb ^. position ref - pos) < 10e-4 where
     
     bb = sizePos ref # (sz, pos) :: Box V2 Float