Portability | GHC |
---|---|

Stability | unstable |

Maintainer | stephen.tetley@gmail.com |

Bounding box with no notion of 'empty'.

Empty pictures cannot be created with Wumpus. This greatly simplifies the implementation of pictures and bounding boxes.

Note - some of the functions exposed by this module are expected to be pertinent only to Wumpus-Core itself.

- data BoundingBox u = BBox {}
- type DBoundingBox = BoundingBox Double
- class Boundary t where
- boundary :: u ~ DUnit t => t -> BoundingBox u

- boundingBox :: Ord u => Point2 u -> Point2 u -> BoundingBox u
- oboundingBox :: (Num u, Ord u) => u -> u -> BoundingBox u
- destBoundingBox :: BoundingBox u -> (u, u, u, u)
- boundaryUnion :: Ord u => BoundingBox u -> BoundingBox u -> BoundingBox u
- traceBoundary :: (Num u, Ord u) => [Point2 u] -> BoundingBox u
- retraceBoundary :: (Num u, Ord u) => (Point2 u -> Point2 u) -> BoundingBox u -> BoundingBox u
- boundaryCorners :: BoundingBox u -> (Point2 u, Point2 u, Point2 u, Point2 u)
- boundaryCornerList :: BoundingBox u -> [Point2 u]
- withinBoundary :: Ord u => Point2 u -> BoundingBox u -> Bool
- boundaryWidth :: Num u => BoundingBox u -> u
- boundaryHeight :: Num u => BoundingBox u -> u

# Types

data BoundingBox u Source

Bounding box of a picture, represented by the lower left and upper right corners.

We cannot construct empty pictures - so bounding boxes are
spared the obligation to be *empty*.

BoundingBox operates as a semigroup where `boundaryUnion`

is the
addition.

Eq u => Eq (BoundingBox u) | |

Show u => Show (BoundingBox u) | |

PSUnit u => Format (BoundingBox u) | |

(Num u, Ord u) => Translate (BoundingBox u) | |

(Num u, Ord u) => Scale (BoundingBox u) | |

(Real u, Floating u) => RotateAbout (BoundingBox u) | |

(Real u, Floating u) => Rotate (BoundingBox u) | |

(Num u, Ord u) => Transform (BoundingBox u) |

type DBoundingBox = BoundingBox DoubleSource

# Type class

Type class extracting the bounding box of an object - Picture, Path etc.

boundary :: u ~ DUnit t => t -> BoundingBox uSource

# Constructors

boundingBox :: Ord u => Point2 u -> Point2 u -> BoundingBox uSource

`boundingBox`

: `lower_left_corner * upper_right_corner -> BoundingBox`

Contruct a bounding box, vis the BBox constructor with range checking on the corner points.

`boundingBox`

throws an error if the width or height of the
constructed bounding box is negative.

oboundingBox :: (Num u, Ord u) => u -> u -> BoundingBox uSource

`oboundingBbox`

: `width * height -> BoundingBox`

Create a BoundingBox with bottom left corner at the origin,
and dimensions `w`

and `h`

.

`oboundingBox`

throws an error if either the suppplied width
or height is negative.

# Operations

destBoundingBox :: BoundingBox u -> (u, u, u, u)Source

`destBoundingBox`

: ```
bbox -> (lower_left_x, lower_lefy_y,
upper_right_x, upper_right_y)
```

Destructor for BoundingBox, assembles a four-tuple of the x and y values of the corner points.

Arguably this is easier to pattern match upon, as it removes a layer of nesting.

boundaryUnion :: Ord u => BoundingBox u -> BoundingBox u -> BoundingBox uSource

The union of two bounding boxes.

traceBoundary :: (Num u, Ord u) => [Point2 u] -> BoundingBox uSource

Trace a list of points, retuning the BoundingBox that includes them.

`trace`

throws a run-time error when supplied with the empty
list.

retraceBoundary :: (Num u, Ord u) => (Point2 u -> Point2 u) -> BoundingBox u -> BoundingBox uSource

Perform the supplied transformation on the four corners of the bounding box. Trace the new corners to calculate the resulting bounding box.

This helper function can be used to re-calculate a bounding box after a rotation for example.

boundaryCorners :: BoundingBox u -> (Point2 u, Point2 u, Point2 u, Point2 u)Source

`boundaryCorners`

: ```
bbox -> (bottom_left, bottom_right,
top_right, top_left)
```

Generate all the corners of a bounding box, counter-clock
wise from the bottom left, i.e. `(bl, br, tr, tl)`

.

boundaryCornerList :: BoundingBox u -> [Point2 u]Source

`boundaryCornerList`

: ```
bbox -> [bottom_left, bottom_right,
top_right, top_left]
```

Generate all the corners of a bounding box, counter-clock
wise from the bottom left, i.e. `[bl, br, tr, tl]`

.

This is a list version of `boundaryCorners`

which is sometimes
more convenient. For instance, to create a vertex path it is
more direct to use this list rather than build one from the
4-tuple returned by `boundaryCorners`

.

withinBoundary :: Ord u => Point2 u -> BoundingBox u -> BoolSource

Within test - is the supplied point within the bounding box?

boundaryWidth :: Num u => BoundingBox u -> uSource

Extract the width of a bounding box.

boundaryHeight :: Num u => BoundingBox u -> uSource

Extract the height of a bounding box.