Struct Polyline2View
Non-owning read-only view of an ordered sequence of 2D points.
struct Polyline2View(T)
if (isGeoScalar!T);
Supported scalar types are int, long, float, double, and real.
Polyline2View is an empty view.
Polyline2View does not allocate or copy point data. The caller retains ownership of the backing storage, which must remain valid for the lifetime of the view.
The view aliases its backing storage. Changes made to mutable backing storage through its owner remain visible through an existing view. Mutation is not exposed through Polyline2View itself.
Empty and singleton polylines are valid.
Constructors
| Name | Description |
|---|---|
this
(points)
|
Constructs a view over contiguous point storage. |
Properties
| Name | Type | Description |
|---|---|---|
empty[get]
|
bool | True when the view contains no points. |
length[get]
|
size_t | Number of stored points. |
segmentCount[get]
|
size_t | Number of consecutive line segments represented by the view. |
Methods
| Name | Description |
|---|---|
opIndex
(index)
|
Returns one point by value. |
segment
(index)
|
Returns the segment beginning at point index. |
Example
Example borrowing caller-owned point storage as a polyline.
import geo;
alias P = Point2!double;
alias S = Segment2!double;
alias V = Polyline2View!double;
P[3] points = [
P(0.0, 0.0),
P(2.0, 1.0),
P(5.0, 1.0)
];
auto polyline =
V(points[]);
assert(!polyline .empty);
assert(polyline .length == 3);
assert(polyline .segmentCount == 2);
assert(
polyline[1] ==
P(2.0, 1.0)
);
assert(
polyline .segment(1) ==
S(
P(2.0, 1.0),
P(5.0, 1.0)
)
);
/*
* The view aliases rather than copies caller-owned storage.
*/
points[1] =
P(3.0, 2.0);
assert(
polyline[1] ==
P(3.0, 2.0)
);