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

Safe HaskellNone
LanguageHaskell2010

Data.Range

Synopsis

Documentation

data EndPoint a Source #

Constructors

Open !a 
Closed !a 

Instances

Functor EndPoint Source # 

Methods

fmap :: (a -> b) -> EndPoint a -> EndPoint b #

(<$) :: a -> EndPoint b -> EndPoint a #

Foldable EndPoint Source # 

Methods

fold :: 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 #

Traversable EndPoint Source # 

Methods

traverse :: 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 # 

Methods

(==) :: EndPoint a -> EndPoint a -> Bool #

(/=) :: EndPoint a -> EndPoint a -> Bool #

Ord a => Ord (EndPoint a) Source # 

Methods

compare :: 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 # 
Show a => Show (EndPoint a) Source # 

Methods

showsPrec :: Int -> EndPoint a -> ShowS #

show :: EndPoint a -> String #

showList :: [EndPoint a] -> ShowS #

Generic (EndPoint a) Source # 

Associated Types

type Rep (EndPoint a) :: * -> * #

Methods

from :: EndPoint a -> Rep (EndPoint a) x #

to :: Rep (EndPoint a) x -> EndPoint a #

NFData a => NFData (EndPoint a) Source # 

Methods

rnf :: EndPoint a -> () #

type Rep (EndPoint a) Source # 
type Rep (EndPoint a) = D1 (MetaData "EndPoint" "Data.Range" "hgeometry-0.6.0.0-ODn7ZyBfwj6IkLPAAzetJ" False) ((:+:) (C1 (MetaCons "Open" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a))) (C1 (MetaCons "Closed" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a))))

data Range a Source #

Constructors

Range 

Fields

Instances

Functor Range Source # 

Methods

fmap :: (a -> b) -> Range a -> Range b #

(<$) :: a -> Range b -> Range a #

Foldable Range Source # 

Methods

fold :: 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 #

Traversable Range Source # 

Methods

traverse :: 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 # 

Methods

(==) :: Range a -> Range a -> Bool #

(/=) :: Range a -> Range a -> Bool #

Show a => Show (Range a) Source # 

Methods

showsPrec :: Int -> Range a -> ShowS #

show :: Range a -> String #

showList :: [Range a] -> ShowS #

Generic (Range a) Source # 

Associated Types

type Rep (Range a) :: * -> * #

Methods

from :: Range a -> Rep (Range a) x #

to :: Rep (Range a) x -> Range a #

NFData a => NFData (Range a) Source # 

Methods

rnf :: Range a -> () #

IntervalLike (Range r) Source # 

Methods

toRange :: Range r -> Range (NumType (Range r)) Source #

Ord a => IsIntersectableWith (Range a) (Range a) Source # 

Methods

intersect :: 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 # 
type Rep (Range a) = D1 (MetaData "Range" "Data.Range" "hgeometry-0.6.0.0-ODn7ZyBfwj6IkLPAAzetJ" False) (C1 (MetaCons "Range" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "_lower") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (EndPoint a))) (S1 (MetaSel (Just Symbol "_upper") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (EndPoint a)))))
type NumType (Range a) Source # 
type NumType (Range a) = a
type IntersectionOf (Range a) (Range a) Source # 
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 :: forall a. a -> a -> Range a Source #

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

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

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

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)"