std/geometry/box
std/geometry/src/box.trb
Box, the axis-aligned box in space: what a bounding volume hierarchy is built out of, and the three-dimensional
half-open shape.
type Box
type Box<Scalar: Numeric = Float>
An axis-aligned box: where it starts, and how big it is.
The minimum face is inside and the maximum face is outside, on all three axes and for every scalar, exactly as
Rectangle decides it in the plane. A stack of boxes therefore tiles space without a cell belonging to two of them.
Examples
const cell = Box Vector3(0, 0, 0), Vector3(8, 8, 8)
print "{cell.contains(Vector3(0, 0, 0))} {cell.contains(Vector3(8, 0, 0))}"
Pitfalls
- A size with a negative or zero component describes no points, and
Box.isEmptysays so.intersectionanswers an empty box rather thanNone, so that a chain of them stays a box.
Related
Rectangle- the same in the plane, where the rule is decided.Sphere- the other bounding volume.
field origin
origin: Vector3<Scalar>
The corner with the smaller coordinates.
field size
size: Vector3<Scalar>
How far the box reaches from its origin, along each axis.
fn between
static fn between(first: Vector3<Scalar>, second: Vector3<Scalar>): Box<Scalar>
The smallest box with those two points as corners. Either point may be either corner.
fn minimum
fn minimum(): Vector3<Scalar>
The corner with the smaller coordinates, which is inside the box.
fn maximum
fn maximum(): Vector3<Scalar>
The corner with the larger coordinates, which is outside the box.
fn isEmpty
fn isEmpty(): Bool
Whether the box describes no points, which is the case as soon as a side is zero or negative.
fn volume
fn volume(): Scalar
How much the box holds: cells for a whole-number scalar, volume for one with fractions.
fn contains
fn contains(point: Vector3<Scalar>): Bool
Whether the point is inside, with the minimum face in and the maximum face out.
fn encloses
fn encloses(other: Box<Scalar>): Bool
Whether the other box is inside this one, faces included. An empty box is inside everything.
fn intersects
fn intersects(other: Box<Scalar>): Bool
Whether the two boxes share at least one point.
fn intersection
fn intersection(other: Box<Scalar>): Box<Scalar>
The box both cover, which is empty where they do not overlap.
fn combined
fn combined(other: Box<Scalar>): Box<Scalar>
The smallest box that covers both. An empty box contributes nothing.
fn covering
fn covering(point: Vector3<Scalar>): Box<Scalar>
The smallest box whose corners hold this one and the point.
Like bounds, it answers the closed hull: the point can come to lie exactly on the maximum face, and
Box.contains then answers false for it.
fn translated
fn translated(by: Vector3<Scalar>): Box<Scalar>
The same box moved.
fn grown
fn grown(by: Vector3<Scalar>): Box<Scalar>
The same box with every side grown by that much on both ends. A negative amount shrinks it.
fn closestPoint
fn closestPoint(to: Vector3<Scalar>): Vector3<Scalar>
The point of the box that is nearest to the one given, which is the point itself where it is inside.
fn bounds
fn bounds(): Box<Scalar>
The box itself: what every shape in space answers, so that one broad phase can hold all of them.
extend Box<Scalar>
extend<Scalar: Signed> Box<Scalar>
What a sign buys: the distance to a point, along the axes.
fn manhattanDistanceTo
fn manhattanDistanceTo(point: Vector3<Scalar>): Scalar
The distance from the point to the nearest point of the box, along the axes. Zero where it is inside.
extend Box<Scalar>
extend<Scalar: Real> Box<Scalar>
What a root and a halving buy: the midpoint and the euclidean distance.
fn centered
static fn centered(at: Vector3<Scalar>, size: Vector3<Scalar>): Box<Scalar>
The box of that size whose midpoint is the point given.
fn center
fn center(): Vector3<Scalar>
The midpoint.
fn distanceTo
fn distanceTo(point: Vector3<Scalar>): Scalar
The distance from the point to the nearest point of the box. Zero where it is inside.
fn distanceSquaredTo
fn distanceSquaredTo(point: Vector3<Scalar>): Scalar
The square of Box.distanceTo, for a comparison that needs no root.