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

Copyright(c) 2014 diagrams-lib team (see LICENSE)
LicenseBSD-style (see LICENSE)
Maintainerdiagrams-discuss@googlegroups.com
Safe HaskellNone
LanguageHaskell2010

Diagrams.Size

Contents

Description

Utilities for working with sizes of objects.

Synopsis

Size spec

data SizeSpec v n Source

A SizeSpec is a way of specifying a size without needed lengths for all the dimensions.

Instances

Functor v => Functor (SizeSpec v) 
Show (v n) => Show (SizeSpec v n) 
Generic (SizeSpec v n) 
Hashable (v n) => Hashable (SizeSpec v n) 
Typeable ((* -> *) -> * -> *) SizeSpec 
type Rep (SizeSpec v n) 
type V (SizeSpec v n) = v 
type N (SizeSpec v n) = n 

Making size spec

mkSizeSpec :: (Functor v, Num n) => v (Maybe n) -> SizeSpec v n Source

Make a SizeSpec from a vector of maybe values. Any negative values will be ignored. For 2D SizeSpecs see mkWidth and mkHeight from Diagrams.TwoD.Size.

dims :: Functor v => v n -> SizeSpec v n Source

Make a SizeSpec from a vector. Any negative values will be ignored.

absolute :: (Additive v, Num n) => SizeSpec v n Source

A size spec with no hints to the size.

Extracting size specs

getSpec :: (Functor v, Num n, Ord n) => SizeSpec v n -> v (Maybe n) Source

Retrieve a size spec as a vector of maybe values. Only positive sizes are returned.

specToSize :: (Foldable v, Functor v, Num n, Ord n) => n -> SizeSpec v n -> v n Source

specToSize n spec extracts a size from a SizeSpec sz. Any values not specified in the spec are replaced by the smallest of the values that are specified. If there are no specified values (i.e. absolute) then n is used.

Functions on size specs

requiredScale :: (Additive v, Foldable v, Fractional n, Ord n) => SizeSpec v n -> v n -> n Source

requiredScale spec sz returns the largest scaling factor to make something of size sz fit the requested size spec without changing the aspect ratio. sz should be non-zero (otherwise a scale of 1 is returned). For non-uniform scaling see boxFit.

requiredScaling :: (Additive v, Foldable v, Fractional n, Ord n) => SizeSpec v n -> v n -> Transformation v n Source

Return the Transformation calcuated from requiredScale.

sized :: (InSpace v n a, HasLinearMap v, HasBasis v, Transformable a, Enveloped a, Fractional n, Ord n) => SizeSpec v n -> a -> a Source

Uniformly scale any enveloped object so that it fits within the given size. For non-uniform scaling see boxFit.

sizedAs :: (InSpace v n a, SameSpace a b, HasLinearMap v, HasBasis v, Transformable a, Enveloped a, Enveloped b, Fractional n, Ord n) => b -> a -> a Source

Uniformly scale an enveloped object so that it "has the same size as" (fits within the width and height of) some other object.

sizeAdjustment :: (Additive v, Foldable v, OrderedField n) => SizeSpec v n -> BoundingBox v n -> (v n, Transformation v n) Source

Get the adjustment to fit a BoundingBox in the given SizeSpec. The vector is the new size and the transformation to position the lower corner at the origin and scale to the size spec.