Struct Bounds2
A closed axis-aligned bounds in a two-dimensional Euclidean space.
struct Bounds2(T)
if (isGeoScalar!T);
Supported scalar types are int, long, float, double, and real.
Bounds2 is empty.
Bounds2 has two semantic states:
- empty: contains no point; - non-empty: min <= max component-wise.
A degenerate bounds with min == max is non-empty.
Floating-point non-empty bounds may contain infinities but never NaN.
All public Bounds2 value operations perform no allocation and run in O(1) time with O(1) auxiliary space.
Properties
| Name | Type | Description |
|---|---|---|
empty[get]
|
bool | True when this bounds contains no point. |
isFinite[get]
|
bool | True when all represented coordinates are finite. |
max[get]
|
Point2!T | Maximum corner. |
min[get]
|
Point2!T | Minimum corner. |
Methods
| Name | Description |
|---|---|
contains
(p)
|
True when this closed bounds contains p. |
extend
(other)
|
Extends this bounds so that it contains other. |
intersects
(other)
|
True when this closed bounds intersects other. |
opEquals
(rhs)
|
Exact bounds equality. |
tryExtend
(p)
|
Extends this bounds so that it contains p. |
tryFromMinMax
(minimum, maximum, result)
|
Constructs a non-empty bounds from minimum and maximum corners. |
tryFromPoint
(p, result)
|
Constructs a degenerate non-empty bounds containing exactly p. |
Example
Example using the core Bounds2 value operations.
import geo;
alias P = Point2!int;
alias B = Bounds2!int;
assert(B .init .empty);
assert(B .init .isFinite);
B first;
assert(
B .tryFromPoint(
P(3, 4),
first
)
);
assert(!first .empty);
assert(first .min == P(3, 4));
assert(first .max == P(3, 4));
assert(first .isFinite);
B second;
assert(
B .tryFromPoint(
P(-2, 8),
second
)
);
first .extend(second);
assert(first .min == P(-2, 4));
assert(first .max == P(3, 8));
const copy = first;
assert(copy == first);