Maths · function
boundsOfBox
Bounds for a box the caller names itself, into bounds the caller owns.
Explained in Coordinates and units.
function boundsOfBox(minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number, out: Bounds): Boundsimport { boundsOfBox } from '@driftengine/core';Parameters
| Parameter | Type | Description |
|---|---|---|
minX | number | |
minY | number | |
minZ | number | |
maxX | number | |
maxY | number | |
maxZ | number | |
out | Bounds |
In depth
boundsOfPositions was the only way to make one of these, and it demands a vertex array.
A consumer that wants to ask the renderer about a region rather than about a mesh — a streamed
world testing its squares, a trigger volume, a room — has no vertices to hand it, so making the
object meant filling centre and radius by hand and getting the sphere's invariant right. A
consumer measured what that costs: with one mesh per material per square, a two-kilometre ring
is 1,618 draws it walks one at a time, where the world itself knows 68 squares it could have
tested instead.
Here the radius is half the diagonal, which is the opposite of what boundsOfPositions
does and is right for the same reason. That function measures the furthest actual vertex,
because a mesh's corners are usually empty; a named box has no vertices and its corners are
exactly the points it promises to contain, so anything tighter would report a region as off
screen while part of it is on.
Degenerate is allowed: a flat square gives a real box and a real radius, and a caller that passes a max below a min gets those values back rather than a silent swap — the box it asked for is the box it gets, and an inverted one is a bug at the call site.