diagrams-lib-1.2.0.1: Embedded domain-specific language for declarative graphics

Diagrams.Coordinates

Contents

Description

Nice syntax for constructing and pattern-matching on literal points and vectors.

Synopsis

# Documentation

data a :& b infixl 7 Source

A pair of values, with a convenient infix (left-associative) data constructor.

Constructors

 a :& b infixl 7

Instances

 (Eq a, Eq b) => Eq ((:&) a b) (Ord a, Ord b) => Ord ((:&) a b) (Show a, Show b) => Show ((:&) a b)

class Coordinates c where Source

Types which are instances of the `Coordinates` class can be constructed using '^&' (for example, a three-dimensional vector could be constructed by `1 ^& 6 ^& 3`), and deconstructed using `coords`. A common pattern is to use `coords` in conjunction with the `ViewPatterns` extension, like so:

```foo :: Vector3 -> ...
foo (coords -> x :& y :& z) = ...
```

Minimal complete definition

Associated Types

type FinalCoord c :: * Source

The type of the final coordinate.

type PrevDim c :: * Source

The type of everything other than the final coordinate.

type Decomposition c :: * Source

Decomposition of `c` into applications of `:&`.

Methods

(^&) :: PrevDim c -> FinalCoord c -> c infixl 7 Source

Construct a value of type `c` by providing something of one less dimension (which is perhaps itself recursively constructed using `(^&)`) and a final coordinate. For example,

```2 ^& 3 :: P2
3 ^& 5 ^& 6 :: R3
```

Note that `^&` is left-associative.

pr :: PrevDim c -> FinalCoord c -> c Source

Prefix synonym for `^&`. pr stands for pair of `PrevDim`, `FinalCoord`

coords :: c -> Decomposition c Source

Decompose a value of type `c` into its constituent coordinates, stored in a nested `(:&)` structure.

Instances

 Coordinates R2 Coordinates R3 Coordinates v => Coordinates (Point v) Coordinates (a, b) Coordinates (a, b, c) Coordinates (a, b, c, d)

# Lenses for particular axes

class HasX t where Source

The class of types with at least one coordinate, called _x.

Minimal complete definition

Nothing

Methods

Instances

 HasX P2 HasX R2 HasX P3 HasX R3

class HasY t where Source

The class of types with at least two coordinates, the second called _y.

Minimal complete definition

Nothing

Methods

Instances

 HasY P2 HasY R2 HasY P3 HasY R3

class HasZ t where Source

The class of types with at least three coordinates, the third called _z.

Minimal complete definition

Nothing

Methods

Instances

 HasZ P3 HasZ R3

class HasR t where Source

The class of types with a single length coordinate _r. _r is magnitude of a vector, or the distance from the origin of a point.

Minimal complete definition

Nothing

Methods

Instances

 HasR P2 HasR R2 HasR P3 HasR R3