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

Safe Haskell | None |

"Envelopes", aka functional bounding regions. See Diagrams.Core.Envelope for internal implementation details.

- data Envelope v
- class (InnerSpace (V a), OrderedField (Scalar (V a))) => Enveloped a
- envelope :: (OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Monoid' m) => Lens' (QDiagram b v m) (Envelope v)
- setEnvelope :: (OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Monoid' m) => Envelope v -> QDiagram b v m -> QDiagram b v m
- withEnvelope :: (HasLinearMap (V a), Enveloped a, Monoid' m) => a -> QDiagram b (V a) m -> QDiagram b (V a) m
- phantom :: (Backend b (V a), Enveloped a, Traced a, Monoid' m) => a -> QDiagram b (V a) m
- pad :: (Backend b v, InnerSpace v, OrderedField (Scalar v), Monoid' m) => Scalar v -> QDiagram b v m -> QDiagram b v m
- extrudeEnvelope :: (Ord (Scalar v), Num (Scalar v), AdditiveGroup (Scalar v), Floating (Scalar v), HasLinearMap v, InnerSpace v, Monoid' m) => v -> QDiagram b v m -> QDiagram b v m
- intrudeEnvelope :: (Ord (Scalar v), Num (Scalar v), AdditiveGroup (Scalar v), Floating (Scalar v), HasLinearMap v, InnerSpace v, Monoid' m) => v -> QDiagram b v m -> QDiagram b v m
- envelopeVMay :: Enveloped a => V a -> a -> Maybe (V a)
- envelopeV :: Enveloped a => V a -> a -> V a
- envelopePMay :: Enveloped a => V a -> a -> Maybe (Point (V a))
- envelopeP :: Enveloped a => V a -> a -> Point (V a)
- diameter :: Enveloped a => V a -> a -> Scalar (V a)
- radius :: Enveloped a => V a -> a -> Scalar (V a)

# Types

data Envelope v

Every diagram comes equipped with an *envelope*. What is an envelope?

Consider first the idea of a *bounding box*. A bounding box
expresses the distance to a bounding plane in every direction
parallel to an axis. That is, a bounding box can be thought of
as the intersection of a collection of half-planes, two
perpendicular to each axis.

More generally, the intersection of half-planes in *every*
direction would give a tight "bounding region", or convex hull.
However, representing such a thing intensionally would be
impossible; hence bounding boxes are often used as an
approximation.

An envelope is an *extensional* representation of such a
"bounding region". Instead of storing some sort of direct
representation, we store a *function* which takes a direction as
input and gives a distance to a bounding half-plane as output.
The important point is that envelopes can be composed, and
transformed by any affine transformation.

Formally, given a vector `v`

, the envelope computes a scalar `s`

such
that

- for every point
`u`

inside the diagram, if the projection of`(u - origin)`

onto`v`

is`s' *^ v`

, then`s' <= s`

. -
`s`

is the smallest such scalar.

There is also a special "empty envelope".

The idea for envelopes came from
Sebastian Setzer; see
http://byorgey.wordpress.com/2009/10/28/collecting-attributes/#comment-2030. See also Brent Yorgey, *Monoids: Theme and Variations*, published in the 2012 Haskell Symposium: http://www.cis.upenn.edu/~byorgey/pub/monoid-pearl.pdf; video: http://www.youtube.com/watch?v=X-8NCkD2vOw.

Action Name (Envelope v) | |

Show (Envelope v) | |

Ord (Scalar v) => Semigroup (Envelope v) | |

Ord (Scalar v) => Monoid (Envelope v) | |

(InnerSpace v, OrderedField (Scalar v)) => Juxtaposable (Envelope v) | |

(InnerSpace v, OrderedField (Scalar v)) => Enveloped (Envelope v) | |

(HasLinearMap v, InnerSpace v, Floating (Scalar v)) => Transformable (Envelope v) | |

(InnerSpace v, Fractional (Scalar v)) => HasOrigin (Envelope v) | The local origin of an envelope is the point with respect to
which bounding queries are made, |

(InnerSpace v, OrderedField (Scalar v)) => Alignable (Envelope v) | |

(~ * (Scalar v) s, ~ * (Scalar v') s', ~ * s s') => Wrapped (Option (v -> Max s)) (Option (v' -> Max s')) (Envelope v) (Envelope v') | |

Wrapped (DUALTree (DownAnnots v) (UpAnnots b v m) () (QDiaLeaf b v m)) (DUALTree (DownAnnots v') (UpAnnots b' v' m') () (QDiaLeaf b' v' m')) (QDiagram b v m) (QDiagram b' v' m') |

class (InnerSpace (V a), OrderedField (Scalar (V a))) => Enveloped a

`Enveloped`

abstracts over things which have an envelope.

# Diagram envelopes

envelope :: (OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Monoid' m) => Lens' (QDiagram b v m) (Envelope v)

Get the envelope of a diagram.

setEnvelope :: (OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Monoid' m) => Envelope v -> QDiagram b v m -> QDiagram b v m

Replace the envelope of a diagram.

withEnvelope :: (HasLinearMap (V a), Enveloped a, Monoid' m) => a -> QDiagram b (V a) m -> QDiagram b (V a) mSource

Use the envelope from some object as the envelope for a diagram, in place of the diagram's default envelope.

sqNewEnv = circle 1 # fc green ||| ( c # dashing [0.1,0.1] 0 # lc white <> square 2 # withEnvelope (c :: D R2) # fc blue ) c = circle 0.8 withEnvelopeEx = sqNewEnv # centerXY # pad 1.5

phantom :: (Backend b (V a), Enveloped a, Traced a, Monoid' m) => a -> QDiagram b (V a) mSource

`phantom x`

produces a "phantom" diagram, which has the same
envelope and trace as `x`

but produces no output.

pad :: (Backend b v, InnerSpace v, OrderedField (Scalar v), Monoid' m) => Scalar v -> QDiagram b v m -> QDiagram b v mSource

`pad s`

"pads" a diagram, expanding its envelope by a factor of
`s`

(factors between 0 and 1 can be used to shrink the envelope).
Note that the envelope will expand with respect to the local
origin, so if the origin is not centered the padding may appear
"uneven". If this is not desired, the origin can be centered
(using, e.g., `centerXY`

for 2D diagrams) before applying `pad`

.

extrudeEnvelope :: (Ord (Scalar v), Num (Scalar v), AdditiveGroup (Scalar v), Floating (Scalar v), HasLinearMap v, InnerSpace v, Monoid' m) => v -> QDiagram b v m -> QDiagram b v mSource

`extrudeEnvelope v d`

asymmetrically "extrudes" the envelope of
a diagram in the given direction. All parts of the envelope
within 90 degrees of this direction are modified, offset outwards
by the magnitude of the vector.

This works by offsetting the envelope distance proportionally to the cosine of the difference in angle, and leaving it unchanged when this factor is negative.

intrudeEnvelope :: (Ord (Scalar v), Num (Scalar v), AdditiveGroup (Scalar v), Floating (Scalar v), HasLinearMap v, InnerSpace v, Monoid' m) => v -> QDiagram b v m -> QDiagram b v mSource

`intrudeEnvelope v d`

asymmetrically "intrudes" the envelope of
a diagram away from the given direction. All parts of the envelope
within 90 degrees of this direction are modified, offset inwards
by the magnitude of the vector.

Note that this could create strange inverted envelopes, where
` diameter v d < 0 `

.

# Querying envelopes

envelopeVMay :: Enveloped a => V a -> a -> Maybe (V a)

Compute the vector from the local origin to a separating
hyperplane in the given direction, or `Nothing`

for the empty
envelope.

envelopeV :: Enveloped a => V a -> a -> V a

Compute the vector from the local origin to a separating hyperplane in the given direction. Returns the zero vector for the empty envelope.

envelopePMay :: Enveloped a => V a -> a -> Maybe (Point (V a))

Compute the point on a separating hyperplane in the given
direction, or `Nothing`

for the empty envelope.

envelopeP :: Enveloped a => V a -> a -> Point (V a)

Compute the point on a separating hyperplane in the given direction. Returns the origin for the empty envelope.