Struct Point2
A position in a two-dimensional Euclidean affine space.
struct Point2(T)
if (isGeoScalar!T);
Supported scalar types are int, long, float, double, and real.
Point2 is the origin (0, 0).
Point2 follows affine point semantics. A point may be translated by
adding or subtracting a vector, and subtracting two points produces the
vector between them. Point-point addition, unary point negation, and
scalar multiplication or division of points are deliberately unavailable.
Equality is exact and component-wise according to the equality semantics
of T; no tolerance or epsilon is applied. Consequently, a floating-point
point containing NaN does not compare equal to itself.
Floating-point coordinates may be non-finite. isFinite reports whether
both coordinates are finite. Integral points are always finite.
Constructors
| Name | Description |
|---|---|
this
(x, y)
|
Constructs a point from its coordinates. |
Properties
| Name | Type | Description |
|---|---|---|
isFinite[get]
|
bool | Returns true when both coordinates are finite. |
x[get]
|
T | X coordinate. |
y[get]
|
T | Y coordinate. |
Methods
| Name | Description |
|---|---|
opBinary
(rhs)
|
Translates this point by a vector. |
opBinary
(rhs)
|
Translates this point by the inverse of a vector. |
opBinary
(rhs)
|
Difference between two points. |
opBinaryRight
(lhs)
|
Supports Vector + Point. |
opOpAssign
(rhs)
|
Compound point translation. |
opOpAssign
(rhs)
|
Compound inverse point translation. |
Example
Example using a point with affine vector translation.
import geo;
alias P = Point2!double;
alias V = Vector2!double;
auto point =
P(1.0, 2.0);
auto shift =
V(3.0, -1.0);
assert(point .x == 1.0);
assert(point .y == 2.0);
assert(point .isFinite);
assert(
point + shift ==
P(4.0, 1.0)
);
assert(
shift + point ==
P(4.0, 1.0)
);
point += shift;
assert(
point ==
P(4.0, 1.0)
);