Portability | GHC |
---|---|

Stability | highly unstable |

Maintainer | stephen.tetley@gmail.com |

Base types for Drawing Objects, Graphics / Images (a Graphic that also returns an answer), etc.

Base classes for monadic drawing.

Notes on prefix and suffix names:

Function types suffixed `F`

are functions from same-to-same, e.g.:

type Point2F u = Point2 u -> Point2 u

Functional types subfixed `R`

are functions from some static
context to the answer type (c.f the ReaderMonad), e.g.:

newtype DrawingR a = DrawingR { getDrawingR :: DrawingContext -> a }

The suffix `M`

is used for classes defining monadic actions.

The prefix `Loc`

indicates a functional type
*from Point2 to something...*

The prefix `ThetaLoc`

indicates a functional type
*from Direction (radian) then Point to something...*

** WARNING ** - some names are expected to change.

- type family MonUnit m :: *
- class Monad m => TraceM m where
- class (Applicative m, Monad m) => DrawingCtxM m where
- askDC :: m DrawingContext
- localize :: (DrawingContext -> DrawingContext) -> m a -> m a

- asksDC :: DrawingCtxM m => (DrawingContext -> a) -> m a
- class Monad m => PointSupplyM m where
- data HPrim u
- hprimToList :: HPrim u -> [PrimElement u]
- singleH :: PrimElement u -> HPrim u
- type Point2F u = Point2 u -> Point2 u
- type DPoint2F = Point2F Double
- data DrawingR a
- type LocDrawingR u a = Point2 u -> DrawingR a
- type DLocDrawingR a = LocDrawingR Double a
- runDrawingR :: DrawingContext -> DrawingR a -> a
- type Graphic u = DrawingR (HPrim u)
- type DGraphic = Graphic Double
- runGraphic :: DrawingContext -> Graphic u -> HPrim u
- xlinkGraphic :: XLink -> Graphic u -> Graphic u
- type LocGraphic u = Point2 u -> Graphic u
- type DLocGraphic = LocGraphic Double
- type Image u a = DrawingR (a, HPrim u)
- type DImage a = Image Double a
- type LocImage u a = Point2 u -> Image u a
- type DLocImage a = LocImage Double a
- runImage :: DrawingContext -> Image u a -> (a, HPrim u)
- intoImage :: DrawingR a -> Graphic u -> Image u a
- intoLocImage :: LocDrawingR u a -> LocGraphic u -> LocImage u a
- xlinkImage :: XLink -> Image u a -> Image u a
- type ConnectorDrawingR u a = Point2 u -> Point2 u -> DrawingR a
- type DConnectorDrawingR a = ConnectorDrawingR Double a
- type ConnectorGraphic u = Point2 u -> Point2 u -> Graphic u
- type DConnectorGraphic = ConnectorGraphic Double
- type ConnectorImage u a = Point2 u -> Point2 u -> Image u a
- type DConnectorImage a = ConnectorImage Double a
- intoConnectorImage :: ConnectorDrawingR u a -> ConnectorGraphic u -> ConnectorImage u a
- type ThetaLocDrawingR u a = Radian -> LocDrawingR u a
- type DThetaLocDrawingR a = ThetaLocDrawingR Double a
- type ThetaLocGraphic u = Radian -> LocGraphic u
- type DThetaLocGraphic = ThetaLocGraphic Double
- type ThetaLocImage u a = Radian -> LocImage u a
- type DThetaLocImage a = ThetaLocImage Double a

# Drawing monads.

type family MonUnit m :: *Source

DUnit is always for fully saturated type constructors, so (seemingly) an equivalent type family is needed for monads.

class Monad m => TraceM m whereSource

Collect elementary graphics as part of a larger drawing.

TraceM works much like a writer monad.

class (Applicative m, Monad m) => DrawingCtxM m whereSource

askDC :: m DrawingContextSource

localize :: (DrawingContext -> DrawingContext) -> m a -> m aSource

DrawingCtxM DrawingR | |

DrawingCtxM m => DrawingCtxM (DirectionT m) | |

DrawingCtxM (Drawing u) | |

Monad m => DrawingCtxM (DrawingT u m) | |

DrawingCtxM m => DrawingCtxM (TurtleT u m) | |

DrawingCtxM m => DrawingCtxM (ScalingT ux uy u m) |

asksDC :: DrawingCtxM m => (DrawingContext -> a) -> m aSource

Project a value out of a context.

class Monad m => PointSupplyM m whereSource

A monad that supplies points, e.g. a turtle monad.

(u ~ MonUnit m, Monad m, Num u) => PointSupplyM (TurtleT u m) |

# Base types

Graphics objects, even simple ones (line, arrow, dot) might
need more than one primitive (path or text label) for their
construction. Hence, the primary representation that all the
others are built upon must support *concatenation* of
primitives.

Wumpus-Core has a type Picture - made from one or more Primitives - but Pictures include support for affine frames. For drawing many simple graphics (dots, connector lines...) that do not need individual affine transformations this is a penalty. A list of Primitives is therefore more suitable representation, and a Hughes list which supports efficient concatenation is wise.

hprimToList :: HPrim u -> [PrimElement u]Source

singleH :: PrimElement u -> HPrim uSource

Drawings in Wumpus-Basic have an implicit *graphics state*
the `DrawingContext`

, the most primitive building block is
a function from the DrawingContext to some polymorphic answer.

This functional type is represented concretely as `DrawingR`

.

DrawingR :: DrawingContext -> a

type LocDrawingR u a = Point2 u -> DrawingR aSource

type DLocDrawingR a = LocDrawingR Double aSource

runDrawingR :: DrawingContext -> DrawingR a -> aSource

Run a *Drawing Function* with the supplied *Drawing Context*.

runGraphic :: DrawingContext -> Graphic u -> HPrim uSource

xlinkGraphic :: XLink -> Graphic u -> Graphic uSource

type LocGraphic u = Point2 u -> Graphic uSource

Commonly graphics take a start point as well as a drawing context.

Here they are called a LocGraphic - graphic with a (starting) location.

type DLocGraphic = LocGraphic DoubleSource

type Image u a = DrawingR (a, HPrim u)Source

Images return a value as well as drawing. A *node* is a
typical example - nodes are drawing but the also support
taking anchor points.

runImage :: DrawingContext -> Image u a -> (a, HPrim u)Source

intoLocImage :: LocDrawingR u a -> LocGraphic u -> LocImage u aSource

xlinkImage :: XLink -> Image u a -> Image u aSource

type ConnectorDrawingR u a = Point2 u -> Point2 u -> DrawingR aSource

type DConnectorDrawingR a = ConnectorDrawingR Double aSource

type ConnectorGraphic u = Point2 u -> Point2 u -> Graphic uSource

ConnectorGraphic is a connector drawn between two points contructing a Graphic.

type ConnectorImage u a = Point2 u -> Point2 u -> Image u aSource

ConImage is a connector drawn between two points constructing an Image.

type DConnectorImage a = ConnectorImage Double aSource

intoConnectorImage :: ConnectorDrawingR u a -> ConnectorGraphic u -> ConnectorImage u aSource

type ThetaLocDrawingR u a = Radian -> LocDrawingR u aSource

type DThetaLocDrawingR a = ThetaLocDrawingR Double aSource

type ThetaLocGraphic u = Radian -> LocGraphic uSource

A function from *Radian -\> Point -\> Graphic*...

type ThetaLocImage u a = Radian -> LocImage u aSource

type DThetaLocImage a = ThetaLocImage Double aSource