Portability | unknown |
---|---|
Stability | unstable |
Maintainer | John Lato <jwlato@gmail.com> |
Safe Haskell | None |
Data.RangeSpace
Description
- data Range t = Range !t !t
- type Bounds t = (t, t)
- type Span t = (t, Diff t)
- toBounds :: Ord t => Range t -> Bounds t
- fromBounds :: Ord t => Bounds t -> Range t
- fromBoundsC :: Ord t => t -> t -> Range t
- newRange :: (Ord t, AffineSpace t, HasBasis (Diff t), Ord (Scalar (Diff t)), Num (Scalar (Diff t))) => t -> t -> Range t
- rangeStart :: Ord t => Range t -> t
- rangeEnd :: Ord t => Range t -> t
- range :: AffineSpace t => Range t -> Diff t
- toSpan :: AffineSpace t => Range t -> (t, Diff t)
- fromSpan :: AffineSpace t => Span t -> Range t
- fromSpanC :: AffineSpace t => t -> Diff t -> Range t
- range2D :: (Ord a, Ord b) => Range a -> Range b -> Range (D2V a b)
- fromRange2D :: (Ord a, Ord b) => Range (D2V a b) -> (Range a, Range b)
- unionBounds :: (Num (Scalar (Diff t)), Ord (Scalar (Diff t)), Ord t, HasBasis (Diff t), AffineSpace t) => Bounds t -> Bounds t -> Bounds t
- translateRange :: AffineSpace t => Diff t -> Range t -> Range t
- unionRange :: (Num (Scalar (Diff t)), Ord t, Ord (Scalar (Diff t)), HasBasis (Diff t), AffineSpace t) => Range t -> Range t -> Range t
- maskRange :: (Eq (Basis (Diff t)), Num (Scalar (Diff t)), Ord t, Ord (Scalar (Diff t)), HasBasis (Diff t), AffineSpace t) => Range t -> Range t -> Range t
- inRange :: (Ord a, AffineSpace a, HasBasis (Diff a), Eq (Basis (Diff a)), Num (Scalar (Diff a)), Ord (Scalar (Diff a))) => a -> Range a -> Bool
- inOrdRange :: Ord a => a -> Range a -> Bool
- compareRange :: Ord a => a -> Range a -> Ordering
- extentX :: (Ord b, Ord a) => Range (Point (D2V a b)) -> Range a
- extentY :: (Ord b, Ord a) => Range (Point (D2V a b)) -> Range b
Types
Define a Range over some domain
Constructors
Range !t !t |
Conversions
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 :: (Ord t, AffineSpace t, HasBasis (Diff t), Ord (Scalar (Diff t)), Num (Scalar (Diff 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
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 :: (Num (Scalar (Diff t)), Ord (Scalar (Diff t)), Ord t, HasBasis (Diff t), AffineSpace 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 :: (Num (Scalar (Diff t)), Ord t, Ord (Scalar (Diff t)), HasBasis (Diff t), AffineSpace 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.
Querying ranges
inRange :: (Ord a, AffineSpace a, HasBasis (Diff a), Eq (Basis (Diff a)), Num (Scalar (Diff a)), Ord (Scalar (Diff a))) => a -> Range a -> BoolSource
True if a value lies inside a Range
.
inOrdRange :: Ord a => a -> Range a -> BoolSource
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