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

CopyrightJohn Lato
LicenseBSD3 (see LICENSE)
MaintainerJohn Lato <jwlato@gmail.com>
Stabilityunstable
Portabilityunknown
Safe HaskellNone
LanguageHaskell2010

Data.RangeSpace

Contents

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 t Source

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

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

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 t Source

A curried form of fromBounds

See the notes for fromBounds.

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

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 -> t Source

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

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

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 t Source

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

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

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 t Source

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

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

Translate a Range by the given amount.

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

Calculate the union of two Ranges, 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.

maskRange Source

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 -> Bool Source

True if a value lies inside a Range.

inOrdRange :: Ord a => a -> Range a -> Bool Source

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 -> Ordering Source

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 a Source

Calculate the X extent of a 2D pointwise range

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

Calculate the Y extent of a 2D pointwise range

Modules