Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- data Box = Box {}
- box_ :: Vec2 -> Box
- degenerate :: Box -> Bool
- move :: Vec2 -> Box -> Box
- resize :: Vec2 -> Box -> Box
- rescale :: Vec2 -> Box -> Box
- newtype TRBL = TRBL Vec4
- type WithTRBL r = Float -> Float -> Float -> Float -> r
- fromTRBL :: WithTRBL Box
- toTRBL :: Box -> TRBL
- withTRBL :: Box -> WithTRBL r -> r
- addPadding :: TRBL -> Box -> Box
- addPaddingRel :: TRBL -> Box -> Box
- addMargins :: TRBL -> Box -> Box
- addMarginsRel :: TRBL -> Box -> Box
- fromCorners :: Vec2 -> Vec2 -> Box
- toCorners :: Box -> (Vec2, Vec2)
- withCorners :: Box -> (Vec2 -> Vec2 -> r) -> r
- projectInto :: Vec2 -> Box -> Vec2
- inside :: Vec2 -> Box -> Bool
- whenInside :: Applicative m => Vec2 -> Box -> (Vec2 -> m ()) -> m ()
- canContain :: Box -> Box -> Bool
- contains :: Box -> Box -> Bool
- union :: Box -> Box -> Box
- intersection :: Box -> Box -> Maybe Box
- intersectionDirty :: Box -> Box -> Box
- intersects :: Box -> Box -> Bool
- leftovers :: Box -> Box -> TRBL
- withLeftovers :: Box -> Box -> WithTRBL r -> r
- mkTransform :: Box -> Transform
- mkTransformZ :: Float -> Box -> Transform
Documentation
2D rectangle with its origin at the center.
Size transformations don't affect its position and vice versa.
┏━━━━━┓ ┃ ┃ ┃ * ┃ ┃ ┃ ┗━━━━━┛
Instances
degenerate :: Box -> Bool Source #
Check if one of the dimensions is negative.
Edge representation
Packed top- right- bottom- left- edge values.
addPaddingRel :: TRBL -> Box -> Box Source #
Construct a smaller Box by adding non-uniform padding as a fraction of Box
size.
addMarginsRel :: TRBL -> Box -> Box Source #
Construct a larger Box by adding non-uniform margins as a fraction of Box
size.
AABB representation
Point-box interaction
whenInside :: Applicative m => Vec2 -> Box -> (Vec2 -> m ()) -> m () Source #
Box-box interaction
intersection :: Box -> Box -> Maybe Box Source #
Get an intersection between two boxes, if there is one.
Use faster intersects
instead if only need a test.
intersectionDirty :: Box -> Box -> Box Source #
Get a potentially-degenerate intersection between two boxes.
intersects :: Box -> Box -> Bool Source #
Box-box intersection test.
Any edge contact counts as intersection.
For area contact use intersection
, which is a little less efficient.
leftovers :: Box -> Box -> TRBL Source #
Remaining space when one box is placed inside another.
All positive when the box is fully inside. Negative edges mean the box is "outside" in that direction.
addPadding (leftovers inner outer) inner === outer addMargins (leftovers inner outer) outer === inner
Conversion
mkTransform :: Box -> Transform Source #
Build a transformation matrix to stretch a unit square and place it at depth 0.0.