Struct Segment2

A line segment between two points in a two-dimensional Euclidean space.

struct Segment2(T)
  
if (isGeoScalar!T);

Supported scalar types are int, long, float, double, and real.

Segment2.init is the degenerate segment from the origin to the origin.

Endpoint order is part of the stored value representation, but does not imply traversal direction. Reversing the endpoints therefore produces a different value unless both endpoints are equal.

Degenerate segments with equal endpoints are valid.

Equality is exact endpoint equality according to the equality semantics of Point2!T; no tolerance or epsilon is applied.

Floating-point endpoints may contain non-finite coordinates. isFinite reports whether both endpoints contain only finite coordinates.

Constructors

NameDescription
this (a, b) Constructs a segment from its endpoints.

Properties

NameTypeDescription
a[get] Point2!TFirst stored endpoint.
b[get] Point2!TSecond stored endpoint.
isFinite[get] boolTrue when both endpoints contain only finite coordinates.

Example

Example constructing and inspecting a segment.

import geo;

alias P = Point2!double;
alias S = Segment2!double;

auto segment =
    S(
        P(1.0, 2.0),
        P(4.0, 6.0)
    );

assert(
    segment.a ==
    P(1.0, 2.0)
);

assert(
    segment.b ==
    P(4.0, 6.0)
);

assert(segment.isFinite);