hgeometry-0.7.0.0: Geometric Algorithms, Data structures, and Data types.

Data.Range

Description

Synopsis

# Documentation

data EndPoint a Source #

Endpoints of a range may either be open or closed.

Constructors

 Open !a Closed !a
Instances
 Source # Instance detailsDefined in Data.Range Methodsfmap :: (a -> b) -> EndPoint a -> EndPoint b #(<$) :: a -> EndPoint b -> EndPoint a # Source # Instance detailsDefined in Data.Range Methodsfold :: Monoid m => EndPoint m -> m #foldMap :: Monoid m => (a -> m) -> EndPoint a -> m #foldr :: (a -> b -> b) -> b -> EndPoint a -> b #foldr' :: (a -> b -> b) -> b -> EndPoint a -> b #foldl :: (b -> a -> b) -> b -> EndPoint a -> b #foldl' :: (b -> a -> b) -> b -> EndPoint a -> b #foldr1 :: (a -> a -> a) -> EndPoint a -> a #foldl1 :: (a -> a -> a) -> EndPoint a -> a #toList :: EndPoint a -> [a] #null :: EndPoint a -> Bool #length :: EndPoint a -> Int #elem :: Eq a => a -> EndPoint a -> Bool #maximum :: Ord a => EndPoint a -> a #minimum :: Ord a => EndPoint a -> a #sum :: Num a => EndPoint a -> a #product :: Num a => EndPoint a -> a # Source # Instance detailsDefined in Data.Range Methodstraverse :: Applicative f => (a -> f b) -> EndPoint a -> f (EndPoint b) #sequenceA :: Applicative f => EndPoint (f a) -> f (EndPoint a) #mapM :: Monad m => (a -> m b) -> EndPoint a -> m (EndPoint b) #sequence :: Monad m => EndPoint (m a) -> m (EndPoint a) # Eq a => Eq (EndPoint a) Source # Instance detailsDefined in Data.Range Methods(==) :: EndPoint a -> EndPoint a -> Bool #(/=) :: EndPoint a -> EndPoint a -> Bool # Ord a => Ord (EndPoint a) Source # Instance detailsDefined in Data.Range Methodscompare :: EndPoint a -> EndPoint a -> Ordering #(<) :: EndPoint a -> EndPoint a -> Bool #(<=) :: EndPoint a -> EndPoint a -> Bool #(>) :: EndPoint a -> EndPoint a -> Bool #(>=) :: EndPoint a -> EndPoint a -> Bool #max :: EndPoint a -> EndPoint a -> EndPoint a #min :: EndPoint a -> EndPoint a -> EndPoint a # Read a => Read (EndPoint a) Source # Instance detailsDefined in Data.Range MethodsreadsPrec :: Int -> ReadS (EndPoint a) # Show a => Show (EndPoint a) Source # Instance detailsDefined in Data.Range MethodsshowsPrec :: Int -> EndPoint a -> ShowS #show :: EndPoint a -> String #showList :: [EndPoint a] -> ShowS # Source # Instance detailsDefined in Data.Range Associated Typestype Rep (EndPoint a) :: * -> * # Methodsfrom :: EndPoint a -> Rep (EndPoint a) x #to :: Rep (EndPoint a) x -> EndPoint a # Arbitrary r => Arbitrary (EndPoint r) # Instance detailsDefined in Test.QuickCheck.HGeometryInstances Methodsshrink :: EndPoint r -> [EndPoint r] # NFData a => NFData (EndPoint a) Source # Instance detailsDefined in Data.Range Methodsrnf :: EndPoint a -> () # type Rep (EndPoint a) Source # Instance detailsDefined in Data.Range type Rep (EndPoint a) = D1 (MetaData "EndPoint" "Data.Range" "hgeometry-0.7.0.0-3y7zA7ljCTE9s6EHvXHItM" False) (C1 (MetaCons "Open" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a)) :+: C1 (MetaCons "Closed" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a))) data Range a Source # Data type for representing ranges. Constructors  Range Fields_lower :: !(EndPoint a) _upper :: !(EndPoint a) Instances  Source # Instance detailsDefined in Data.Range Methodsfmap :: (a -> b) -> Range a -> Range b #(<$) :: a -> Range b -> Range a # Source # Instance detailsDefined in Data.Range Methodsfold :: Monoid m => Range m -> m #foldMap :: Monoid m => (a -> m) -> Range a -> m #foldr :: (a -> b -> b) -> b -> Range a -> b #foldr' :: (a -> b -> b) -> b -> Range a -> b #foldl :: (b -> a -> b) -> b -> Range a -> b #foldl' :: (b -> a -> b) -> b -> Range a -> b #foldr1 :: (a -> a -> a) -> Range a -> a #foldl1 :: (a -> a -> a) -> Range a -> a #toList :: Range a -> [a] #null :: Range a -> Bool #length :: Range a -> Int #elem :: Eq a => a -> Range a -> Bool #maximum :: Ord a => Range a -> a #minimum :: Ord a => Range a -> a #sum :: Num a => Range a -> a #product :: Num a => Range a -> a # Source # Instance detailsDefined in Data.Range Methodstraverse :: Applicative f => (a -> f b) -> Range a -> f (Range b) #sequenceA :: Applicative f => Range (f a) -> f (Range a) #mapM :: Monad m => (a -> m b) -> Range a -> m (Range b) #sequence :: Monad m => Range (m a) -> m (Range a) # Eq a => Eq (Range a) Source # Instance detailsDefined in Data.Range Methods(==) :: Range a -> Range a -> Bool #(/=) :: Range a -> Range a -> Bool # Show a => Show (Range a) Source # Instance detailsDefined in Data.Range MethodsshowsPrec :: Int -> Range a -> ShowS #show :: Range a -> String #showList :: [Range a] -> ShowS # Generic (Range a) Source # Instance detailsDefined in Data.Range Associated Typestype Rep (Range a) :: * -> * # Methodsfrom :: Range a -> Rep (Range a) x #to :: Rep (Range a) x -> Range a # (Arbitrary r, Ord r) => Arbitrary (Range r) # Instance detailsDefined in Test.QuickCheck.HGeometryInstances Methodsarbitrary :: Gen (Range r) #shrink :: Range r -> [Range r] # NFData a => NFData (Range a) Source # Instance detailsDefined in Data.Range Methodsrnf :: Range a -> () # Source # Instance detailsDefined in Data.Geometry.IntervalTree MethodstoRange :: Range r -> Range (NumType (Range r)) Source # Ord a => IsIntersectableWith (Range a) (Range a) Source # Instance detailsDefined in Data.Range Methodsintersect :: Range a -> Range a -> Intersection (Range a) (Range a) Source #intersects :: Range a -> Range a -> Bool Source #nonEmptyIntersection :: proxy (Range a) -> proxy (Range a) -> Intersection (Range a) (Range a) -> Bool Source # type Rep (Range a) Source # Instance detailsDefined in Data.Range type Rep (Range a) = D1 (MetaData "Range" "Data.Range" "hgeometry-0.7.0.0-3y7zA7ljCTE9s6EHvXHItM" False) (C1 (MetaCons "Range" PrefixI True) (S1 (MetaSel (Just "_lower") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (EndPoint a)) :*: S1 (MetaSel (Just "_upper") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (EndPoint a)))) type NumType (Range a) Source # Instance detailsDefined in Data.Range type NumType (Range a) = a type IntersectionOf (Range a) (Range a) Source # Instance detailsDefined in Data.Range type IntersectionOf (Range a) (Range a) = NoIntersection ': (Range a ': ([] :: [*]))

lower :: forall a. Lens' (Range a) (EndPoint a) Source #

upper :: forall a. Lens' (Range a) (EndPoint a) Source #

pattern OpenRange :: a -> a -> Range a Source #

pattern ClosedRange :: a -> a -> Range a Source #

pattern Range' :: a -> a -> Range a Source #

A range from l to u, ignoring/forgetting the type of the endpoints

inRange :: Ord a => a -> Range a -> Bool Source #

Test if a value lies in a range.

>>> 1 inRange (OpenRange 0 2)
True
>>> 1 inRange (OpenRange 0 1)
False
>>> 1 inRange (ClosedRange 0 1)
True
>>> 1 inRange (ClosedRange 1 1)
True
>>> 10 inRange (OpenRange 1 10)
False
>>> 10 inRange (ClosedRange 0 1)
False


width :: Num r => Range r -> r Source #

Get the width of the interval

>>> width $ClosedRange 1 10 9 >>> width$ OpenRange 5 10
5


clipLower :: Ord a => EndPoint a -> Range a -> Maybe (Range a) Source #

Clip the interval from below. I.e. intersect with the interval {l,infty), where { is either open, (, orr closed, [.

clipUpper :: Ord a => EndPoint a -> Range a -> Maybe (Range a) Source #

Clip the interval from above. I.e. intersect with (-infty, u}, where } is either open, ), or closed, ],

isValid :: Ord a => Range a -> Bool Source #

Check if the range is valid and nonEmpty, i.e. if the lower endpoint is indeed smaller than the right endpoint. Note that we treat empty open-ranges as invalid as well.

covers :: Ord a => Range a -> Range a -> Bool Source #

Wether or not the first range completely covers the second one

shiftLeft :: Num r => r -> Range r -> Range r Source #

Shift a range x units to the left

>>> prettyShow $shiftLeft 10 (ClosedRange 10 20) "[0, 10]" >>> prettyShow$ shiftLeft 10 (OpenRange 15 25)
"(5, 15)"


shiftRight :: Num r => r -> Range r -> Range r Source #

Shifts the range to the right

>>> prettyShow $shiftRight 10 (ClosedRange 10 20) "[20, 30]" >>> prettyShow$ shiftRight 10 (OpenRange 15 25)
"(25, 35)"