Copyright | (c) 2011 diagrams-lib team (see LICENSE) |
---|---|
License | BSD-style (see LICENSE) |
Maintainer | diagrams-discuss@googlegroups.com |
Safe Haskell | None |
Language | Haskell2010 |
Bounding boxes are not very compositional (e.g. it is not possible to do anything sensible with them under rotation), so they are not used in the diagrams core. However, they do have their uses; this module provides definitions and functions for working with them.
- data BoundingBox v
- emptyBox :: BoundingBox v
- fromCorners :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => Point v -> Point v -> BoundingBox v
- fromPoint :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => Point v -> BoundingBox v
- fromPoints :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => [Point v] -> BoundingBox v
- boundingBox :: forall a. (Enveloped a, HasBasis (V a), AdditiveGroup (V a), Ord (Basis (V a))) => a -> BoundingBox (V a)
- isEmptyBox :: BoundingBox v -> Bool
- getCorners :: BoundingBox v -> Maybe (Point v, Point v)
- getAllCorners :: (HasBasis v, AdditiveGroup (Scalar v), Ord (Basis v)) => BoundingBox v -> [Point v]
- boxExtents :: AdditiveGroup v => BoundingBox v -> v
- boxTransform :: (AdditiveGroup v, HasLinearMap v, Fractional (Scalar v), AdditiveGroup (Scalar v), Ord (Basis v)) => BoundingBox v -> BoundingBox v -> Maybe (Transformation v)
- boxFit :: (Enveloped a, Transformable a, Monoid a, Ord (Basis (V a))) => BoundingBox (V a) -> a -> a
- contains :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> Point v -> Bool
- contains' :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> Point v -> Bool
- inside :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> Bool
- inside' :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> Bool
- outside :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> Bool
- outside' :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> Bool
- union :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> BoundingBox v
- intersection :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> BoundingBox v
Bounding boxes
data BoundingBox v
A bounding box is an axis-aligned region determined by two points
indicating its "lower" and "upper" corners. It can also represent
an empty bounding box - the points are wrapped in Maybe
.
Eq v => Eq (BoundingBox v) | |
Data v => Data (BoundingBox v) | |
Show v => Show (BoundingBox v) | |
(HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => Semigroup (BoundingBox v) | |
(HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => Monoid (BoundingBox v) | |
(InnerSpace v, HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v), Floating (Scalar v)) => Enveloped (BoundingBox v) | |
(VectorSpace v, HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => HasOrigin (BoundingBox v) | |
Typeable (* -> *) BoundingBox | |
type V (BoundingBox v) = v |
Constructing bounding boxes
emptyBox :: BoundingBox v
An empty bounding box. This is the same thing as mempty
, but it doesn't
require the same type constraints that the Monoid
fromCorners :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => Point v -> Point v -> BoundingBox v
Create a bounding box from a point that is component-wise (<=)
than the
other. If this is not the case, then mempty
is returned.
fromPoint :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => Point v -> BoundingBox v
Create a degenerate bounding "box" containing only a single point.
fromPoints :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => [Point v] -> BoundingBox v
Create the smallest bounding box containing all the given points.
boundingBox :: forall a. (Enveloped a, HasBasis (V a), AdditiveGroup (V a), Ord (Basis (V a))) => a -> BoundingBox (V a)
Create a bounding box for any enveloped object (such as a diagram or path).
Queries on bounding boxes
isEmptyBox :: BoundingBox v -> Bool
Queries whether the BoundingBox is empty.
getCorners :: BoundingBox v -> Maybe (Point v, Point v)
Gets the lower and upper corners that define the bounding box.
getAllCorners :: (HasBasis v, AdditiveGroup (Scalar v), Ord (Basis v)) => BoundingBox v -> [Point v]
Computes all of the corners of the bounding box.
boxExtents :: AdditiveGroup v => BoundingBox v -> v
Get the size of the bounding box - the vector from the (component-wise) lesser point to the greater point.
boxTransform :: (AdditiveGroup v, HasLinearMap v, Fractional (Scalar v), AdditiveGroup (Scalar v), Ord (Basis v)) => BoundingBox v -> BoundingBox v -> Maybe (Transformation v)
Create a transformation mapping points from one bounding box to the other.
boxFit :: (Enveloped a, Transformable a, Monoid a, Ord (Basis (V a))) => BoundingBox (V a) -> a -> a
Transforms an enveloped thing to fit within a BoundingBox
. If it's
empty, then the result is also mempty
.
contains :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> Point v -> Bool
Check whether a point is contained in a bounding box (including its edges).
contains' :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> Point v -> Bool
Check whether a point is strictly contained in a bounding box.
inside :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> Bool
Test whether the first bounding box is contained inside the second.
inside' :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> Bool
Test whether the first bounding box is strictly contained inside the second.
outside :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> Bool
Test whether the first bounding box lies outside the second (although they may intersect in their boundaries).
outside' :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> Bool
Test whether the first bounding box lies strictly outside the second (they do not intersect at all).
Operations on bounding boxes
union :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> BoundingBox v
Form the smallest bounding box containing the given two bound union. This
function is just an alias for mappend
.
intersection :: (HasBasis v, Ord (Basis v), AdditiveGroup (Scalar v), Ord (Scalar v)) => BoundingBox v -> BoundingBox v -> BoundingBox v
Form the largest bounding box contained within this given two
bounding boxes, or Nothing
if the two bounding boxes do not
overlap at all.