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

Maintainer | diagrams-discuss@googlegroups.com
Safe Haskell | None

Diagrams.TwoD.Types

Contents

- 2D Euclidean space
- Angles

Description

Basic types for two-dimensional Euclidean space.

Synopsis

- data R2
- r2 :: (Double, Double) -> R2
- unr2 :: R2 -> (Double, Double)
- type P2 = Point R2
- p2 :: (Double, Double) -> P2
- unp2 :: P2 -> (Double, Double)
- type T2 = Transformation R2
- class Num a => Angle a where
  - toTurn :: a -> Turn
  - fromTurn :: Turn -> a
- newtype Turn = Turn {
  - getTurn :: Double
  }
- type CircleFrac = Turn
- newtype Rad = Rad {
  - getRad :: Double
  }
- newtype Deg = Deg {
  - getDeg :: Double
  }
- fullCircle :: Angle a => a
- convertAngle :: (Angle a, Angle b) => a -> b

# 2D Euclidean space

data R2 Source

The two-dimensional Euclidean vector space R^2. This type is intentionally abstract.

- To construct a vector, use `r2`, or `&` (from Diagrams.Coordinates):

     r2 (3,4) :: R2
     3 & 4    :: R2

Note that Diagrams.Coordinates is not re-exported by Diagrams.Prelude and must be explicitly imported.

- To construct the vector from the origin to a point `p`, use `p `.-.` `origin``.
- To convert a vector `v` into the point obtained by following `v` from the origin, use ``origin` `.+^` v`.
- To convert a vector back into a pair of components, use `unv2` or `coords` (from Diagrams.Coordinates). These are typically used in conjunction with the `ViewPatterns` extension:

     foo (unr2 -> (x,y)) = ...
     foo (coords -> x :& y) = ...

Instances

Eq R2 |
Fractional R2 |
Num R2 |
Ord R2 |
Read R2 |
Show R2 |
Typeable R2 |
Transformable R2 |
HasBasis R2 |
VectorSpace R2 |
InnerSpace R2 |
AdditiveGroup R2 |
Coordinates R2 |
Newtype R2 (Double, Double) |
Traced (FixedSegment R2) |
Traced (Trail R2) |
Traced (Path R2) |
Traced (Segment Closed R2) |
Renderable (Path R2) b => TrailLike (QDiagram b R2 Any) |

r2 :: (Double, Double) -> R2 Source

Construct a 2D vector from a pair of components. See also `&`.

unr2 :: R2 -> (Double, Double)Source

Convert a 2D vector back into a pair of components. See also `coords`.

type P2 = Point R2 Source

Points in R^2. This type is intentionally abstract.

- To construct a point, use `p2`, or `&` (see Diagrams.Coordinates):

     p2 (3,4)  :: P2
     3 & 4     :: P2

- To construct a point from a vector `v`, use ``origin` `.+^` v`.
- To convert a point `p` into the vector from the origin to `p`, use `p `.-.` `origin``.
- To convert a point back into a pair of coordinates, use `unp2`, or `coords` (from Diagrams.Coordinates). It's common to use these in conjunction with the `ViewPatterns` extension:

     foo (unp2 -> (x,y)) = ...
     foo (coords -> x :& y) = ...

p2 :: (Double, Double) -> P2 Source

Construct a 2D point from a pair of coordinates. See also `&`.

unp2 :: P2 -> (Double, Double)Source

Convert a 2D point back into a pair of coordinates. See also `coords`.

type T2 = Transformation R2 Source

Transformations in R^2.

# Angles

class Num a => Angle a where Source

Type class for types that measure angles.

Methods

toTurn :: a -> Turn Source

Convert to a turn, i.e. a fraction of a circle.

fromTurn :: Turn -> aSource

Convert from a turn, i.e. a fraction of a circle.

Instances

Angle Deg | 360 degrees = 1 full turn.
Angle Rad | tau radians = 1 full turn.
Angle Turn |

newtype Turn Source

Newtype wrapper used to represent angles as fractions of a circle. For example, 1/3 turn = tau/3 radians = 120 degrees.

Constructors

Turn |

Fields

getTurn :: Double

Instances

Enum Turn |
Eq Turn |
Floating Turn |
Fractional Turn |
Num Turn |
Ord Turn |
Read Turn |
Real Turn |
RealFloat Turn |
RealFrac Turn |
Show Turn |
Angle Turn |

type CircleFrac = Turn Source

Deprecated synonym for `Turn`, retained for backwards compatibility.

newtype Rad Source

Newtype wrapper for representing angles in radians.

Constructors

Rad |

Fields

getRad :: Double

Instances

Enum Rad |
Eq Rad |
Floating Rad |
Fractional Rad |
Num Rad |
Ord Rad |
Read Rad |
Real Rad |
RealFloat Rad |
RealFrac Rad |
Show Rad |
Angle Rad | tau radians = 1 full turn.

newtype Deg Source

Newtype wrapper for representing angles in degrees.

Constructors

Deg |

Fields

getDeg :: Double

Instances

Enum Deg |
Eq Deg |
Floating Deg |
Fractional Deg |
Num Deg |
Ord Deg |
Read Deg |
Real Deg |
RealFloat Deg |
RealFrac Deg |
Show Deg |
Angle Deg | 360 degrees = 1 full turn.

fullCircle :: Angle a => aSource

Deprecated synonym for `fullTurn`, retained for backwards compatibility.

convertAngle :: (Angle a, Angle b) => a -> bSource

Convert between two angle representations.