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

NumHask.Space.Point

Description

A 2-dimensional point.

Synopsis

Documentation

data Point a Source #

A 2-dimensional Point of a's

In contrast with a tuple, a Point is functorial over both arguments.

>>> let p = Point 1 1
>>> p + p
Point 2 2
>>> (2*) <$> p
Point 2 2

A major reason for this bespoke treatment (compared to just using linear, say) is that Points do not have maximums and minimums but they do form a lattice, and this is useful for folding sets of points to find out the (rectangular) Space they occupy.

>>> Point 0 1 /\ Point 1 0
Point 0 0
>>> Point 0 1 \/ Point 1 0
Point 1 1

This is used extensively in chart-svg to ergonomically obtain chart areas.

unsafeSpace1 [Point 1 0, Point 0 1] :: Rect Double

Rect 0.0 1.0 0.0 1.0

Constructors

Point 

Fields

Instances

Instances details
Representable Point Source # 
Instance details

Defined in NumHask.Space.Point

Associated Types

type Rep Point #

Methods

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

index :: Point a -> Rep Point -> a #

Foldable Point Source # 
Instance details

Defined in NumHask.Space.Point

Methods

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

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

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

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

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

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

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

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

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

toList :: Point a -> [a] #

null :: Point a -> Bool #

length :: Point a -> Int #

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

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

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

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

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

Eq1 Point Source # 
Instance details

Defined in NumHask.Space.Point

Methods

liftEq :: (a -> b -> Bool) -> Point a -> Point b -> Bool #

Traversable Point Source # 
Instance details

Defined in NumHask.Space.Point

Methods

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

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

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

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

Applicative Point Source # 
Instance details

Defined in NumHask.Space.Point

Methods

pure :: a -> Point a #

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

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

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

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

Functor Point Source # 
Instance details

Defined in NumHask.Space.Point

Methods

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

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

Monad Point Source # 
Instance details

Defined in NumHask.Space.Point

Methods

(>>=) :: Point a -> (a -> Point b) -> Point b #

(>>) :: Point a -> Point b -> Point b #

return :: a -> Point a #

Distributive Point Source # 
Instance details

Defined in NumHask.Space.Point

Methods

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

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

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

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

Monoid a => Monoid (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Methods

mempty :: Point a #

mappend :: Point a -> Point a -> Point a #

mconcat :: [Point a] -> Point a #

Semigroup a => Semigroup (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Methods

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

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

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

Bounded a => Bounded (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Methods

minBound :: Point a #

maxBound :: Point a #

Generic (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Associated Types

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

Methods

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

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

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

Defined in NumHask.Space.Point

Methods

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

show :: Point a -> String #

showList :: [Point a] -> ShowS #

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

Defined in NumHask.Space.Point

Methods

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

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

Additive a => AdditiveAction (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Associated Types

type AdditiveScalar (Point a) #

Methods

(|+) :: Point a -> AdditiveScalar (Point a) -> Point a #

Divisive a => DivisiveAction (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Methods

(|/) :: Point a -> Scalar (Point a) -> Point a #

Multiplicative a => MultiplicativeAction (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Associated Types

type Scalar (Point a) #

Methods

(|*) :: Point a -> Scalar (Point a) -> Point a #

Subtractive a => SubtractiveAction (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Methods

(|-) :: Point a -> AdditiveScalar (Point a) -> Point a #

Additive a => Additive (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Methods

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

zero :: Point a #

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

Defined in NumHask.Space.Point

Methods

negate :: Point a -> Point a #

(-) :: Point a -> Point a -> Point a #

Ord a => JoinSemiLattice (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Methods

(\/) :: Point a -> Point a -> Point a #

Ord a => MeetSemiLattice (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Methods

(/\) :: Point a -> Point a -> Point a #

(ExpField a, Eq a) => Basis (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Associated Types

type Mag (Point a) #

type Base (Point a) #

Methods

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

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

TrigField a => Direction (Point a) Source #

angle formed by a vector from the origin to a Point and the x-axis (Point 1 0). Note that an angle between two points p1 & p2 is thus angle p2 - angle p1

Instance details

Defined in NumHask.Space.Point

Associated Types

type Dir (Point a) #

Methods

angle :: Point a -> Dir (Point a) #

ray :: Dir (Point a) -> Point a #

Divisive a => Divisive (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Methods

recip :: Point a -> Point a #

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

Multiplicative a => Multiplicative (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Methods

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

one :: Point a #

UniformRange a => UniformRange (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

Methods

uniformRM :: StatefulGen g m => (Point a, Point a) -> g -> m (Point a) #

(Multiplicative a, Additive a) => Affinity (Point a) a Source # 
Instance details

Defined in NumHask.Space.Point

Methods

transform :: Transform a -> Point a -> Point a Source #

type Rep Point Source # 
Instance details

Defined in NumHask.Space.Point

type Rep Point = Bool
type Rep (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

type Rep (Point a) = D1 ('MetaData "Point" "NumHask.Space.Point" "numhask-space-0.11.1.0-CGZkWl1dCI0Hh4RFyxzImX" 'False) (C1 ('MetaCons "Point" 'PrefixI 'True) (S1 ('MetaSel ('Just "_x") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "_y") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))
type AdditiveScalar (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

type AdditiveScalar (Point a) = a
type Scalar (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

type Scalar (Point a) = a
type Base (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

type Base (Point a) = Point a
type Dir (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

type Dir (Point a) = a
type Mag (Point a) Source # 
Instance details

Defined in NumHask.Space.Point

type Mag (Point a) = a

rotateP :: TrigField a => a -> Point a -> Point a Source #

rotate a point by x relative to the origin

>>> rotateP (pi/2) (Point 1 0)
Point 6.123233995736766e-17 1.0

gridP :: FieldSpace (Range a) => (a -> a) -> Range a -> Grid (Range a) -> [Point a] Source #

Create Points for a formulae y = f(x) across an x range

>>> gridP (^^2) (Range 0 4) 4
[Point 0.0 0.0,Point 1.0 1.0,Point 2.0 4.0,Point 3.0 9.0,Point 4.0 16.0]

dotP :: (Multiplicative a, Additive a) => Point a -> Point a -> a Source #

dot product

(<.>) :: (Multiplicative a, Additive a) => Point a -> Point a -> a infix 4 Source #

dot product operator

crossP :: (Multiplicative a, Subtractive a) => Point a -> Point a -> a Source #

cross product

flipY :: Subtractive a => Point a -> Point a Source #

reflect on x-axis

data Line a Source #

A line is a composed of 2 Points

Constructors

Line 

Fields

Instances

Instances details
Foldable Line Source # 
Instance details

Defined in NumHask.Space.Point

Methods

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

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

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

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

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

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

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

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

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

toList :: Line a -> [a] #

null :: Line a -> Bool #

length :: Line a -> Int #

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

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

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

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

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

Traversable Line Source # 
Instance details

Defined in NumHask.Space.Point

Methods

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

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

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

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

Functor Line Source # 
Instance details

Defined in NumHask.Space.Point

Methods

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

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

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

Defined in NumHask.Space.Point

Methods

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

show :: Line a -> String #

showList :: [Line a] -> ShowS #

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

Defined in NumHask.Space.Point

Methods

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

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

(Multiplicative a, Additive a) => Affinity (Line a) a Source # 
Instance details

Defined in NumHask.Space.Point

Methods

transform :: Transform a -> Line a -> Line a Source #

lineSolve :: (ExpField a, Eq a) => Line a -> (a, a, a) Source #

Return the parameters (a, b, c) for the line equation a*x + b*y + c = 0.

lineDistance :: ExpField a => Line a -> Point a -> a Source #

Return the signed distance from a point to the line. If the distance is negative, the point lies to the right of the line

closestPoint :: Field a => Line a -> Point a -> Point a Source #

Return the point on the line closest to the given point.

lineIntersect :: (Ord a, Epsilon a, Absolute a, Field a) => Line a -> Line a -> Maybe (Point a) Source #

Calculate the intersection of two lines. If the determinant is less than tolerance (parallel or coincident lines), return Nothing.

scaleT :: TrigField a => Point a -> Transform a Source #

scale an Affinity by a Point

skew :: TrigField a => Point a -> Transform a Source #

Skew transform

x-axis skew

skew (Point x 0)