Portability | GHC with TypeFamilies and more |
---|---|
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 themselves and bounding boxes.
WARNING - this module is no so tightly designed, with some of the functions seeming superfluous in hindsight. It is likely to change in the future.
- data BoundingBox u = BBox {}
- type DBoundingBox = BoundingBox Double
- class Boundary a where
- boundary :: DUnit a ~ u => a -> BoundingBox u
- bbox :: Ord u => Point2 u -> Point2 u -> BoundingBox u
- obbox :: Num u => u -> u -> BoundingBox u
- union :: 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
- corners :: BoundingBox u -> (Point2 u, Point2 u, Point2 u, Point2 u)
- within :: Ord u => Point2 u -> BoundingBox u -> Bool
- boundaryWidth :: Num u => BoundingBox u -> u
- boundaryHeight :: Num u => BoundingBox u -> u
- boundaryBottomLeft :: BoundingBox u -> Point2 u
- boundaryTopRight :: BoundingBox u -> Point2 u
- boundaryTopLeft :: BoundingBox u -> Point2 u
- boundaryBottomRight :: BoundingBox u -> Point2 u
- leftPlane :: BoundingBox u -> u
- rightPlane :: BoundingBox u -> u
- lowerPlane :: BoundingBox u -> u
- upperPlane :: 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 is an instance
of the Semigroup class where append
is the union operation.
Eq u => Eq (BoundingBox u) | |
Show u => Show (BoundingBox u) | |
Ord u => Semigroup (BoundingBox u) | |
Pretty u => Pretty (BoundingBox u) | |
Pointwise (BoundingBox u) | |
(Num u, Ord u) => Scale (BoundingBox u) |
type DBoundingBox = BoundingBox DoubleSource
Type class
Type class extracting the bounding box of an object - Picture, Path etc.
boundary :: DUnit a ~ u => a -> BoundingBox uSource
Operations
bbox :: Ord u => Point2 u -> Point2 u -> BoundingBox uSource
Contruct a bounding box, vis the BBox constructor with range checking on the corner points.
bbox
throws an error if the width or height of the
constructed bounding box is negative.
obbox :: Num u => u -> u -> BoundingBox uSource
Create a BoundingBox with bottom left corner at the origin,
and dimensions w
and h
.
union :: Ord u => BoundingBox u -> BoundingBox u -> BoundingBox uSource
The union of two bounding boxes. This is also the append
of BoundingBox's Semigroup
instance.
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.
corners :: BoundingBox u -> (Point2 u, Point2 u, Point2 u, Point2 u)Source
Generate all the corners of a bounding box, counter-clock
wise from the bottom left, i.e. (bl, br, tr, tl)
.
within :: 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.
boundaryBottomLeft :: BoundingBox u -> Point2 uSource
Extract the bottom-left corner of the bounding box.
boundaryTopRight :: BoundingBox u -> Point2 uSource
Extract the top-right corner of the bounding box.
boundaryTopLeft :: BoundingBox u -> Point2 uSource
Extract the top-left corner of the bounding box.
boundaryBottomRight :: BoundingBox u -> Point2 uSource
Extract the bottom-right corner of the bounding box.
leftPlane :: BoundingBox u -> uSource
Extract the unit of the left vertical plane.
rightPlane :: BoundingBox u -> uSource
Extract the unit of the right vertical plane.
lowerPlane :: BoundingBox u -> uSource
Extract the unit of the lower horizontal plane.
upperPlane :: BoundingBox u -> uSource
Extract the unit of the upper horizontal plane.