Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- newtype Rect a = Rect' (Compose Point Range a)
- pattern Rect :: a -> a -> a -> a -> Rect a
- pattern Ranges :: Range a -> Range a -> Rect a
- corners :: Ord a => Rect a -> [Point a]
- corners4 :: Rect a -> [Point a]
- projectRect :: (Field a, Ord a) => Rect a -> Rect a -> Rect a -> Rect a
- foldRect :: Ord a => [Rect a] -> Maybe (Rect a)
- foldRectUnsafe :: (Foldable f, Ord a) => f (Rect a) -> Rect a
- addPoint :: Additive a => Point a -> Rect a -> Rect a
- rotationBound :: (TrigField a, Ord a) => a -> Rect a -> Rect a
- gridR :: (Field a, FromIntegral a Int, Ord a) => (a -> a) -> Range a -> Int -> [Rect a]
- gridF :: (Point Double -> b) -> Rect Double -> Grid (Rect Double) -> [(Rect Double, b)]
- aspect :: Double -> Rect Double
- ratio :: Field a => Rect a -> a
- projectOnR :: Rect Double -> Rect Double -> Rect Double -> Rect Double
- projectOnP :: Rect Double -> Rect Double -> Point Double -> Point Double
Documentation
a rectangular space often representing a finite 2-dimensional or XY plane.
>>>
one :: Rect Double
Rect (-0.5) 0.5 (-0.5) 0.5
>>>
zero :: Rect Double
Rect 0.0 0.0 0.0 0.0
>>>
one + one :: Rect Double
Rect (-1.0) 1.0 (-1.0) 1.0
>>>
let a = Rect (-1.0) 1.0 (-2.0) 4.0
>>>
a
Rect (-1.0) 1.0 (-2.0) 4.0
>>>
a * one
Rect (-1.0) 1.0 (-2.0) 4.0
>>>
let (Ranges x y) = a
>>>
x
Range -1.0 1.0>>>
y
Range -2.0 4.0>>>
fmap (+1) (Rect 1 2 3 4)
Rect 2 3 4 5
as a Space instance with Points as Elements
>>>
project (Rect 0.0 1.0 (-1.0) 0.0) (Rect 1.0 4.0 10.0 0.0) (Point 0.5 1.0)
Point 2.5 (-10.0)>>>
gridSpace (Rect 0.0 10.0 0.0 1.0) (Point (2::Int) (2::Int))
[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.0 10.0 0.0 1.0) (Point (2::Int) (2::Int))
[Point 2.5 0.25,Point 2.5 0.75,Point 7.5 0.25,Point 7.5 0.75]
Instances
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 one
[Point (-0.5) (-0.5),Point 0.5 0.5]
corners4 :: Rect a -> [Point a] Source #
the 4 corners
>>>
corners4 one
[Point (-0.5) (-0.5),Point (-0.5) 0.5,Point 0.5 (-0.5),Point 0.5 0.5]
projectRect :: (Field a, Ord 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
foldRect :: Ord a => [Rect a] -> Maybe (Rect a) Source #
convex hull union of Rect's
>>>
foldRect [Rect 0 1 0 1, one]
Just Rect (-0.5) 1.0 (-0.5) 1.0
foldRectUnsafe :: (Foldable f, Ord a) => f (Rect a) -> Rect a Source #
convex hull union of Rect's applied to a non-empty structure
>>>
foldRectUnsafe [Rect 0 1 0 1, one]
Rect (-0.5) 1.0 (-0.5) 1.0
addPoint :: Additive a => Point a -> Rect a -> Rect a Source #
add a Point to a Rect
>>>
addPoint (Point 0 1) one
Rect (-0.5) 0.5 0.5 1.5
rotationBound :: (TrigField 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
>>>
rotationBound (pi/4) one
Rect (-0.7071067811865475) 0.7071067811865475 (-0.7071067811865475) 0.7071067811865475
gridR :: (Field a, FromIntegral a Int, Ord 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 :: (Point Double -> b) -> Rect Double -> Grid (Rect Double) -> [(Rect Double, 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 :: Double -> Rect Double 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 :: Field a => Rect a -> a Source #
convert a Rect to a ratio
>>>
:set -XNegativeLiterals
>>>
ratio (Rect (-1) 1 (-0.5) 0.5)
2.0