tryBounds - multiple declarations
Function tryBounds
Computes the closed axis-aligned bounds of a segment.
Both stored endpoints participate in the result. Endpoint order does not affect the geometric bounds.
A degenerate segment produces a degenerate non-empty bounds.
Returns false when either endpoint contains NaN. Infinity is permitted.
On failure, result is Bounds2!T.
No allocation is performed.
Complexity
time O(1) space O(1)
Function tryBounds
Computes the closed axis-aligned bounds of a polyline.
bool tryBounds(T)(
scope Polyline2View!T polyline,
out Bounds2!T result
) pure nothrow @nogc @safe
if (isGeoScalar!T);
Every stored point participates in the result.
An empty polyline succeeds with Bounds2!T.
A singleton polyline produces a degenerate non-empty bounds.
Returns false when any stored point contains NaN. Infinity is permitted.
Failure is transactional: on failure, result is Bounds2!T.
No allocation is performed.
Complexity for n stored points:
time O(n) space O(1)
Function tryBounds
Computes the closed axis-aligned bounds of a linear ring.
bool tryBounds(T)(
scope LinearRing2View!T ring,
out Bounds2!T result
) pure nothrow @nogc @safe
if (isGeoScalar!T);
Every stored vertex participates in the result. The implicit closing segment requires no separate treatment because both of its endpoints are already stored vertices.
Ring topology is not validated. Empty, degenerate, and topologically invalid rings may still have well-defined bounds.
An empty ring succeeds with Bounds2!T.
Returns false when any stored vertex contains NaN. Infinity is permitted.
Failure is transactional: on failure, result is Bounds2!T.
No allocation is performed.
Complexity for n stored vertices:
time O(n) space O(1)
Function tryBounds
Computes the closed axis-aligned bounds of a polygon representation.
bool tryBounds(T)(
scope Polygon2View!T polygon,
out Bounds2!T result
) pure nothrow @nogc @safe
if (isGeoScalar!T);
Every stored vertex of every stored ring participates in the result, including all interior rings.
Polygon topology is deliberately not validated. In particular, a stored interior ring outside the exterior ring still contributes to the result.
An empty polygon succeeds with Bounds2!T. Empty constituent rings
contribute no points.
Returns false when any stored vertex contains NaN. Infinity is permitted.
Failure is transactional: on failure, result is Bounds2!T.
No allocation is performed.
Complexity for n total stored vertices across all rings:
time O(n) space O(1)
Example
Example computing bounds of a non-owning polyline view.
import geo;
alias P = Point2!int;
P[4] points = [
P(3, 4),
P(-2, 9),
P(8, -5),
P(1, 6)
];
const polyline =
Polyline2View!int(points[]);
Bounds2!int bounds;
assert(
tryBounds(
polyline,
bounds
)
);
assert(bounds .min == P(-2, -5));
assert(bounds .max == P(8, 9));