Safe Haskell | None |
---|---|
Language | Haskell2010 |
- newtype Rect a = Rect' (Compose Pair Range a)
- pattern Rect :: a -> a -> a -> a -> Rect a
- pattern Ranges :: Range a -> Range a -> Rect a
- corners :: (Signed a, FromInteger a, BoundedField a, Ord a) => Rect a -> [Pair a]
- projectRect :: (Signed a, FromInteger a, Ord a, BoundedField a) => Rect a -> Rect a -> Rect a -> Rect a
Documentation
a Pair
of Ranges
that form a rectangle in what is often thought of as the XY plane.
>>>
let a = Rect (-1) 1 (-2) 4
>>>
a
Rect -1 1 -2 4>>>
let (Ranges x y) = a
>>>
x
Range -1 1>>>
y
Range -2 4>>>
fmap (+1) (Rect 1 2 3 4)
Rect 2 3 4 5>>>
one :: Rect Double
Rect -0.5 0.5 -0.5 0.5>>>
zero :: Rect Double
Rect Infinity -Infinity Infinity -Infinity
as a Field instance
>>>
Rect 0 1 2 3 + zero
Rect 0.0 1.0 2.0 3.0>>>
Rect 0 1 (-2) (-1) + Rect 2 3 (-5) 3
Rect 0.0 3.0 -5.0 3.0>>>
Rect 1 1 1 1 - one
Rect 0.5 1.0 0.5 1.0>>>
Rect 0 1 0 1 * one
Rect 0.0 1.0 0.0 1.0>>>
Rect 0 1 0 1 / one
Rect 0.0 1.0 0.0 1.0>>>
singleton (Pair 1.0 2.0) :: Rect Double
Rect 1.0 1.0 2.0 2.0>>>
abs (Rect 1 0 1 0)
Rect 0.0 1.0 0.0 1.0>>>
sign (Rect 1 0 1 0) == negate one
True
as a Space instance
>>>
project (Rect 0 1 (-1) 0) (Rect 1 4 10 0) (Pair 0.5 1)
Pair 2.5 -10.0>>>
gridSpace (Rect 0 10 0 1) (Pair 2 2)
[Rect 0.0 5.0 0.0 0.5,Rect 0.0 5.0 0.5 1.0,Rect 5.0 10.0 0.0 0.5,Rect 5.0 10.0 0.5 1.0]>>>
grid MidPos (Rect 0 10 0 1) (Pair 2 2)
[Pair 2.5 0.25,Pair 2.5 0.75,Pair 7.5 0.25,Pair 7.5 0.75]
corners :: (Signed a, FromInteger a, BoundedField a, Ord a) => Rect a -> [Pair a] Source #
create a list of pairs representing the lower left and upper right cormners of a rectangle.
projectRect :: (Signed a, FromInteger a, Ord a, BoundedField a) => Rect a -> Rect a -> Rect a -> Rect a Source #
project a Rect from an old range to a new one