numhask-space-0.11.1.0: Numerical spaces.
Safe HaskellSafe-Inferred
LanguageGHC2021

NumHask.Space.Rect

Description

A (finite) two-dimensional plane, implemented as a composite of a Point of Ranges.

Synopsis

Documentation

newtype Rect a Source #

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]

Constructors

Rect' (Compose Point Range a) 

Instances

Instances details
Representable Rect Source # 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Rep Rect #

Methods

tabulate :: (Rep Rect -> a) -> Rect a #

index :: Rect a -> Rep Rect -> a #

Foldable Rect Source # 
Instance details

Defined in NumHask.Space.Rect

Methods

fold :: Monoid m => Rect m -> m #

foldMap :: Monoid m => (a -> m) -> Rect a -> m #

foldMap' :: Monoid m => (a -> m) -> Rect a -> m #

foldr :: (a -> b -> b) -> b -> Rect a -> b #

foldr' :: (a -> b -> b) -> b -> Rect a -> b #

foldl :: (b -> a -> b) -> b -> Rect a -> b #

foldl' :: (b -> a -> b) -> b -> Rect a -> b #

foldr1 :: (a -> a -> a) -> Rect a -> a #

foldl1 :: (a -> a -> a) -> Rect a -> a #

toList :: Rect a -> [a] #

null :: Rect a -> Bool #

length :: Rect a -> Int #

elem :: Eq a => a -> Rect a -> Bool #

maximum :: Ord a => Rect a -> a #

minimum :: Ord a => Rect a -> a #

sum :: Num a => Rect a -> a #

product :: Num a => Rect a -> a #

Traversable Rect Source # 
Instance details

Defined in NumHask.Space.Rect

Methods

traverse :: Applicative f => (a -> f b) -> Rect a -> f (Rect b) #

sequenceA :: Applicative f => Rect (f a) -> f (Rect a) #

mapM :: Monad m => (a -> m b) -> Rect a -> m (Rect b) #

sequence :: Monad m => Rect (m a) -> m (Rect a) #

Applicative Rect Source # 
Instance details

Defined in NumHask.Space.Rect

Methods

pure :: a -> Rect a #

(<*>) :: Rect (a -> b) -> Rect a -> Rect b #

liftA2 :: (a -> b -> c) -> Rect a -> Rect b -> Rect c #

(*>) :: Rect a -> Rect b -> Rect b #

(<*) :: Rect a -> Rect b -> Rect a #

Functor Rect Source # 
Instance details

Defined in NumHask.Space.Rect

Methods

fmap :: (a -> b) -> Rect a -> Rect b #

(<$) :: a -> Rect b -> Rect a #

Distributive Rect Source # 
Instance details

Defined in NumHask.Space.Rect

Methods

distribute :: Functor f => f (Rect a) -> Rect (f a) #

collect :: Functor f => (a -> Rect b) -> f a -> Rect (f b) #

distributeM :: Monad m => m (Rect a) -> Rect (m a) #

collectM :: Monad m => (a -> Rect b) -> m a -> Rect (m b) #

Ord a => Semigroup (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

Methods

(<>) :: Rect a -> Rect a -> Rect a #

sconcat :: NonEmpty (Rect a) -> Rect a #

stimes :: Integral b => b -> Rect a -> Rect a #

Generic (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Rep (Rect a) :: Type -> Type #

Methods

from :: Rect a -> Rep (Rect a) x #

to :: Rep (Rect a) x -> Rect a #

(Ord a, Additive a, Show a) => Show (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

Methods

showsPrec :: Int -> Rect a -> ShowS #

show :: Rect a -> String #

showList :: [Rect a] -> ShowS #

Eq a => Eq (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

Methods

(==) :: Rect a -> Rect a -> Bool #

(/=) :: Rect a -> Rect a -> Bool #

Additive a => Additive (Rect a) Source #

Numeric algebra based on interval arithmetic for addition and unitRect and projection for multiplication >>> one + one :: Rect Double Rect (-1.0) 1.0 (-1.0) 1.0

Instance details

Defined in NumHask.Space.Rect

Methods

(+) :: Rect a -> Rect a -> Rect a #

zero :: Rect a #

Subtractive a => Subtractive (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

Methods

negate :: Rect a -> Rect a #

(-) :: Rect a -> Rect a -> Rect a #

(Ord a, Field a) => Basis (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Mag (Rect a) #

type Base (Rect a) #

Methods

magnitude :: Rect a -> Mag (Rect a) #

basis :: Rect a -> Base (Rect a) #

(Ord a, Field a) => Divisive (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

Methods

recip :: Rect a -> Rect a #

(/) :: Rect a -> Rect a -> Rect a #

(Ord a, Field a) => Multiplicative (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

Methods

(*) :: Rect a -> Rect a -> Rect a #

one :: Rect a #

(FromIntegral a Int, Field a, Ord a) => FieldSpace (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Grid (Rect a) Source #

Methods

grid :: Pos -> Rect a -> Grid (Rect a) -> [Element (Rect a)] Source #

gridSpace :: Rect a -> Grid (Rect a) -> [Rect a] Source #

Ord a => Space (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Element (Rect a) Source #

Methods

lower :: Rect a -> Element (Rect a) Source #

upper :: Rect a -> Element (Rect a) Source #

singleton :: Element (Rect a) -> Rect a Source #

intersection :: Rect a -> Rect a -> Rect a Source #

union :: Rect a -> Rect a -> Rect a Source #

normalise :: Rect a -> Rect a Source #

(...) :: Element (Rect a) -> Element (Rect a) -> Rect a Source #

(>.<) :: Element (Rect a) -> Element (Rect a) -> Rect a Source #

(|.|) :: Element (Rect a) -> Rect a -> Bool Source #

(|>|) :: Rect a -> Rect a -> Bool Source #

(|<|) :: Rect a -> Rect a -> Bool Source #

type Rep Rect Source # 
Instance details

Defined in NumHask.Space.Rect

type Rep Rect = (Bool, Bool)
type Rep (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

type Rep (Rect a) = D1 ('MetaData "Rect" "NumHask.Space.Rect" "numhask-space-0.11.1.0-CGZkWl1dCI0Hh4RFyxzImX" 'True) (C1 ('MetaCons "Rect'" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Compose Point Range a))))
type Base (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

type Base (Rect a) = a
type Mag (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

type Mag (Rect a) = Rect a
type Element (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

type Element (Rect a) = Point a
type Grid (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

type Grid (Rect a) = Point Int

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

projectOnR :: Rect Double -> Rect Double -> Rect Double -> Rect Double Source #

project a Rect from one Rect to another, preserving relative position, with guards for singleton Rects.

>>> projectOnR one (Rect 0 1 0 1) (Rect 0 0.5 0 0.5)
Rect (-0.5) 0.0 (-0.5) 0.0

projectOnP :: Rect Double -> Rect Double -> Point Double -> Point Double Source #

project a Point from one Rect to another, preserving relative position, with guards for singleton Rects.

>>> projectOnP one (Rect 0 1 0 1) zero
Point (-0.5) (-0.5)