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

Data.Range

Synopsis

# Documentation

data EndPoint a Source

Constructors

 Open a Closed a

Instances

 Source Source Source Eq a => Eq (EndPoint a) Source Read a => Read (EndPoint a) Source Show a => Show (EndPoint a) Source

data Range a Source

Constructors

 Range Fields_lower :: EndPoint a _upper :: EndPoint a

Instances

 Source Source Source Eq a => Eq (Range a) Source Read a => Read (Range a) Source Show a => Show (Range a) Source Ord a => IsIntersectableWith (Range a) (Range a) Source type IntersectionOf (Range a) (Range a) = (:) * NoIntersection ((:) * (Range a) ([] *)) Source

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

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

pattern OpenRange :: t -> t -> Range t Source

pattern ClosedRange :: t -> t -> Range t Source

pattern Range' :: EndPoint a -> EndPoint 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.

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