range-space-0.1.1.2: A Range type with vector-space instances

Portability unknown unstable John Lato None

Data.RangeSpace

Description

Synopsis

# Types

data Range t Source

Define a Range over some domain

Constructors

 Range !t !t

Instances

 Functor Range Applicative Range Eq t => Eq (Range t) Ord t => Ord (Range t) Show t => Show (Range t) BasisRange t => Semigroup (Range t)

type Bounds t = (t, t)Source

A '(minimum,maximum)' pair

type Span t = (t, Diff t)Source

A starting point and duration

# Conversions

toBounds :: Ord t => Range t -> Bounds tSource

Convert a `Range` to a '(min,max)' pair.

fromBounds :: Ord t => Bounds t -> Range tSource

Create a `Range` from a '(min,max)' `Bounds` pair.

`fromBounds` uses the `Ord` instance to construct a `Range`. For multi-dimensional types, this probably isn't correct. For that case, see `newRange`

fromBoundsC :: Ord t => t -> t -> Range tSource

A curried form of `fromBounds`

See the notes for `fromBounds`.

newRange :: BasisRange t => t -> t -> Range tSource

Create a range from a 'start,stop' pair. For multi-dimensional ranges, the resulting range will be the union of the two points.

rangeStart :: Ord t => Range t -> tSource

rangeEnd :: Ord t => Range t -> tSource

range :: AffineSpace t => Range t -> Diff tSource

Get the range covered by a `Range`

toSpan :: AffineSpace t => Range t -> (t, Diff t)Source

Generate a `Span`, '(start, distance)' from a `Range`

fromSpan :: AffineSpace t => Span t -> Range tSource

Generate a `Range` from a `Span` '(start, distance)'

fromSpanC :: AffineSpace t => t -> Diff t -> Range tSource

A curried `fromSpan`

range2D :: (Ord a, Ord b) => Range a -> Range b -> Range (D2V a b)Source

Create a 2D range from two independent axes.

fromRange2D :: (Ord a, Ord b) => Range (D2V a b) -> (Range a, Range b)Source

Decompose a 2D range into X/Y axes.

# Functions

## Combining ranges

unionBounds :: BasisRange t => Bounds t -> Bounds t -> Bounds tSource

Calculate the union of two `Bounds`. See the notes for `unionRange`.

translateRange :: AffineSpace t => Diff t -> Range t -> Range tSource

Translate a `Range` by the given amount.

unionRange :: BasisRange t => Range t -> Range t -> Range tSource

Calculate the union of two `Range`s, per-basis.

The union is constructed by calculating the difference vector between two points, performing a basis decomposition on that vector, performing comparisons and adjustments on each basis vector, recomposing, and adding the result back to the starting position.

The advantage of this method is that it works on an `AffineSpace` and doesn't require a full `VectorSpace`. It does require that the affine space scalars are in a vector space, but this is more easily satisfiable.

Arguments

 :: (Eq (Basis (Diff t)), BasisRange t) => Range t restriction -> Range t original Range -> Range t

Restrict a `Range` by applying a sub-`Range` mask.

For ranges with multiple dimensions, the masking is performed independently for each basis. If the range lies entirely outside the mask, the returned value is 'Range rmin rmin' (per-basis)

## Querying ranges

inRange :: (BasisRange a, Eq (Basis (Diff a))) => a -> Range a -> BoolSource

True if a value lies inside a `Range`.

inOrdRange :: Ord a => a -> Range a -> BoolSource

Check if a value is in a `Range`, using `Ord` comparison.

If `Ord` is usable, this is likely to be faster than `inRange`.

compareRange :: Ord a => a -> Range a -> OrderingSource

Compare a value to a `Range`. Returns `EQ` if the value is inside the range, `LT` or `GT` if it's outside.

Uses `Ord` for comparison.

extentX :: (Ord b, Ord a) => Range (Point (D2V a b)) -> Range aSource

Calculate the X extent of a 2D pointwise range

extentY :: (Ord b, Ord a) => Range (Point (D2V a b)) -> Range bSource

Calculate the Y extent of a 2D pointwise range