Description

a two-dimensional plane, implemented as a composite of a Point of Ranges.

Synopsis

# Documentation

newtype Rect a Source #

a rectangular space often representing a 2-dimensional or 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


as a Space instance with Points as Elements

>>> project (Rect 0 1 (-1) 0) (Rect 1 4 10 0) (Point 0.5 1)
Point 2.5 -10.0
>>> gridSpace (Rect 0 10 0 1) (Point 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) (Point 2 2)
[Point 2.5 0.25,Point 2.5 0.75,Point 7.5 0.25,Point 7.5 0.75]


Constructors

 Rect' (Compose Point Range a)
Instances

pattern Rect :: a -> a -> a -> a -> Rect a Source #

pattern of Rect lowerx upperx lowery uppery

pattern Ranges :: Range a -> Range a -> Rect a Source #

pattern of Ranges xrange yrange

corners :: Ord a => Rect a -> [Point a] Source #

create a list of points representing the lower left and upper right corners of a rectangle.

>>> corners unitRect
[Point -0.5 -0.5,Point 0.5 0.5]


corners4 :: Rect a -> [Point a] Source #

the 4 corners

>>> corners4 unitRect
[Point -0.5 -0.5,Point -0.5 0.5,Point 0.5 -0.5,Point 0.5 0.5]


projectRect :: (Ord a, Fractional a) => Rect a -> Rect a -> Rect a -> Rect a Source #

project a Rect from an old Space (Rect) to a new one.

The Space instance of Rect uses Points as Elements, but a Rect can also be a Space over Rects.

>>> projectRect (Rect 0 1 (-1) 0) (Rect 0 4 0 8) (Rect 0.25 0.75 (-0.75) (-0.25))
Rect 1.0 3.0 2.0 6.0


addRect :: Num a => Rect a -> Rect a -> Rect a Source #

>>> unitRect addRect unitRect
Rect -1.0 1.0 -1.0 1.0


multRect :: (Ord a, Fractional a) => Rect a -> Rect a -> Rect a Source #

Rect multiplication

>>> unitRect multRect Rect 0 2 0 4
Rect 0.0 2.0 0.0 4.0


a unit Rectangle, with values chosen so that width and height are one and mid is zero

>>> unitRect :: Rect Double
Rect -0.5 0.5 -0.5 0.5


foldRect :: Ord a => [Rect a] -> Maybe (Rect a) Source #

convex hull union of Rect's

>>> foldRect [Rect 0 1 0 1, unitRect]
Just Rect -0.5 1.0 -0.5 1.0


addPoint :: Num a => Point a -> Rect a -> Rect a Source #

add a Point to a Rect

>>> addPoint (Point 0 1) unitRect
Rect -0.5 0.5 0.5 1.5


rotateRect :: (Floating a, Ord a) => a -> Rect a -> Rect a Source #

rotate the corners of a Rect by x degrees relative to the origin, and fold to a new Rect

>>> rotateRect 45 unitRect
Rect -0.7071067811865475 0.7071067811865475 -5.551115123125783e-17 5.551115123125783e-17


gridR :: (Ord a, Fractional a) => (a -> a) -> Range a -> Int -> [Rect a] Source #

Create Rects for a formulae y = f(x) across an x range where the y range is Range 0 y

>>> gridR (**2) (Range 0 4) 4
[Rect 0.0 1.0 0.0 0.25,Rect 1.0 2.0 0.0 2.25,Rect 2.0 3.0 0.0 6.25,Rect 3.0 4.0 0.0 12.25]


gridF :: (Ord a, Fractional a) => (Point a -> b) -> Rect a -> Grid (Rect a) -> [(Rect a, b)] Source #

Create values c for Rects data for a formulae c = f(x,y)

>>> gridF (\(Point x y) -> x * y) (Rect 0 4 0 4) (Point 2 2)
[(Rect 0.0 2.0 0.0 2.0,1.0),(Rect 0.0 2.0 2.0 4.0,3.0),(Rect 2.0 4.0 0.0 2.0,3.0),(Rect 2.0 4.0 2.0 4.0,9.0)]


aspect :: Fractional a => a -> Rect a Source #

convert a ratio (eg x:1) to a Rect with a height of one.

>>> aspect 2
Rect -1.0 1.0 -0.5 0.5


ratio :: Fractional a => Rect a -> a Source #

convert a Rect to a ratio

>>> ratio (Rect (-1) 1 (-0.5) 0.5)
2.0