plot-light-0.4.3: A lightweight plotting library, exporting to SVG

Safe HaskellSafe
LanguageHaskell2010

Graphics.Rendering.Plot.Light.Internal.Geometry

Contents

Description

This module provides functionality for working with affine transformations (i.e. in the unit square)

Synopsis

Geometry

Point

data Point a #

A Point object defines a point in the plane

Constructors

Point 

Fields

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

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

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

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

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

compare :: Point a -> Point a -> Ordering #

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

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

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

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

max :: Point a -> Point a -> Point a #

min :: Point a -> Point a -> Point a #

Show a => Show (Point a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

show :: Point a -> String #

showList :: [Point a] -> ShowS #

Generic (Point a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Associated Types

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

Methods

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

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

type Rep (Point a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

type Rep (Point a) = D1 (MetaData "Point" "Graphics.Rendering.Plot.Light.Internal.Geometry" "plot-light-0.4.3-KNQxaEmS8qx6K0iBhRdVwd" False) (C1 (MetaCons "Point" PrefixI True) (S1 (MetaSel (Just "_px") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_py") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)))

mkPoint :: a -> a -> Point a #

setPointX :: a -> Point a -> Point a #

setPointY :: a -> Point a -> Point a #

LabeledPoint

data LabeledPoint l a #

A LabeledPoint carries a "label" (i.e. any additional information such as a text tag, or any other data structure), in addition to position information. Data points on a plot are LabeledPoints.

Constructors

LabeledPoint 

Fields

Instances
(Eq a, Eq l) => Eq (LabeledPoint l a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(==) :: LabeledPoint l a -> LabeledPoint l a -> Bool #

(/=) :: LabeledPoint l a -> LabeledPoint l a -> Bool #

(Show a, Show l) => Show (LabeledPoint l a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

labelPoint :: (Point a -> l) -> Point a -> LabeledPoint l a #

Given a labelling function and a Point p, returned a LabeledPoint containing p and the computed label

mapLabel :: (l1 -> l2) -> LabeledPoint l1 a -> LabeledPoint l2 a #

Apply a function to the label

Frame

data Frame a #

A frame, i.e. a bounding box for objects

Constructors

Frame 

Fields

Instances
Eq a => Eq (Frame a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

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

Show a => Show (Frame a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

show :: Frame a -> String #

showList :: [Frame a] -> ShowS #

Generic (Frame a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Associated Types

type Rep (Frame a) :: * -> * #

Methods

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

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

Ord a => Semigroup (Frame a) #

The semigroup operation (mappend) applied on two Frames results in a new Frame that bounds both.

Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

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

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

(Ord a, Num a) => Monoid (Frame a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

mempty :: Frame a #

mappend :: Frame a -> Frame a -> Frame a #

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

type Rep (Frame a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

type Rep (Frame a) = D1 (MetaData "Frame" "Graphics.Rendering.Plot.Light.Internal.Geometry" "plot-light-0.4.3-KNQxaEmS8qx6K0iBhRdVwd" False) (C1 (MetaCons "Frame" PrefixI True) (S1 (MetaSel (Just "_fpmin") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Point a)) :*: S1 (MetaSel (Just "_fpmax") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Point a))))

mkFrame :: Point a -> Point a -> Frame a #

unitFrame :: Num a => Frame a #

The unit square (0, 0) - (1, 1)

frameFromPoints :: (Ord a, Foldable t, Functor t) => t (Point a) -> Frame a #

Create a Frame from a container of Points P, i.e. construct two points p1 and p2 such that :

p1 := inf(x,y) P

p2 := sup(x,y) P

mkFrameOrigin :: Num a => a -> a -> Frame a #

Build a frame rooted at the origin (0, 0)

height :: Num a => Frame a -> a #

The width is the extent in the x direction and height is the extent in the y direction

width :: Num a => Frame a -> a #

The width is the extent in the x direction and height is the extent in the y direction

xmin :: Frame a -> a #

Frame corner coordinates

xmax :: Frame a -> a #

Frame corner coordinates

ymin :: Frame a -> a #

Frame corner coordinates

ymax :: Frame a -> a #

Frame corner coordinates

isPointInFrame :: Ord a => Frame a -> Point a -> Bool #

Axis

data Axis #

Constructors

X 
Y 
Instances
Eq Axis # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(==) :: Axis -> Axis -> Bool #

(/=) :: Axis -> Axis -> Bool #

Show Axis # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

showsPrec :: Int -> Axis -> ShowS #

show :: Axis -> String #

showList :: [Axis] -> ShowS #

Vectors

data V2 a #

V2 is a vector in R^2

Constructors

V2 a a 
Instances
Eq a => Eq (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

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

Show a => Show (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

show :: V2 a -> String #

showList :: [V2 a] -> ShowS #

Num a => Semigroup (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

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

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

Num a => Monoid (V2 a) #

Vectors form a monoid w.r.t. vector addition

Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

mempty :: V2 a #

mappend :: V2 a -> V2 a -> V2 a #

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

Eps (V2 Double) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(~=) :: V2 Double -> V2 Double -> Bool #

Eps (V2 Float) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(~=) :: V2 Float -> V2 Float -> Bool #

Num a => Hermitian (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Associated Types

type InnerProduct (V2 a) :: * #

Methods

(<.>) :: V2 a -> V2 a -> InnerProduct (V2 a) #

Num a => VectorSpace (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Associated Types

type Scalar (V2 a) :: * #

Methods

(.*) :: Scalar (V2 a) -> V2 a -> V2 a #

Num a => AdditiveGroup (V2 a) #

Vectors form an additive group

Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

zero :: V2 a #

(^+^) :: V2 a -> V2 a -> V2 a #

(^-^) :: V2 a -> V2 a -> V2 a #

Fractional a => MatrixGroup (DiagMat2 a) (V2 a) #

Diagonal matrices can always be inverted

Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(<\>) :: DiagMat2 a -> V2 a -> V2 a #

Num a => LinearMap (DiagMat2 a) (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(#>) :: DiagMat2 a -> V2 a -> V2 a #

Num a => LinearMap (Mat2 a) (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(#>) :: Mat2 a -> V2 a -> V2 a #

type InnerProduct (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

type InnerProduct (V2 a) = a
type Scalar (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

type Scalar (V2 a) = a

pointFromV2 :: V2 a -> Point a #

Build a Point p from a V2 v (i.e. assuming v points from the origin (0,0) to p)

Matrices

data Mat2 a #

A Mat2 can be seen as a linear operator that acts on points in the plane

Constructors

Mat2 a a a a 
Instances
Eq a => Eq (Mat2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

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

Show a => Show (Mat2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

show :: Mat2 a -> String #

showList :: [Mat2 a] -> ShowS #

Num a => Semigroup (Mat2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

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

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

Num a => Monoid (Mat2 a) #

Matrices form a monoid w.r.t. matrix multiplication and have the identity matrix as neutral element

Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

mempty :: Mat2 a #

mappend :: Mat2 a -> Mat2 a -> Mat2 a #

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

Num a => MultiplicativeSemigroup (Mat2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(##) :: Mat2 a -> Mat2 a -> Mat2 a #

Num a => LinearMap (Mat2 a) (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(#>) :: Mat2 a -> V2 a -> V2 a #

data DiagMat2 a #

Diagonal matrices in R2 behave as scaling transformations

Constructors

DMat2 a a 
Instances
Eq a => Eq (DiagMat2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

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

Show a => Show (DiagMat2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

show :: DiagMat2 a -> String #

showList :: [DiagMat2 a] -> ShowS #

Num a => Semigroup (DiagMat2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

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

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

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

Num a => Monoid (DiagMat2 a) #

Diagonal matrices form a monoid w.r.t. matrix multiplication and have the identity matrix as neutral element

Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

mempty :: DiagMat2 a #

mappend :: DiagMat2 a -> DiagMat2 a -> DiagMat2 a #

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

Num a => MultiplicativeSemigroup (DiagMat2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(##) :: DiagMat2 a -> DiagMat2 a -> DiagMat2 a #

Fractional a => MatrixGroup (DiagMat2 a) (V2 a) #

Diagonal matrices can always be inverted

Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(<\>) :: DiagMat2 a -> V2 a -> V2 a #

Num a => LinearMap (DiagMat2 a) (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(#>) :: DiagMat2 a -> V2 a -> V2 a #

diagMat2 :: Num a => a -> a -> DiagMat2 a #

Create a diagonal matrix

Primitive elements

origin :: Num a => Point a #

The origin of the axes, point (0, 0)

oneOne :: Num a => Point a #

The (1, 1) point

e1 :: Num a => V2 a #

X-aligned unit vector

e2 :: Num a => V2 a #

Y-aligned unit vector

Vector norm operations

norm2 :: (Hermitian v, Floating n, n ~ InnerProduct v) => v -> n #

Euclidean (L^2) norm

normalize2 :: (InnerProduct v ~ Scalar v, Floating (Scalar v), Hermitian v) => v -> v #

Normalize a V2 w.r.t. its Euclidean norm

Vector construction

v2fromEndpoints :: Num a => Point a -> Point a -> V2 a #

Create a V2 v from two endpoints p1, p2. That is v can be seen as pointing from p1 to p2

v2fromPoint :: Num a => Point a -> V2 a #

Build a V2 v from a Point p (i.e. assuming v points from the origin (0,0) to p)

Operations on points

movePoint :: Num a => V2 a -> Point a -> Point a #

Move a point along a vector

moveLabeledPointV2 :: Num a => V2 a -> LabeledPoint l a -> LabeledPoint l a #

Move a LabeledPoint along a vector

moveLabeledPointBwFrames #

Arguments

:: Fractional a 
=> Frame a

Initial frame

-> Frame a

Final frame

-> Bool

Flip L-R in [0,1] x [0,1]

-> Bool

Flip U-D in [0,1] x [0,1]

-> LabeledPoint l a

Initial LabeledPoint

-> LabeledPoint l a 

(-.) :: Num a => Point a -> Point a -> V2 a #

Create a V2 v from two endpoints p1, p2. That is v can be seen as pointing from p1 to p2

pointRange :: (Fractional a, Integral n) => n -> Point a -> Point a -> [Point a] #

`pointRange n p q` returns a list of equi-spaced Points between p and q.

Operations on vectors

frameToFrame #

Arguments

:: Fractional a 
=> Frame a

Initial frame

-> Frame a

Final frame

-> Bool

Flip L-R in [0,1] x [0,1]

-> Bool

Flip U-D in [0,1] x [0,1]

-> V2 a

Initial vector

-> V2 a 

Given two frames F1 and F2, returns a function f that maps an arbitrary vector v contained within F1 onto one contained within F2.

This function is composed of three affine maps :

  1. map v into a vector v01 that points within the unit square,
  2. map v01 onto v01'. This transformation serves to e.g. flip the dataset along the y axis (since the origin of the SVG canvas is the top-left corner of the screen). If this is not needed one can just supply the identity matrix and the zero vector,
  3. map v01' onto the target frame F2.

NB: we do not check that v is actually contained within the F1, nor that v01' is still contained within [0,1] x [0, 1]. This has to be supplied correctly by the user.

frameToFrameValue #

Arguments

:: Fractional t 
=> Frame t

Initial frame

-> Frame t

Final frame

-> t

Initial value

-> t 

Map function values across frames

Typeclasses

class AdditiveGroup v where #

Additive group :

v ^+^ zero == zero ^+^ v == v
v ^-^ v == zero

Minimal complete definition

zero, (^+^), (^-^)

Methods

zero :: v #

Identity element

(^+^) :: v -> v -> v #

Group action ("sum")

(^-^) :: v -> v -> v #

Inverse group action ("subtraction")

Instances
Num a => AdditiveGroup (V2 a) #

Vectors form an additive group

Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

zero :: V2 a #

(^+^) :: V2 a -> V2 a -> V2 a #

(^-^) :: V2 a -> V2 a -> V2 a #

class AdditiveGroup v => VectorSpace v where #

Vector space : multiplication by a scalar quantity

Minimal complete definition

(.*)

Associated Types

type Scalar v :: * #

Methods

(.*) :: Scalar v -> v -> v #

Scalar multiplication

Instances
Num a => VectorSpace (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Associated Types

type Scalar (V2 a) :: * #

Methods

(.*) :: Scalar (V2 a) -> V2 a -> V2 a #

class VectorSpace v => Hermitian v where #

Hermitian space : inner product

Minimal complete definition

(<.>)

Associated Types

type InnerProduct v :: * #

Methods

(<.>) :: v -> v -> InnerProduct v #

Inner product

Instances
Num a => Hermitian (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Associated Types

type InnerProduct (V2 a) :: * #

Methods

(<.>) :: V2 a -> V2 a -> InnerProduct (V2 a) #

class Hermitian v => LinearMap m v where #

Linear maps, i.e. linear transformations of vectors

Minimal complete definition

(#>)

Methods

(#>) :: m -> v -> v #

Matrix action, i.e. linear transformation of a vector

Instances
Num a => LinearMap (DiagMat2 a) (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(#>) :: DiagMat2 a -> V2 a -> V2 a #

Num a => LinearMap (Mat2 a) (V2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(#>) :: Mat2 a -> V2 a -> V2 a #

class MultiplicativeSemigroup m where #

Multiplicative matrix semigroup ("multiplying" two matrices together)

Minimal complete definition

(##)

Methods

(##) :: m -> m -> m #

Matrix product

Instances
Num a => MultiplicativeSemigroup (DiagMat2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(##) :: DiagMat2 a -> DiagMat2 a -> DiagMat2 a #

Num a => MultiplicativeSemigroup (Mat2 a) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(##) :: Mat2 a -> Mat2 a -> Mat2 a #

class LinearMap m v => MatrixGroup m v where #

The class of invertible linear transformations

Minimal complete definition

(<\>)

Methods

(<\>) :: m -> v -> v #

Inverse matrix action on a vector

Instances
Fractional a => MatrixGroup (DiagMat2 a) (V2 a) #

Diagonal matrices can always be inverted

Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(<\>) :: DiagMat2 a -> V2 a -> V2 a #

class Eps a where #

Numerical equality

Minimal complete definition

(~=)

Methods

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

Comparison within numerical precision

Instances
Eps Double # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(~=) :: Double -> Double -> Bool #

Eps Float # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(~=) :: Float -> Float -> Bool #

Eps (V2 Double) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(~=) :: V2 Double -> V2 Double -> Bool #

Eps (V2 Float) # 
Instance details

Defined in Graphics.Rendering.Plot.Light.Internal.Geometry

Methods

(~=) :: V2 Float -> V2 Float -> Bool #

Utilities

meshGrid #

Arguments

:: (Enum a, RealFrac a) 
=> Frame a 
-> Int

Number of points along x axis

-> Int

" y axis

-> [Point a] 

A list of nx by ny points in the plane arranged on the vertices of a rectangular mesh.

NB: Only the minimum x, y coordinate point is included in the output mesh. This is intentional, since the output from this can be used as an input to functions that use a corner rather than the center point as refernce (e.g. rect)

subdivSegment :: (Real a, Enum b, RealFrac b) => a -> a -> Int -> [b] #

interpolateBilinear :: (Ord p, Fractional p, Show p) => Frame p -> (Point p -> p) -> Point p -> p #

Interpolation

Safe