Maintainer | diagrams-discuss@googlegroups.com |
---|---|

Safe Haskell | None |

Utilities for working with sizes of two-dimensional objects.

- width :: (Enveloped a, V a ~ R2) => a -> Double
- height :: (Enveloped a, V a ~ R2) => a -> Double
- size2D :: (Enveloped a, V a ~ R2) => a -> (Double, Double)
- sizeSpec2D :: (Enveloped a, V a ~ R2) => a -> SizeSpec2D
- extentX :: (Enveloped a, V a ~ R2) => a -> Maybe (Double, Double)
- extentY :: (Enveloped a, V a ~ R2) => a -> Maybe (Double, Double)
- center2D :: (Enveloped a, V a ~ R2) => a -> P2
- data SizeSpec2D
- mkSizeSpec :: Maybe Double -> Maybe Double -> SizeSpec2D
- requiredScaleT :: SizeSpec2D -> (Double, Double) -> Transformation R2
- requiredScale :: SizeSpec2D -> (Double, Double) -> Double
- sized :: (Transformable a, Enveloped a, V a ~ R2) => SizeSpec2D -> a -> a
- sizedAs :: (Transformable a, Enveloped a, V a ~ R2, Enveloped b, V b ~ R2) => b -> a -> a

# Size and extent of diagrams in R2

## Computing sizes

size2D :: (Enveloped a, V a ~ R2) => a -> (Double, Double)Source

Compute the width and height of an enveloped object.

sizeSpec2D :: (Enveloped a, V a ~ R2) => a -> SizeSpec2DSource

Compute the size of an enveloped object as a `SizeSpec2D`

value.

extentX :: (Enveloped a, V a ~ R2) => a -> Maybe (Double, Double)Source

Compute the absolute x-coordinate range of an enveloped object in
R2, in the form (lo,hi). Return `Nothing`

for objects with an
empty envelope.

extentY :: (Enveloped a, V a ~ R2) => a -> Maybe (Double, Double)Source

Compute the absolute y-coordinate range of an enveloped object in R2, in the form (lo,hi).

center2D :: (Enveloped a, V a ~ R2) => a -> P2Source

Compute the point at the center (in the x- and y-directions) of a enveloped object. Return the origin for objects with an empty envelope.

## Specifying sizes

data SizeSpec2D Source

A specification of a (requested) rectangular size.

Width Double | Specify an explicit width. The height should be determined automatically (so as to preserve aspect ratio). |

Height Double | Specify an explicit height. The width should be determined automatically (so as to preserve aspect ratio). |

Dims Double Double | An explicit specification of a width and height. |

Absolute | Absolute size: use whatever size an object already has; do not rescale. |

mkSizeSpec :: Maybe Double -> Maybe Double -> SizeSpec2DSource

Create a size specification from a possibly-specified width and height.

requiredScaleT :: SizeSpec2D -> (Double, Double) -> Transformation R2Source

`requiredScaleT spec sz`

returns a transformation (a uniform scale)
which can be applied to something of size `sz`

to make it fit the
requested size `spec`

, without changing the aspect ratio.

requiredScale :: SizeSpec2D -> (Double, Double) -> DoubleSource

`requiredScale spec sz`

returns a scaling factor necessary to
make something of size `sz`

fit the requested size `spec`

,
without changing the aspect ratio. Hence an explicit
specification of both dimensions may not be honored if the aspect
ratios do not match; in that case the scaling will be as large as
possible so that the object still fits within the requested size.

## Changing the size of things

sized :: (Transformable a, Enveloped a, V a ~ R2) => SizeSpec2D -> a -> aSource

Uniformly scale any enveloped object so that it fits within the given size.