Pangolin
Header-only C++20 plane computational geometry library
Loading...
Searching...
No Matches
pgl::Segment< TPoint, TLabel > Struct Template Reference

Unoriented closed segment between two endpoints plus optional segment label. More...

#include <segment.hpp>

Inheritance diagram for pgl::Segment< TPoint, TLabel >:
[legend]

Public Types

using PointType = TPoint
using NumberType = PointType::NumberType
using LabelType = TLabel

Public Member Functions

constexpr Segment ()=default
 Creates the degenerate segment (0,0)--(0,0).
constexpr Segment (PointType first, PointType second)
 Creates a segment from two endpoints.
constexpr Segment (NumberType x1, NumberType y1, NumberType x2, NumberType y2)
 Creates a segment from four coordinates.
template<class A>
requires (detail::has_label_v<LabelType> && std::constructible_from<LabelType, A&&>)
constexpr Segment (PointType first, PointType second, A &&label)
 Creates a segment from two endpoints and stores a label.
template<class A>
requires (detail::has_label_v<LabelType> && std::constructible_from<LabelType, A&&>)
constexpr Segment (NumberType x1, NumberType y1, NumberType x2, NumberType y2, A &&label)
 Same as the four-coordinate constructor, and stores a label.
template<PointConcept OtherPointType, class OtherLabelType>
requires (std::constructible_from<PointType, const OtherPointType&>)
constexpr Segment (const Segment< OtherPointType, OtherLabelType > &other)
 Converts a segment with a different point and/or label type.
template<PointConcept OtherPointType, class OtherLabelType>
requires (std::constructible_from<PointType, const OtherPointType&>)
constexpr Segmentoperator= (const Segment< OtherPointType, OtherLabelType > &other)
 Assigns from a segment with compatible point and label types.
constexpr const PointTypeoperator[] (std::size_t index) const
 Returns endpoint 0 or 1.
constexpr const PointTypeget (std::ptrdiff_t index) const
 Cyclic access: same as operator[] but index is taken modulo size(); negative indices wrap from the end.
constexpr std::ptrdiff_t index (const PointType &point) const
 Returns the smallest index i with (*this)[i] == point, or -1 if no endpoint equals point.
constexpr const PointTypemin () const
 Returns the smallest stored endpoint.
constexpr const PointTypemax () const
 Returns the largest stored endpoint.
constexpr auto begin () const
 Returns an iterator to the first endpoint.
constexpr auto cbegin () const
 Returns an iterator to the first endpoint.
constexpr auto end () const
 Returns an iterator past the last endpoint.
constexpr auto cend () const
 Returns an iterator past the last endpoint.
constexpr bool operator== (const Segment &other) const
 Compares two segments by their endpoints; the label is ignored.
template<AnyShapeConcept OtherShape>
constexpr bool samePointSet (const OtherShape &other) const
 Tests whether another shape defines exactly the same point set.
constexpr auto operator<=> (const Segment &other) const
 Provides lexicographic ordering on (x1,y1),(x2,y2).
template<class A = LabelType>
requires (detail::has_label_v<A>)
constexpr A & label () const
 Returns the segment label.
constexpr operator Line< PointType > () const
 Converts to the supporting unoriented line.
constexpr Line< PointTypeasLine () const
 Returns the supporting line.
constexpr HalfplaneIntersection< PointTypeasHalfplaneIntersection () const
 Returns the segment as a (degenerate) half-plane intersection.
constexpr Segment rotated90 (int k=1) const
 Returns the segment rotated by 90k degrees around the origin.
constexpr void rotate90 (int k=1)
 Rotates the segment by 90k degrees around the origin in place.
template<class OtherNumber>
constexpr Segment scaledUpX (const OtherNumber scalar) const
 Returns the segment with its x-coordinates multiplied by a factor.
template<class OtherNumber>
constexpr void scaleUpX (const OtherNumber scalar)
 Multiplies the segment's x-coordinates by a factor in place.
template<class OtherNumber>
constexpr Segment scaledUpY (const OtherNumber scalar) const
 Returns the segment with its y-coordinates multiplied by a factor.
template<class OtherNumber>
constexpr void scaleUpY (const OtherNumber scalar)
 Multiplies the segment's y-coordinates by a factor in place.
template<class OtherNumber>
constexpr Segment scaledDownX (const OtherNumber scalar) const
 Returns the segment with its x-coordinates divided by a divisor.
template<class OtherNumber>
constexpr void scaleDownX (const OtherNumber scalar)
 Divides the segment's x-coordinates by a divisor in place.
template<class OtherNumber>
constexpr Segment scaledDownY (const OtherNumber scalar) const
 Returns the segment with its y-coordinates divided by a divisor.
template<class OtherNumber>
constexpr void scaleDownY (const OtherNumber scalar)
 Divides the segment's y-coordinates by a divisor in place.
constexpr bool isDegenerate () const
 Returns whether both endpoints coincide.
constexpr bool isPoint () const
 Returns whether the segment collapses to a single point.
constexpr std::optional< PointTypegetIfPoint () const
 Returns the point the segment collapses to, if it does.
constexpr bool isUndefined () const
 Returns whether the segment is degenerate without collapsing to a point or to a segment.
constexpr bool isVertical () const
 Returns whether the segment is vertical.
constexpr bool isHorizontal () const
 Returns whether the segment is horizontal.
template<class ResultNumber = NumberType>
constexpr ResultNumber area () const
 Returns the area of the segment.
constexpr NumberType twiceArea () const
 Returns twice the area of the segment.
constexpr auto squaredLength () const
 Returns the squared Euclidean length.
template<class ApproximateNumber = double>
ApproximateNumber length () const
 Returns the Euclidean length.
constexpr auto lengthL1 () const
 Returns the Manhattan length.
constexpr auto lengthLInf () const
 Returns the Chebyshev length.
template<PointConcept OtherPoint>
constexpr bool verticesContain (const OtherPoint &point) const
 Returns whether one endpoint equals the given point.
template<PointConcept OtherPoint>
constexpr bool containsEndpoint (const OtherPoint &point) const
 Returns whether the given point is one endpoint.
template<PointConcept OtherPoint>
constexpr bool boundaryContains (const OtherPoint &point) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<SegmentConcept OtherSegment>
constexpr bool boundaryContains (const OtherSegment &other) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<OrientedSegmentConcept OtherOrientedSegment>
constexpr bool boundaryContains (const OtherOrientedSegment &other) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<LineConcept OtherLine>
constexpr bool boundaryContains (const OtherLine &) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<OrientedLineConcept OtherOrientedLine>
constexpr bool boundaryContains (const OtherOrientedLine &) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<RayConcept OtherRay>
constexpr bool boundaryContains (const OtherRay &) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<HalfplaneConcept OtherHalfplane>
constexpr bool boundaryContains (const OtherHalfplane &) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<RectangleConcept OtherRectangle>
constexpr bool boundaryContains (const OtherRectangle &other) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<TriangleConcept OtherTriangle>
constexpr bool boundaryContains (const OtherTriangle &other) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<ConvexConcept OtherConvex>
constexpr bool boundaryContains (const OtherConvex &other) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<PolygonConcept OtherPolygon>
constexpr bool boundaryContains (const OtherPolygon &other) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<DiskConcept OtherDisk>
constexpr bool boundaryContains (const OtherDisk &other) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<PointConcept OtherPoint>
constexpr bool containsCollinear (const OtherPoint &point) const
 Returns whether the segment contains the given point that is collinear with the segment.
template<PointConcept OtherPoint>
constexpr bool contains (const OtherPoint &point) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<SegmentConcept OtherSegment>
constexpr bool contains (const OtherSegment &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<OrientedSegmentConcept OtherOrientedSegment>
constexpr bool contains (const OtherOrientedSegment &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<LineConcept OtherLine>
constexpr bool contains (const OtherLine &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<OrientedLineConcept OtherOrientedLine>
constexpr bool contains (const OtherOrientedLine &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<RayConcept OtherRay>
constexpr bool contains (const OtherRay &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<HalfplaneConcept OtherHalfplane>
constexpr bool contains (const OtherHalfplane &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<RectangleConcept OtherRectangle>
constexpr bool contains (const OtherRectangle &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<TriangleConcept OtherTriangle>
constexpr bool contains (const OtherTriangle &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<ConvexConcept OtherConvex>
constexpr bool contains (const OtherConvex &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<PolygonConcept OtherPolygon>
constexpr bool contains (const OtherPolygon &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<DiskConcept OtherDisk>
constexpr bool contains (const OtherDisk &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<PointConcept OtherPoint>
constexpr bool contains (const Shape< OtherPoint > &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<PointConcept OtherPoint>
constexpr bool boundaryContains (const Shape< OtherPoint > &other) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<class EmptyPoint>
constexpr bool contains (const EmptyShape< EmptyPoint > &) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<class EmptyPoint>
constexpr bool boundaryContains (const EmptyShape< EmptyPoint > &) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<class EmptyPoint>
constexpr bool interiorContains (const EmptyShape< EmptyPoint > &) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<class EmptyPoint>
constexpr bool separates (const EmptyShape< EmptyPoint > &) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<PointConcept OtherPoint>
constexpr bool interiorContains (const OtherPoint &point) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<SegmentConcept OtherSegment>
constexpr bool interiorContains (const OtherSegment &other) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<OrientedSegmentConcept OtherOrientedSegment>
constexpr bool interiorContains (const OtherOrientedSegment &other) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<TriangleConcept OtherTriangle>
constexpr bool interiorContains (const OtherTriangle &other) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<LineConcept OtherLine>
constexpr bool interiorContains (const OtherLine &) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<OrientedLineConcept OtherOrientedLine>
constexpr bool interiorContains (const OtherOrientedLine &) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<RayConcept OtherRay>
constexpr bool interiorContains (const OtherRay &) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<HalfplaneConcept OtherHalfplane>
constexpr bool interiorContains (const OtherHalfplane &) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<RectangleConcept OtherRectangle>
constexpr bool interiorContains (const OtherRectangle &other) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<ConvexConcept OtherConvex>
constexpr bool interiorContains (const OtherConvex &other) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<PolygonConcept OtherPolygon>
constexpr bool interiorContains (const OtherPolygon &other) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<DiskConcept OtherDisk>
constexpr bool interiorContains (const OtherDisk &other) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<PointConcept OtherPoint>
constexpr bool interiorContains (const Shape< OtherPoint > &other) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<PointConcept OtherPoint>
constexpr bool collinear (const OtherPoint &point) const
 Returns whether the given point lies on the supporting line.
template<SegmentConcept OtherSegment>
constexpr bool collinear (const OtherSegment &other) const
 Returns whether another segment lies on the same supporting line.
template<OrientedSegmentConcept OtherOrientedSegment>
constexpr bool collinear (const OtherOrientedSegment &other) const
 Returns whether an oriented segment lies on the same supporting line.
template<LineConcept OtherLine>
constexpr bool collinear (const OtherLine &other) const
 Returns whether a line lies on the same supporting line.
template<OrientedLineConcept OtherOrientedLine>
constexpr bool collinear (const OtherOrientedLine &other) const
 Returns whether an oriented line lies on the same supporting line.
template<RayConcept OtherRay>
constexpr bool collinear (const OtherRay &other) const
 Returns whether a ray lies on the same supporting line.
template<class ResultNumber = division_result_t<NumberType>>
constexpr ResultNumber slope () const
 Returns the slope of the segment.
template<SegmentConcept OtherSegment>
constexpr bool parallel (const OtherSegment &other) const
 Returns whether another segment is parallel to this one.
template<OrientedSegmentConcept OtherOrientedSegment>
constexpr bool parallel (const OtherOrientedSegment &other) const
 Returns whether an oriented segment is parallel to this one.
template<LineConcept OtherLine>
constexpr bool parallel (const OtherLine &other) const
 Returns whether a line is parallel to this segment.
template<OrientedLineConcept OtherOrientedLine>
constexpr bool parallel (const OtherOrientedLine &other) const
 Returns whether an oriented line is parallel to this segment.
template<RayConcept OtherRay>
constexpr bool parallel (const OtherRay &other) const
 Returns whether a ray is parallel to this segment.
template<PointConcept OtherPoint>
constexpr bool intersects (const OtherPoint &other) const
 Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
template<SegmentConcept OtherSegment>
constexpr bool intersects (const OtherSegment &other) const
 Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
constexpr bool intersects (const Shape< PointType > &other) const
 Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
template<typename OtherShape>
requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
constexpr bool intersects (const OtherShape &other) const
 Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
template<class EmptyPoint>
constexpr bool intersects (const EmptyShape< EmptyPoint > &) const
 Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
template<class ResultNumber = NumberType, PointConcept OtherPoint>
constexpr std::optional< Point< ResultNumber, typename PointType::LabelType > > intersection (const OtherPoint &other) const
 Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
template<class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Segment< Point< ResultNumber, typename PointType::LabelType > > > > intersection (const OtherSegment &other) const
 Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires (!PointConcept<OtherShape> && (detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape&
o, const Segment& self) { o.template intersection<ResultNumber>(self); })
constexpr auto intersection (const OtherShape &other) const
 Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
template<class ResultNumber = NumberType, class EmptyPoint>
constexpr EmptyShape< EmptyPoint > intersection (const EmptyShape< EmptyPoint > &) const
 Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
template<class ResultNumber = division_result_t<NumberType>, class OtherNumber>
constexpr std::optional< ResultNumber > yAtX (const OtherNumber &x) const
 Returns the value of the y coordinate for a given x, if it exists.
template<class ResultNumber = division_result_t<NumberType>, class OtherNumber>
constexpr std::optional< ResultNumber > xAtY (const OtherNumber &y) const
 Returns the value of the x coordinate for a given y, if it exists.
template<PointConcept OtherPoint>
constexpr bool separates (const OtherPoint &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<SegmentConcept OtherSegment>
constexpr bool separates (const OtherSegment &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<OrientedSegmentConcept OtherOrientedSegment>
constexpr bool separates (const OtherOrientedSegment &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<LineConcept OtherLine>
constexpr bool separates (const OtherLine &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<OrientedLineConcept OtherOrientedLine>
constexpr bool separates (const OtherOrientedLine &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<RayConcept OtherRay>
constexpr bool separates (const OtherRay &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<RectangleConcept OtherRectangle>
constexpr bool separates (const OtherRectangle &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<TriangleConcept OtherTriangle>
constexpr bool separates (const OtherTriangle &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<HalfplaneConcept OtherHalfplane>
constexpr bool separates (const OtherHalfplane &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<ConvexConcept OtherConvex>
constexpr bool separates (const OtherConvex &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<PolygonConcept OtherPolygon>
constexpr bool separates (const OtherPolygon &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<MonotoneChainConcept OtherChain>
constexpr bool contains (const OtherChain &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<MonotoneChainConcept OtherChain>
constexpr bool boundaryContains (const OtherChain &other) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<MonotoneChainConcept OtherChain>
constexpr bool interiorContains (const OtherChain &other) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<MonotoneChainConcept OtherChain>
constexpr bool separates (const OtherChain &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<PolylineConcept OtherPolyline>
constexpr bool contains (const OtherPolyline &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<PolylineConcept OtherPolyline>
constexpr bool boundaryContains (const OtherPolyline &other) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<PolylineConcept OtherPolyline>
constexpr bool interiorContains (const OtherPolyline &other) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<PolylineConcept OtherPolyline>
constexpr bool separates (const OtherPolyline &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<HalfplaneIntersectionConcept OtherRegion>
constexpr bool contains (const OtherRegion &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<HalfplaneIntersectionConcept OtherRegion>
constexpr bool boundaryContains (const OtherRegion &other) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<HalfplaneIntersectionConcept OtherRegion>
constexpr bool interiorContains (const OtherRegion &other) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<HalfplaneIntersectionConcept OtherRegion>
constexpr bool separates (const OtherRegion &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<PolygonWithHolesConcept OtherRegion>
constexpr bool contains (const OtherRegion &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<PolygonWithHolesConcept OtherRegion>
constexpr bool boundaryContains (const OtherRegion &other) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<PolygonWithHolesConcept OtherRegion>
constexpr bool interiorContains (const OtherRegion &other) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<PolygonWithHolesConcept OtherRegion>
bool separates (const OtherRegion &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<PolygonSetConcept OtherSet>
constexpr bool contains (const OtherSet &other) const
 Tests whether this shape contains the other shape (A ⊇ B).
template<PolygonSetConcept OtherSet>
constexpr bool boundaryContains (const OtherSet &other) const
 Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
template<PolygonSetConcept OtherSet>
constexpr bool interiorContains (const OtherSet &other) const
 Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
template<PolygonSetConcept OtherSet>
bool separates (const OtherSet &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<DiskConcept OtherDisk>
constexpr bool separates (const OtherDisk &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
constexpr bool separates (const Shape< PointType > &other) const
 Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
template<PointConcept OtherPoint>
constexpr bool interiorsIntersect (const OtherPoint &other) const
 Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
template<SegmentConcept OtherSegment>
constexpr bool interiorsIntersect (const OtherSegment &other) const
 Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
template<typename OtherShape>
requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
constexpr bool interiorsIntersect (const OtherShape &other) const
 Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
template<class EmptyPoint>
constexpr bool interiorsIntersect (const EmptyShape< EmptyPoint > &) const
 Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
constexpr bool interiorsIntersect (const Shape< PointType > &other) const
 Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
template<SegmentConcept OtherSegment>
constexpr bool crosses (const OtherSegment &other) const
 Tests whether the two shapes mutually separate each other (each disconnects the other).
template<PointConcept OtherPoint>
constexpr bool crosses (const OtherPoint &other) const
 Tests whether the two shapes mutually separate each other (each disconnects the other).
template<typename OtherShape>
requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
constexpr bool crosses (const OtherShape &other) const
 Tests whether the two shapes mutually separate each other (each disconnects the other).
template<class EmptyPoint>
constexpr bool crosses (const EmptyShape< EmptyPoint > &) const
 Tests whether the two shapes mutually separate each other (each disconnects the other).
constexpr bool crosses (const Shape< PointType > &other) const
 Tests whether the two shapes mutually separate each other (each disconnects the other).
template<class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
constexpr auto squaredDistance (const OtherPoint &point) const
 Returns the squared Euclidean distance to the given shape.
template<class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
constexpr auto squaredDistance (const OtherSegment &other) const
 Returns the squared Euclidean distance to the given shape.
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape& o, const Segment& self)
{ o.template squaredDistance<ResultNumber>(self); })
constexpr auto squaredDistance (const OtherShape &other) const
 Returns the squared Euclidean distance to the given shape.
template<class ResultNumber = double, class DiskPointType, class DiskLabel>
detail::floating_result_t< ResultNumber > squaredDistance (const Disk< DiskPointType, DiskLabel > &disk) const
 Returns the squared Euclidean distance to a disk.
template<class ResultNumber = NumberType, BoundedPolygonalConcept OtherShape>
requires detail::ClosestPairConcept<Segment<TPoint, TLabel>, OtherShape>
constexpr auto closestSegments (const OtherShape &other) const
 Returns the pair of elements realizing the distance, nothing when the shapes meet.
template<class ResultNumber = division_result_t<NumberType>, class OtherShape>
requires detail::ClosestPointsPairConcept<Segment<TPoint, TLabel>, OtherShape>
constexpr auto closestPoints (const OtherShape &other) const
 Returns the pair of points realizing the distance, nothing when the shapes meet.
template<class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
constexpr auto distanceL1 (const OtherPoint &point) const
 Returns the Manhattan (L1) distance to the given shape.
template<class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
constexpr auto distanceL1 (const OtherSegment &other) const
 Returns the Manhattan (L1) distance to the given shape.
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape& o, const Segment& self)
{ o.template distanceL1<ResultNumber>(self); })
constexpr auto distanceL1 (const OtherShape &other) const
 Returns the Manhattan (L1) distance to the given shape.
template<class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
constexpr auto intersection (const Shape< OtherPoint > &other) const
 Returns the intersection of the two shapes (A ∩ B), re-dispatching through the wrapper's own intersection.
template<class ResultNumber = double, PointConcept OtherPoint>
constexpr auto distanceL1 (const Shape< OtherPoint > &other) const
 Returns the distance to the given shape, using symmetry to re-dispatch through the wrapper's own distanceL1.
template<class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
constexpr auto distanceLInf (const OtherPoint &point) const
 Returns the Chebyshev (LInf) distance to the given shape.
template<class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
constexpr auto distanceLInf (const OtherSegment &other) const
 Returns the Chebyshev (LInf) distance to the given shape.
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape& o, const Segment& self)
{ o.template distanceLInf<ResultNumber>(self); })
constexpr auto distanceLInf (const OtherShape &other) const
 Returns the Chebyshev (LInf) distance to the given shape.
template<class ResultNumber = double, PointConcept OtherPoint>
constexpr auto distanceLInf (const Shape< OtherPoint > &other) const
 Returns the distance to the given shape, using symmetry to re-dispatch through the wrapper's own distanceLInf.
template<class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
constexpr auto hausdorffDistanceL1 (const OtherSegment &other) const
 Returns the Manhattan (L1) Hausdorff distance to the given shape.
template<class ResultNumber = NumberType, PointConcept OtherPoint>
constexpr auto hausdorffDistanceL1 (const OtherPoint &point) const
 Returns the Manhattan (L1) Hausdorff distance to the given shape.
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape& o, const Segment& self)
{ o.template hausdorffDistanceL1<ResultNumber>(self); })
constexpr auto hausdorffDistanceL1 (const OtherShape &other) const
 Returns the Manhattan (L1) Hausdorff distance to the given shape.
template<class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
constexpr auto hausdorffDistanceL1 (const Shape< OtherPoint > &other) const
 Returns the distance to the given shape, using symmetry to re-dispatch through the wrapper's own hausdorffDistanceL1.
template<class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
constexpr auto hausdorffDistanceLInf (const OtherSegment &other) const
 Returns the Chebyshev (LInf) Hausdorff distance to the given shape.
template<class ResultNumber = NumberType, PointConcept OtherPoint>
constexpr auto hausdorffDistanceLInf (const OtherPoint &point) const
 Returns the Chebyshev (LInf) Hausdorff distance to the given shape.
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape& o, const Segment& self)
{ o.template hausdorffDistanceLInf<ResultNumber>(self); })
constexpr auto hausdorffDistanceLInf (const OtherShape &other) const
 Returns the Chebyshev (LInf) Hausdorff distance to the given shape.
template<class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
constexpr auto hausdorffDistanceLInf (const Shape< OtherPoint > &other) const
 Returns the distance to the given shape, using symmetry to re-dispatch through the wrapper's own hausdorffDistanceLInf.
template<class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
constexpr auto squaredHausdorffDistance (const OtherSegment &other) const
 Returns the squared Hausdorff distance to another segment.
template<class ResultNumber = NumberType, PointConcept OtherPoint>
constexpr auto squaredHausdorffDistance (const OtherPoint &point) const
 Returns the squared Hausdorff distance to a point.
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape& o, const Segment& self)
{ o.template squaredHausdorffDistance<ResultNumber>(self); })
constexpr auto squaredHausdorffDistance (const OtherShape &other) const
 Returns the squared Hausdorff distance to the given shape.
constexpr Segment diameter () const
 Returns a segment defining the diameter.
template<class ResultNumber = division_result_t<NumberType>>
constexpr Point< ResultNumber > midpoint () const
 Returns the midpoint of the segment.
template<class ResultNumber = division_result_t<NumberType>>
constexpr Point< ResultNumber > pointInside () const
 Returns a point inside the segment.
template<class OtherShape>
constexpr bool pointInsideInteriorContainedIn (const OtherShape &shape) const
 Tests whether some point in this shape's relative interior lies in the strict interior of shape.
template<class ResultNumber = grid_number_t<typename TPoint::NumberType>>
requires (detail::extended_integral<ResultNumber> || std::same_as<ResultNumber, BigInt>)
std::vector< Point< ResultNumber, typename PointType::LabelType > > latticePoints () const
 Returns the integer points the segment contains.
constexpr Rectangle< PointTypebbox () const
 Returns the bounding box of the segment.
template<std::floating_point ResultNumber = double>
constexpr Rectangle< Point< ResultNumber > > fbox () const
 Returns a bounding box of the segment with floating point coordinates.
constexpr std::array< PointType, 2 > vertices () const
 Returns the two endpoints in canonical order.
constexpr Convex< PointTypeconvexHull () const
 Returns the convex hull of the segment's endpoints.
constexpr std::array< Segment, 1 > edges () const
 Returns the unique boundary edge of the segment.
constexpr std::array< OrientedSegment< PointType >, 1 > orientedEdges () const
 Returns the unique oriented boundary edge in canonical order.
constexpr Polyline< PointTypeasPolyline () const
 Returns the segment as a two-vertex polyline.
template<class OtherShape>
requires MinkowskiSummableConcept<Segment<TPoint, TLabel>, OtherShape>
constexpr auto minkowskiSum (const OtherShape &other) const
 Returns the Minkowski sum of this shape and another (A ⊕ B).
template<class OtherShape>
requires MinkowskiSummableConcept<Segment<TPoint, TLabel>, OtherShape>
constexpr auto minkowskiErosion (const OtherShape &other) const
 Returns the Minkowski erosion of this shape by another (A ⊖ B).
template<class OtherShape>
requires (!MinkowskiSummableConcept<Segment<TPoint, TLabel>, OtherShape> && BoundedPolygonalConcept<OtherShape>)
constexpr auto minkowskiErosion (const OtherShape &other) const
 Returns the Minkowski erosion of this shape by a bounded polygonal one (A ⊖ B).
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires (!MinkowskiSummableConcept<Segment<TPoint, TLabel>, OtherShape> && (detail::shapeRank<OtherShape> > detail::shapeRank
<Segment>) && requires(const OtherShape& o, const Segment& self) { o.template minkowskiSum<ResultNumber>(self); })
auto minkowskiSum (const OtherShape &other) const
 Returns the regularized Minkowski sum of the two shapes (A ⊕ B).
template<PointConcept OtherPoint>
constexpr Segmentoperator+= (const OtherPoint &translation)
 Translates the segment by the given point in place.
template<PointConcept OtherPoint>
constexpr Segmentoperator-= (const OtherPoint &translation)
 Translates the segment by the negation of the given point in place.
template<class Scalar>
requires (!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
constexpr Segmentoperator*= (const Scalar &scalar)
 Scales the segment around the origin by a scalar in place.
template<class Scalar>
requires (!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
constexpr Segmentoperator/= (const Scalar &scalar)
 Divides the segment coordinates by a scalar in place.
template<PointConcept OtherPoint>
constexpr Segment< PointType, LabelType > & operator+= (const OtherPoint &translation)
template<PointConcept OtherPoint>
constexpr Segment< PointType, LabelType > & operator-= (const OtherPoint &translation)
template<class Scalar>
requires (!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
constexpr Segment< PointType, LabelType > & operator*= (const Scalar &scalar)
template<class Scalar>
requires (!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
constexpr Segment< PointType, LabelType > & operator/= (const Scalar &scalar)
template<class OtherNumber>
constexpr Segment< PointType, LabelTypescaledUpX (const OtherNumber scalar) const
template<class OtherNumber>
constexpr Segment< PointType, LabelTypescaledUpY (const OtherNumber scalar) const
template<class OtherNumber>
constexpr Segment< PointType, LabelTypescaledDownX (const OtherNumber scalar) const
template<class OtherNumber>
constexpr Segment< PointType, LabelTypescaledDownY (const OtherNumber scalar) const

Static Public Member Functions

static constexpr std::size_t size ()
 Returns the number of endpoints (always 2).

Detailed Description

template<class TPoint, class TLabel>
struct pgl::Segment< TPoint, TLabel >

Unoriented closed segment between two endpoints plus optional segment label.

Unoriented segment connecting two endpoints.

The endpoints are always sorted. The interior of the segment is the segment excluding the endpoints.

A segment may carry an optional LabelType value, independent of the endpoint point label. The label is metadata: it is ignored by equality, ordering and hashing, but it is copied across conversions and preserved by in-place transformations.

Template Parameters
PointTypeEndpoint point type.
TLabelOptional label type carried with the segment (NoLabel to omit).

Member Typedef Documentation

◆ LabelType

template<class TPoint, class TLabel>
using pgl::Segment< TPoint, TLabel >::LabelType = TLabel

◆ NumberType

template<class TPoint, class TLabel>
using pgl::Segment< TPoint, TLabel >::NumberType = PointType::NumberType

◆ PointType

template<class TPoint, class TLabel>
using pgl::Segment< TPoint, TLabel >::PointType = TPoint

Constructor & Destructor Documentation

◆ Segment() [1/6]

template<class TPoint, class TLabel>
pgl::Segment< TPoint, TLabel >::Segment ( )
constexprdefault

Creates the degenerate segment (0,0)--(0,0).

◆ Segment() [2/6]

template<class TPoint, class TLabel>
pgl::Segment< TPoint, TLabel >::Segment ( PointType first,
PointType second )
inlineconstexpr

Creates a segment from two endpoints.

The stored endpoints are reordered so that min() <= max().

Parameters
firstFirst endpoint.
secondSecond endpoint.

◆ Segment() [3/6]

template<class TPoint, class TLabel>
pgl::Segment< TPoint, TLabel >::Segment ( NumberType x1,
NumberType y1,
NumberType x2,
NumberType y2 )
inlineconstexpr

Creates a segment from four coordinates.

Parameters
x1X coordinate of the first endpoint.
y1Y coordinate of the first endpoint.
x2X coordinate of the second endpoint.
y2Y coordinate of the second endpoint.

◆ Segment() [4/6]

template<class TPoint, class TLabel>
template<class A>
requires (detail::has_label_v<LabelType> && std::constructible_from<LabelType, A&&>)
pgl::Segment< TPoint, TLabel >::Segment ( PointType first,
PointType second,
A && label )
inlineconstexpr

Creates a segment from two endpoints and stores a label.

The stored endpoints are reordered so that min() <= max().

Template Parameters
AType convertible to LabelType.
Parameters
firstFirst endpoint.
secondSecond endpoint.
labelSegment label, forwarded into the stored label.

◆ Segment() [5/6]

template<class TPoint, class TLabel>
template<class A>
requires (detail::has_label_v<LabelType> && std::constructible_from<LabelType, A&&>)
pgl::Segment< TPoint, TLabel >::Segment ( NumberType x1,
NumberType y1,
NumberType x2,
NumberType y2,
A && label )
inlineconstexpr

Same as the four-coordinate constructor, and stores a label.

◆ Segment() [6/6]

template<class TPoint, class TLabel>
template<PointConcept OtherPointType, class OtherLabelType>
requires (std::constructible_from<PointType, const OtherPointType&>)
pgl::Segment< TPoint, TLabel >::Segment ( const Segment< OtherPointType, OtherLabelType > & other)
inlineconstexpr

Converts a segment with a different point and/or label type.

The endpoints are converted to PointType and re-sorted, and the label is copied when both sides carry one.

Member Function Documentation

◆ area()

template<class PointType, class LabelType>
template<class ResultNumber>
ResultNumber pgl::Segment< PointType, LabelType >::area ( ) const
nodiscardconstexpr

Returns the area of the segment.

A segment is one-dimensional, so its area is always zero.

Template Parameters
ResultNumberResult type (default: NumberType).
Returns
Zero.

◆ asHalfplaneIntersection()

template<class TPoint, class TLabel>
HalfplaneIntersection< PointType > pgl::Segment< TPoint, TLabel >::asHalfplaneIntersection ( ) const
inlinenodiscardconstexpr

Returns the segment as a (degenerate) half-plane intersection.

The region is the segment's supporting-line slab clamped perpendicularly at each endpoint; it has empty interior. A zero-length segment produces the corresponding single-point region.

Returns
Half-plane intersection whose point set is this segment.

◆ asLine()

template<class TPoint, class TLabel>
Line< PointType > pgl::Segment< TPoint, TLabel >::asLine ( ) const
inlinenodiscardconstexpr

Returns the supporting line.

Returns
Line containing the segment.

◆ asPolyline()

template<class TPoint, class TLabel>
Polyline< typename Segment< TPoint, TLabel >::PointType > pgl::Segment< TPoint, TLabel >::asPolyline ( ) const
nodiscardconstexpr

Returns the segment as a two-vertex polyline.

The vertices are min() and max(), already in canonical polyline order. The segment's own label is not carried over.

Returns
Polyline with the segment's two endpoints.

◆ bbox()

template<class PointType, class LabelType>
Rectangle< PointType > pgl::Segment< PointType, LabelType >::bbox ( ) const
nodiscardconstexpr

Returns the bounding box of the segment.

Returns
The minimun rectangle that contains the segment.

◆ begin()

template<class TPoint, class TLabel>
auto pgl::Segment< TPoint, TLabel >::begin ( ) const
inlineconstexpr

Returns an iterator to the first endpoint.

Returns
Pointer to the first endpoint.

◆ boundaryContains() [1/19]

template<class TPoint, class TLabel>
template<class EmptyPoint>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const EmptyShape< EmptyPoint > & ) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [2/19]

template<class TPoint, class TLabel>
template<MonotoneChainConcept OtherChain>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherChain & other) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [3/19]

template<class TPoint, class TLabel>
template<ConvexConcept OtherConvex>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherConvex & other) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [4/19]

template<class TPoint, class TLabel>
template<DiskConcept OtherDisk>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherDisk & other) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [5/19]

template<class TPoint, class TLabel>
template<HalfplaneConcept OtherHalfplane>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherHalfplane & ) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [6/19]

template<class TPoint, class TLabel>
template<LineConcept OtherLine>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherLine & ) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [7/19]

template<class TPoint, class TLabel>
template<OrientedLineConcept OtherOrientedLine>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherOrientedLine & ) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [8/19]

template<class TPoint, class TLabel>
template<OrientedSegmentConcept OtherOrientedSegment>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherOrientedSegment< TPoint, TLabel > & other) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [9/19]

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::boundaryContains ( const OtherPoint & point) const
nodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

For segments, the boundary is exactly the two endpoints.

Template Parameters
OtherPointType of the point.
Parameters
pointPoint to test.
Returns
true if the point is one of the endpoints.

Segment

Segment endpoint, boundary, containment, collinearity, intersection, and topological predicates, including the generic separates / crosses dispatch used against 1D and area targets.

◆ boundaryContains() [10/19]

template<class TPoint, class TLabel>
template<PolygonConcept OtherPolygon>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherPolygon & other) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [11/19]

template<class TPoint, class TLabel>
template<PolylineConcept OtherPolyline>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherPolyline & other) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [12/19]

template<class TPoint, class TLabel>
template<RayConcept OtherRay>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherRay & ) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [13/19]

template<class TPoint, class TLabel>
template<RectangleConcept OtherRectangle>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherRectangle & other) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [14/19]

template<class TPoint, class TLabel>
template<PolygonWithHolesConcept OtherRegion>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherRegion & other) const
nodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

A boundary has no area, so it holds only a region with no area — which is exactly the union of that region's ring edges.

◆ boundaryContains() [15/19]

template<class PointType, class LabelType>
template<PolygonWithHolesConcept OtherRegion>
bool pgl::Segment< PointType, LabelType >::boundaryContains ( const OtherRegion & other) const
nodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [16/19]

template<class TPoint, class TLabel>
template<SegmentConcept OtherSegment>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherSegment< TPoint, TLabel > & other) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

For segments, the boundary is exactly the two endpoints, so this is true iff all vertices of other are endpoints of this segment.

Template Parameters
OtherPointType of the Shape defining points.
Parameters
otherShape to check.
Returns
The result of the shape-specific boundaryContains method.

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [17/19]

template<class TPoint, class TLabel>
template<PolygonSetConcept OtherSet>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherSet & other) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [18/19]

template<class TPoint, class TLabel>
template<TriangleConcept OtherTriangle>
bool pgl::Segment< TPoint, TLabel >::boundaryContains ( const OtherTriangle & other) const
inlinenodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ boundaryContains() [19/19]

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::boundaryContains ( const Shape< OtherPoint > & other) const
nodiscardconstexpr

Tests whether this shape's boundary contains the other shape (∂A ⊇ B).

◆ cbegin()

template<class TPoint, class TLabel>
auto pgl::Segment< TPoint, TLabel >::cbegin ( ) const
inlineconstexpr

Returns an iterator to the first endpoint.

Returns
Pointer to the first endpoint.

◆ cend()

template<class TPoint, class TLabel>
auto pgl::Segment< TPoint, TLabel >::cend ( ) const
inlineconstexpr

Returns an iterator past the last endpoint.

Returns
Pointer past the second endpoint.

◆ closestPoints()

template<class TPoint, class TLabel>
requires detail::ClosestPointsPairConcept<Segment<TPoint, TLabel>, OtherShape>
template<class ResultNumber, class OtherShape>
requires detail::ClosestPointsPairConcept<Segment<TPoint, TLabel>, OtherShape>
auto pgl::Segment< TPoint, TLabel >::closestPoints ( const OtherShape & other) const
nodiscardconstexpr

Returns the pair of points realizing the distance, nothing when the shapes meet.

The first point lies on this shape and the second on other. Empty exactly when squaredDistance is zero. Unlike closestSegments this also takes an unbounded convex other — a line, an oriented line, a ray, a half-plane, a half-plane intersection — which realizes the distance at a point on no edge and at no vertex: there is no element to name there, but there is still a point to give.

Template Parameters
ResultNumberCoordinate type of the returned points (default: division_result_t).
Warning
A point interior to an element comes from a division, so with an integer ResultNumber it truncates. Request a floating-point or pgl::Rational result type for an accurate value.

◆ closestSegments()

template<class TPoint, class TLabel>
requires detail::ClosestPairConcept<Segment<TPoint, TLabel>, OtherShape>
template<class ResultNumber, BoundedPolygonalConcept OtherShape>
requires detail::ClosestPairConcept<Segment<TPoint, TLabel>, OtherShape>
auto pgl::Segment< TPoint, TLabel >::closestSegments ( const OtherShape & other) const
nodiscardconstexpr

Returns the pair of elements realizing the distance, nothing when the shapes meet.

The first element is this shape's, the second is other's; each is one of the shape's edges, degenerate to a vertex where the shape has none. Empty exactly when squaredDistance is zero.

Template Parameters
ResultNumberCoordinate type of the returned segments (default: NumberType).
Warning
other's coordinates and labels are re-expressed in this shape's, so a narrower ResultNumber loses them.

◆ collinear() [1/6]

template<class PointType, class LabelType>
template<LineConcept OtherLine>
bool pgl::Segment< PointType, LabelType >::collinear ( const OtherLine & other) const
nodiscardconstexpr

Returns whether a line lies on the same supporting line.

Returns
true if both defining points of other are collinear with this segment.

◆ collinear() [2/6]

template<class PointType, class LabelType>
template<OrientedLineConcept OtherOrientedLine>
bool pgl::Segment< PointType, LabelType >::collinear ( const OtherOrientedLine & other) const
nodiscardconstexpr

Returns whether an oriented line lies on the same supporting line.

Returns
true if both defining points of other are collinear with this segment.

◆ collinear() [3/6]

template<class PointType, class LabelType>
template<OrientedSegmentConcept OtherOrientedSegment>
bool pgl::Segment< PointType, LabelType >::collinear ( const OtherOrientedSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Returns whether an oriented segment lies on the same supporting line.

Template Parameters
OtherPointType of the other segment endpoints.
Parameters
otherOther oriented segment.
Returns
true if both endpoints of other are collinear with this segment.

◆ collinear() [4/6]

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::collinear ( const OtherPoint & point) const
nodiscardconstexpr

Returns whether the given point lies on the supporting line.

Template Parameters
OtherPointType of the point.
Parameters
pointPoint to test.
Returns
true if the point is collinear with the segment endpoints.

◆ collinear() [5/6]

template<class PointType, class LabelType>
template<RayConcept OtherRay>
bool pgl::Segment< PointType, LabelType >::collinear ( const OtherRay & other) const
nodiscardconstexpr

Returns whether a ray lies on the same supporting line.

Returns
true if both defining points of other are collinear with this segment.

◆ collinear() [6/6]

template<class PointType, class LabelType>
template<SegmentConcept OtherSegment>
bool pgl::Segment< PointType, LabelType >::collinear ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Returns whether another segment lies on the same supporting line.

Template Parameters
OtherPointType of the other segment endpoints. *
Parameters
otherOther segment.
Returns
true if both endpoints of other are collinear with this segment.

◆ contains() [1/19]

template<class TPoint, class TLabel>
template<class EmptyPoint>
bool pgl::Segment< TPoint, TLabel >::contains ( const EmptyShape< EmptyPoint > & ) const
inlinenodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

◆ contains() [2/19]

template<class PointType, class LabelType>
template<MonotoneChainConcept OtherChain>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherChain & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

◆ contains() [3/19]

template<class PointType, class LabelType>
template<ConvexConcept OtherConvex>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherConvex & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

Complexity: O(log n) for a convex polygon with n vertices.

Template Parameters
OtherPointType of the convex polygon defining points.
Parameters
otherConvex polygon to check.
Returns
true if all vertices of other lie on this segment.

◆ contains() [4/19]

template<class PointType, class LabelType>
template<DiskConcept OtherDisk>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherDisk & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

Template Parameters
OtherPointType of the disk boundary points.
OtherLabelLabel type of the disk.
Parameters
otherDisk to check.
Returns
true if all three boundary points of other are equal and the segment contains that point.

◆ contains() [5/19]

template<class PointType, class LabelType>
template<HalfplaneConcept OtherHalfplane>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherHalfplane & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

Template Parameters
OtherPointType of the halfplane defining points.
Parameters
otherHalfplane to check.
Returns
true if the halfplane is degenerate and its unique point lies on this segment.

◆ contains() [6/19]

template<class PointType, class LabelType>
template<LineConcept OtherLine>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherLine & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

Template Parameters
OtherPointType of the line defining points.
Parameters
otherLine to check.
Returns
true if the line is degenerate and its unique point lies on this segment.

◆ contains() [7/19]

template<class PointType, class LabelType>
template<OrientedLineConcept OtherOrientedLine>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherOrientedLine & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

Template Parameters
OtherPointType of the oriented line defining points.
Parameters
otherOriented line to check.
Returns
true if the oriented line is degenerate and its unique point lies on this segment.

◆ contains() [8/19]

template<class PointType, class LabelType>
template<OrientedSegmentConcept OtherOrientedSegment>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherOrientedSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

Template Parameters
OtherPointType of the other segment endpoints.
Parameters
otherOther oriented segment.
Returns
true if both endpoints of other lie on this segment.

◆ contains() [9/19]

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherPoint & point) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

Endpoints are included.

Template Parameters
OtherPointType of the point.
Parameters
pointPoint to test.
Returns
true if the point lies on the segment.

Segment

Segment endpoint, boundary, containment, collinearity, intersection, and topological predicates, including the generic separates / crosses dispatch used against 1D and area targets.

◆ contains() [10/19]

template<class PointType, class LabelType>
template<PolygonConcept OtherPolygon>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherPolygon & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

◆ contains() [11/19]

template<class PointType, class LabelType>
template<PolylineConcept OtherPolyline>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherPolyline & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

◆ contains() [12/19]

template<class PointType, class LabelType>
template<RayConcept OtherRay>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherRay & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

Template Parameters
OtherPointType of the ray defining points.
Parameters
otherRay to check.
Returns
true if the ray is degenerate and its unique point lies on this segment.

◆ contains() [13/19]

template<class PointType, class LabelType>
template<RectangleConcept OtherRectangle>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherRectangle & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

Template Parameters
OtherPointType of the rectangle defining points.
Parameters
otherRectangle to check.
Returns
true if all vertices of other lie on this segment.

◆ contains() [14/19]

template<class TPoint, class TLabel>
template<PolygonWithHolesConcept OtherRegion>
bool pgl::Segment< TPoint, TLabel >::contains ( const OtherRegion & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

A region is contained exactly when its outer polygon is: the region holds the whole outer ring whatever its holes do, and this shape has a connected complement. See implementation/contains.hpp.

◆ contains() [15/19]

template<class PointType, class LabelType>
template<PolygonWithHolesConcept OtherRegion>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherRegion & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

◆ contains() [16/19]

template<class PointType, class LabelType>
template<SegmentConcept OtherSegment>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

Template Parameters
OtherPointType of the other segment endpoints.
Parameters
otherOther segment.
Returns
true if both endpoints of other lie on this segment.

◆ contains() [17/19]

template<class TPoint, class TLabel>
template<PolygonSetConcept OtherSet>
bool pgl::Segment< TPoint, TLabel >::contains ( const OtherSet & other) const
inlinenodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

◆ contains() [18/19]

template<class PointType, class LabelType>
template<TriangleConcept OtherTriangle>
bool pgl::Segment< PointType, LabelType >::contains ( const OtherTriangle & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

Template Parameters
OtherPointType of the triangle defining points.
Parameters
otherTriangle to check.
Returns
true if all vertices of other lie on this segment.

◆ contains() [19/19]

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::contains ( const Shape< OtherPoint > & other) const
nodiscardconstexpr

Tests whether this shape contains the other shape (A ⊇ B).

Template Parameters
OtherPointType of the Shape defining points.
Parameters
otherShape to check.
Returns
The result of the shape-specific contains method.

◆ containsCollinear()

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::containsCollinear ( const OtherPoint & point) const
nodiscardconstexpr

Returns whether the segment contains the given point that is collinear with the segment.

Endpoints are included. Undefined behavior if the point is not collinear with the segment.

Template Parameters
OtherPointType of the point.
Parameters
pointPoint to test.
Returns
true if the point lies on the segment.

◆ containsEndpoint()

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::containsEndpoint ( const OtherPoint & point) const
nodiscardconstexpr

Returns whether the given point is one endpoint.

This is a segment-specific alias for verticesContain.

Template Parameters
OtherPointType of the point.
Parameters
pointPoint to test.
Returns
true if the point equals min() or max().

◆ convexHull()

template<class TPoint, class TLabel>
Convex< PointType > pgl::Segment< TPoint, TLabel >::convexHull ( ) const
inlinenodiscardconstexpr

Returns the convex hull of the segment's endpoints.

Returns
A degenerate two-vertex convex polygon spanning the segment.

◆ crosses() [1/5]

template<class TPoint, class TLabel>
template<class EmptyPoint>
bool pgl::Segment< TPoint, TLabel >::crosses ( const EmptyShape< EmptyPoint > & ) const
inlinenodiscardconstexpr

Tests whether the two shapes mutually separate each other (each disconnects the other).

◆ crosses() [2/5]

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::crosses ( const OtherPoint & other) const
nodiscardconstexpr

Tests whether the two shapes mutually separate each other (each disconnects the other).

◆ crosses() [3/5]

template<class PointType, class LabelType>
template<SegmentConcept OtherSegment>
bool pgl::Segment< PointType, LabelType >::crosses ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Tests whether the two shapes mutually separate each other (each disconnects the other).

Two segments cross if they intersect at a single point that is not an endpoint of either segment. Equivalently, two segments s,t cross if s separates t and t separates s. Performs at most 4 orientation tests.

Template Parameters
OtherNumberCoordinate type of the other segment endpoints.
OtherPoint::LabelTypeLabel type of the other segment endpoints.
Parameters
otherOther segment.
Returns
true if the segments cross through their interiors.

Segment

Segment endpoint, boundary, containment, collinearity, intersection, and topological predicates, including the generic separates / crosses dispatch used against 1D and area targets.

◆ crosses() [4/5]

template<class TPoint, class TLabel>
template<typename OtherShape>
requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
bool pgl::Segment< TPoint, TLabel >::crosses ( const OtherShape & other) const
inlinenodiscardconstexpr

Tests whether the two shapes mutually separate each other (each disconnects the other).

◆ crosses() [5/5]

template<class PointType, class LabelType>
bool pgl::Segment< PointType, LabelType >::crosses ( const Shape< PointType > & other) const
nodiscardconstexpr

Tests whether the two shapes mutually separate each other (each disconnects the other).

◆ diameter()

template<class PointType, class LabelType>
Segment< PointType, LabelType > pgl::Segment< PointType, LabelType >::diameter ( ) const
nodiscardconstexpr

Returns a segment defining the diameter.

For a segment, the diameter is the segment itself.

Returns
This segment.

◆ distanceL1() [1/4]

template<class PointType, class LabelType>
template<class ResultNumber, PointConcept OtherPoint>
auto pgl::Segment< PointType, LabelType >::distanceL1 ( const OtherPoint & point) const
nodiscardconstexpr

Returns the Manhattan (L1) distance to the given shape.

Warning
With an integer ResultNumber the exact distance is generally a fraction for a non-axis-aligned segment, so the internal division truncates. Request a floating-point or pgl::Rational result type for an accurate value.

◆ distanceL1() [2/4]

template<class PointType, class LabelType>
template<class ResultNumber, SegmentConcept OtherSegment>
auto pgl::Segment< PointType, LabelType >::distanceL1 ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Returns the Manhattan (L1) distance to the given shape.

Warning
With an integer ResultNumber the exact distance is generally a fraction for a non-axis-aligned segment, so the internal division truncates. Request a floating-point or pgl::Rational result type for an accurate value.

◆ distanceL1() [3/4]

template<class TPoint, class TLabel>
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape& o, const Segment& self)
{ o.template distanceL1<ResultNumber>(self); })
auto pgl::Segment< TPoint, TLabel >::distanceL1 ( const OtherShape & other) const
inlinenodiscardconstexpr

Returns the Manhattan (L1) distance to the given shape.

Forwards to the other shape's implementation so that each unordered pair needs distanceL1 defined only once, on the higher-ranked shape.

◆ distanceL1() [4/4]

template<class TPoint, class TLabel>
template<class ResultNumber = double, PointConcept OtherPoint>
auto pgl::Segment< TPoint, TLabel >::distanceL1 ( const Shape< OtherPoint > & other) const
inlinenodiscardconstexpr

Returns the distance to the given shape, using symmetry to re-dispatch through the wrapper's own distanceL1.

Distance is symmetric, so this just calls other's own distanceL1, which visits its wrapped alternative and throws if the pair is unsupported.

◆ distanceLInf() [1/4]

template<class PointType, class LabelType>
template<class ResultNumber, PointConcept OtherPoint>
auto pgl::Segment< PointType, LabelType >::distanceLInf ( const OtherPoint & point) const
nodiscardconstexpr

Returns the Chebyshev (LInf) distance to the given shape.

Warning
With an integer ResultNumber the exact distance is generally a fraction for a non-axis-aligned segment, so the internal division truncates. Request a floating-point or pgl::Rational result type for an accurate value.

◆ distanceLInf() [2/4]

template<class PointType, class LabelType>
template<class ResultNumber, SegmentConcept OtherSegment>
auto pgl::Segment< PointType, LabelType >::distanceLInf ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Returns the Chebyshev (LInf) distance to the given shape.

Warning
With an integer ResultNumber the exact distance is generally a fraction for a non-axis-aligned segment, so the internal division truncates. Request a floating-point or pgl::Rational result type for an accurate value.

◆ distanceLInf() [3/4]

template<class TPoint, class TLabel>
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape& o, const Segment& self)
{ o.template distanceLInf<ResultNumber>(self); })
auto pgl::Segment< TPoint, TLabel >::distanceLInf ( const OtherShape & other) const
inlinenodiscardconstexpr

Returns the Chebyshev (LInf) distance to the given shape.

Forwards to the other shape's implementation so that each unordered pair needs distanceLInf defined only once, on the higher-ranked shape.

◆ distanceLInf() [4/4]

template<class TPoint, class TLabel>
template<class ResultNumber = double, PointConcept OtherPoint>
auto pgl::Segment< TPoint, TLabel >::distanceLInf ( const Shape< OtherPoint > & other) const
inlinenodiscardconstexpr

Returns the distance to the given shape, using symmetry to re-dispatch through the wrapper's own distanceLInf.

Distance is symmetric, so this just calls other's own distanceLInf, which visits its wrapped alternative and throws if the pair is unsupported.

◆ edges()

template<class PointType, class LabelType>
std::array< Segment< PointType, LabelType >, 1 > pgl::Segment< PointType, LabelType >::edges ( ) const
nodiscardconstexpr

Returns the unique boundary edge of the segment.

Returns
Array containing this segment.

◆ end()

template<class TPoint, class TLabel>
auto pgl::Segment< TPoint, TLabel >::end ( ) const
inlineconstexpr

Returns an iterator past the last endpoint.

Returns
Pointer past the second endpoint.

◆ fbox()

template<class PointType, class LabelType>
template<std::floating_point ResultNumber>
Rectangle< Point< ResultNumber > > pgl::Segment< PointType, LabelType >::fbox ( ) const
nodiscardconstexpr

Returns a bounding box of the segment with floating point coordinates.

Template Parameters
ResultNumberFloating point type
Returns
A rectangle that contains the segment.

◆ get()

template<class TPoint, class TLabel>
const PointType & pgl::Segment< TPoint, TLabel >::get ( std::ptrdiff_t index) const
inlineconstexpr

Cyclic access: same as operator[] but index is taken modulo size(); negative indices wrap from the end.

◆ getIfPoint()

template<class PointType, class LabelType>
std::optional< PointType > pgl::Segment< PointType, LabelType >::getIfPoint ( ) const
nodiscardconstexpr

Returns the point the segment collapses to, if it does.

Complexity: O(1).

Returns
The common endpoint if isPoint, std::nullopt otherwise.

◆ hausdorffDistanceL1() [1/4]

template<class PointType, class LabelType>
template<class ResultNumber, PointConcept OtherPoint>
auto pgl::Segment< PointType, LabelType >::hausdorffDistanceL1 ( const OtherPoint & point) const
nodiscardconstexpr

Returns the Manhattan (L1) Hausdorff distance to the given shape.

◆ hausdorffDistanceL1() [2/4]

template<class PointType, class LabelType>
template<class ResultNumber, SegmentConcept OtherSegment>
auto pgl::Segment< PointType, LabelType >::hausdorffDistanceL1 ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Returns the Manhattan (L1) Hausdorff distance to the given shape.

◆ hausdorffDistanceL1() [3/4]

template<class TPoint, class TLabel>
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape& o, const Segment& self)
{ o.template hausdorffDistanceL1<ResultNumber>(self); })
auto pgl::Segment< TPoint, TLabel >::hausdorffDistanceL1 ( const OtherShape & other) const
inlinenodiscardconstexpr

Returns the Manhattan (L1) Hausdorff distance to the given shape.

Forwards to the other shape's implementation so that each unordered pair needs hausdorffDistanceL1 defined only once, on the higher-ranked shape.

◆ hausdorffDistanceL1() [4/4]

template<class TPoint, class TLabel>
template<class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
auto pgl::Segment< TPoint, TLabel >::hausdorffDistanceL1 ( const Shape< OtherPoint > & other) const
inlinenodiscardconstexpr

Returns the distance to the given shape, using symmetry to re-dispatch through the wrapper's own hausdorffDistanceL1.

Distance is symmetric, so this just calls other's own hausdorffDistanceL1, which visits its wrapped alternative and throws if the pair is unsupported.

◆ hausdorffDistanceLInf() [1/4]

template<class PointType, class LabelType>
template<class ResultNumber, PointConcept OtherPoint>
auto pgl::Segment< PointType, LabelType >::hausdorffDistanceLInf ( const OtherPoint & point) const
nodiscardconstexpr

Returns the Chebyshev (LInf) Hausdorff distance to the given shape.

◆ hausdorffDistanceLInf() [2/4]

template<class PointType, class LabelType>
template<class ResultNumber, SegmentConcept OtherSegment>
auto pgl::Segment< PointType, LabelType >::hausdorffDistanceLInf ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Returns the Chebyshev (LInf) Hausdorff distance to the given shape.

◆ hausdorffDistanceLInf() [3/4]

template<class TPoint, class TLabel>
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape& o, const Segment& self)
{ o.template hausdorffDistanceLInf<ResultNumber>(self); })
auto pgl::Segment< TPoint, TLabel >::hausdorffDistanceLInf ( const OtherShape & other) const
inlinenodiscardconstexpr

Returns the Chebyshev (LInf) Hausdorff distance to the given shape.

Forwards to the other shape's implementation so that each unordered pair needs hausdorffDistanceLInf defined only once, on the higher-ranked shape.

◆ hausdorffDistanceLInf() [4/4]

template<class TPoint, class TLabel>
template<class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
auto pgl::Segment< TPoint, TLabel >::hausdorffDistanceLInf ( const Shape< OtherPoint > & other) const
inlinenodiscardconstexpr

Returns the distance to the given shape, using symmetry to re-dispatch through the wrapper's own hausdorffDistanceLInf.

Distance is symmetric, so this just calls other's own hausdorffDistanceLInf, which visits its wrapped alternative and throws if the pair is unsupported.

◆ index()

template<class TPoint, class TLabel>
std::ptrdiff_t pgl::Segment< TPoint, TLabel >::index ( const PointType & point) const
inlineconstexpr

Returns the smallest index i with (*this)[i] == point, or -1 if no endpoint equals point.

◆ interiorContains() [1/19]

template<class TPoint, class TLabel>
template<class EmptyPoint>
bool pgl::Segment< TPoint, TLabel >::interiorContains ( const EmptyShape< EmptyPoint > & ) const
inlinenodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [2/19]

template<class PointType, class LabelType>
template<MonotoneChainConcept OtherChain>
bool pgl::Segment< PointType, LabelType >::interiorContains ( const OtherChain & other) const
nodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [3/19]

template<class TPoint, class TLabel>
template<ConvexConcept OtherConvex>
bool pgl::Segment< TPoint, TLabel >::interiorContains ( const OtherConvex & other) const
inlinenodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [4/19]

template<class TPoint, class TLabel>
template<DiskConcept OtherDisk>
bool pgl::Segment< TPoint, TLabel >::interiorContains ( const OtherDisk & other) const
inlinenodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [5/19]

template<class TPoint, class TLabel>
template<HalfplaneConcept OtherHalfplane>
bool pgl::Segment< TPoint, TLabel >::interiorContains ( const OtherHalfplane & ) const
inlinenodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [6/19]

template<class TPoint, class TLabel>
template<LineConcept OtherLine>
bool pgl::Segment< TPoint, TLabel >::interiorContains ( const OtherLine & ) const
inlinenodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [7/19]

template<class TPoint, class TLabel>
template<OrientedLineConcept OtherOrientedLine>
bool pgl::Segment< TPoint, TLabel >::interiorContains ( const OtherOrientedLine & ) const
inlinenodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [8/19]

template<class PointType, class LabelType>
template<OrientedSegmentConcept OtherOrientedSegment>
bool pgl::Segment< PointType, LabelType >::interiorContains ( const OtherOrientedSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

Template Parameters
OtherPointType of the other oriented segment endpoints.
Parameters
otherOther oriented segment.
Returns
true if all points of other lie in the interior of this segment.

◆ interiorContains() [9/19]

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::interiorContains ( const OtherPoint & point) const
nodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

Template Parameters
OtherPointType of the point.
Parameters
pointPoint to check.
Returns
true if the point lies in the interior of this segment.

Segment

Segment endpoint, boundary, containment, collinearity, intersection, and topological predicates, including the generic separates / crosses dispatch used against 1D and area targets.

◆ interiorContains() [10/19]

template<class TPoint, class TLabel>
template<PolygonConcept OtherPolygon>
bool pgl::Segment< TPoint, TLabel >::interiorContains ( const OtherPolygon & other) const
inlinenodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [11/19]

template<class PointType, class LabelType>
template<PolylineConcept OtherPolyline>
bool pgl::Segment< PointType, LabelType >::interiorContains ( const OtherPolyline & other) const
nodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [12/19]

template<class TPoint, class TLabel>
template<RayConcept OtherRay>
bool pgl::Segment< TPoint, TLabel >::interiorContains ( const OtherRay & ) const
inlinenodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [13/19]

template<class TPoint, class TLabel>
template<RectangleConcept OtherRectangle>
bool pgl::Segment< TPoint, TLabel >::interiorContains ( const OtherRectangle & other) const
inlinenodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [14/19]

template<class TPoint, class TLabel>
template<PolygonWithHolesConcept OtherRegion>
bool pgl::Segment< TPoint, TLabel >::interiorContains ( const OtherRegion & other) const
nodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [15/19]

template<class PointType, class LabelType>
template<PolygonWithHolesConcept OtherRegion>
bool pgl::Segment< PointType, LabelType >::interiorContains ( const OtherRegion & other) const
nodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [16/19]

template<class PointType, class LabelType>
template<SegmentConcept OtherSegment>
bool pgl::Segment< PointType, LabelType >::interiorContains ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

Template Parameters
OtherPointType of the other segment endpoints.
Parameters
otherOther segment.
Returns
true if all points of other lie in the interior of this segment.

◆ interiorContains() [17/19]

template<class TPoint, class TLabel>
template<PolygonSetConcept OtherSet>
bool pgl::Segment< TPoint, TLabel >::interiorContains ( const OtherSet & other) const
inlinenodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorContains() [18/19]

template<class PointType, class LabelType>
template<TriangleConcept OtherTriangle>
bool pgl::Segment< PointType, LabelType >::interiorContains ( const OtherTriangle & other) const
nodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

Template Parameters
OtherPointType of the triangle defining points.
Parameters
otherTriangle to check.
Returns
true if all vertices of other lie in the interior of this segment.

◆ interiorContains() [19/19]

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::interiorContains ( const Shape< OtherPoint > & other) const
nodiscardconstexpr

Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).

◆ interiorsIntersect() [1/5]

template<class TPoint, class TLabel>
template<class EmptyPoint>
bool pgl::Segment< TPoint, TLabel >::interiorsIntersect ( const EmptyShape< EmptyPoint > & ) const
inlinenodiscardconstexpr

Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).

◆ interiorsIntersect() [2/5]

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::interiorsIntersect ( const OtherPoint & other) const
nodiscardconstexpr

Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).

Performs at most 4 orientation tests.

Template Parameters
OtherNumberCoordinate type of the other segment endpoints.
OtherPoint::LabelTypeLabel type of the other segment endpoints.
Parameters
otherOther segment.
Returns
true if the segments share at least one point interior to both.

Segment

Segment endpoint, boundary, containment, collinearity, intersection, and topological predicates, including the generic separates / crosses dispatch used against 1D and area targets.

◆ interiorsIntersect() [3/5]

template<class PointType, class LabelType>
template<SegmentConcept OtherSegment>
bool pgl::Segment< PointType, LabelType >::interiorsIntersect ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).

◆ interiorsIntersect() [4/5]

template<class TPoint, class TLabel>
template<typename OtherShape>
requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
bool pgl::Segment< TPoint, TLabel >::interiorsIntersect ( const OtherShape & other) const
inlinenodiscardconstexpr

Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).

◆ interiorsIntersect() [5/5]

template<class PointType, class LabelType>
bool pgl::Segment< PointType, LabelType >::interiorsIntersect ( const Shape< PointType > & other) const
nodiscardconstexpr

Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).

◆ intersection() [1/5]

template<class TPoint, class TLabel>
template<class ResultNumber = NumberType, class EmptyPoint>
EmptyShape< EmptyPoint > pgl::Segment< TPoint, TLabel >::intersection ( const EmptyShape< EmptyPoint > & ) const
inlinenodiscardconstexpr

Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.

◆ intersection() [2/5]

template<class PointType, class LabelType>
template<class ResultNumber, PointConcept OtherPoint>
std::optional< Point< ResultNumber, typename PointType::LabelType > > pgl::Segment< PointType, LabelType >::intersection ( const OtherPoint & other) const
nodiscardconstexpr

Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.

The intersection of two segments may be null, a point, or a segment. Hence, we return an std::optional of std::variant of point and segment. Division is only used if the segments cross.

Template Parameters
ResultNumberNumber type of the return value.
OtherNumberCoordinate type of the other segment endpoints.
OtherPoint::LabelTypeLabel type of the other segment endpoints.
Parameters
otherOther segment.
Returns
An std::optional of std::variant of Point and Segment representing the intersection.

◆ intersection() [3/5]

template<class PointType, class LabelType>
template<class ResultNumber, SegmentConcept OtherSegment>
std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Segment< Point< ResultNumber, typename PointType::LabelType > > > > pgl::Segment< PointType, LabelType >::intersection ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.

Warning
Divides coordinates after casting to ResultNumber.

◆ intersection() [4/5]

template<class TPoint, class TLabel>
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires (!PointConcept<OtherShape> && (detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape&
o, const Segment& self) { o.template intersection<ResultNumber>(self); })
auto pgl::Segment< TPoint, TLabel >::intersection ( const OtherShape & other) const
inlinenodiscardconstexpr

Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.

Warning
Divides coordinates after casting to ResultNumber.

◆ intersection() [5/5]

template<class TPoint, class TLabel>
template<class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
auto pgl::Segment< TPoint, TLabel >::intersection ( const Shape< OtherPoint > & other) const
inlinenodiscardconstexpr

Returns the intersection of the two shapes (A ∩ B), re-dispatching through the wrapper's own intersection.

An intersection is symmetric, so this just calls other's own intersection, which visits its wrapped alternative and throws if the pair is unsupported.

The point type is deduced from other so a plain concrete shape cannot reach this overload through an implicit conversion to Shape.

Returns
The intersection wrapped in a Shape, rather than the tighter type the concrete pair would answer with: which alternative other holds is not known until run time, so neither is the result's.

◆ intersects() [1/5]

template<class TPoint, class TLabel>
template<class EmptyPoint>
bool pgl::Segment< TPoint, TLabel >::intersects ( const EmptyShape< EmptyPoint > & ) const
inlinenodiscardconstexpr

Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).

◆ intersects() [2/5]

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::intersects ( const OtherPoint & other) const
nodiscardconstexpr

Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).

Segment

Segment endpoint, boundary, containment, collinearity, intersection, and topological predicates, including the generic separates / crosses dispatch used against 1D and area targets.

◆ intersects() [3/5]

template<class PointType, class LabelType>
template<SegmentConcept OtherSegment>
bool pgl::Segment< PointType, LabelType >::intersects ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).

Performs at most 4 orientation tests.

Template Parameters
OtherNumberCoordinate type of the other segment endpoints.
OtherPoint::LabelTypeLabel type of the other segment endpoints.
Parameters
otherOther segment.
Returns
true if the segments share at least one point.

◆ intersects() [4/5]

template<class TPoint, class TLabel>
template<typename OtherShape>
requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
bool pgl::Segment< TPoint, TLabel >::intersects ( const OtherShape & other) const
inlinenodiscardconstexpr

Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).

◆ intersects() [5/5]

template<class PointType, class LabelType>
bool pgl::Segment< PointType, LabelType >::intersects ( const Shape< PointType > & other) const
nodiscardconstexpr

Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).

◆ isDegenerate()

template<class PointType, class LabelType>
bool pgl::Segment< PointType, LabelType >::isDegenerate ( ) const
nodiscardconstexpr

Returns whether both endpoints coincide.

Returns
true if the segment is a single point.

Segment

Segment endpoint, boundary, containment, collinearity, intersection, and topological predicates, including the generic separates / crosses dispatch used against 1D and area targets.

◆ isHorizontal()

template<class PointType, class LabelType>
bool pgl::Segment< PointType, LabelType >::isHorizontal ( ) const
nodiscardconstexpr

Returns whether the segment is horizontal.

Returns
true if both endpoints share the same y-coordinate.

◆ isPoint()

template<class PointType, class LabelType>
bool pgl::Segment< PointType, LabelType >::isPoint ( ) const
nodiscardconstexpr

Returns whether the segment collapses to a single point.

Equivalent to isDegenerate for a segment, which always has two defining points.

Complexity: O(1).

Returns
true if both endpoints coincide.

◆ isUndefined()

template<class PointType, class LabelType>
bool pgl::Segment< PointType, LabelType >::isUndefined ( ) const
nodiscardconstexpr

Returns whether the segment is degenerate without collapsing to a point or to a segment.

A segment is never undefined: its only degeneracy is collapsing to a point, so this always returns false. Provided for uniformity with the other shapes.

Complexity: O(1).

Returns
false.

◆ isVertical()

template<class PointType, class LabelType>
bool pgl::Segment< PointType, LabelType >::isVertical ( ) const
nodiscardconstexpr

Returns whether the segment is vertical.

Returns
true if both endpoints share the same x-coordinate.

◆ label()

template<class TPoint, class TLabel>
template<class A = LabelType>
requires (detail::has_label_v<A>)
A & pgl::Segment< TPoint, TLabel >::label ( ) const
inlineconstexpr

Returns the segment label.

The label is mutable even through a const segment: it is metadata that does not participate in equality, hashing, or geometric predicates.

Returns
Reference to the stored label.

◆ latticePoints()

template<class PointType, class LabelType>
requires (detail::extended_integral<ResultNumber> || std::same_as<ResultNumber, BigInt>)
template<class ResultNumber>
requires (detail::extended_integral<ResultNumber> || std::same_as<ResultNumber, BigInt>)
std::vector< Point< ResultNumber, typename PointType::LabelType > > pgl::Segment< PointType, LabelType >::latticePoints ( ) const
nodiscard

Returns the integer points the segment contains.

The lattice points lie on the segment in order, from min to max, spaced by the primitive integer direction of the segment. An endpoint is among them exactly when it is a lattice point itself, so integer endpoints always are and fractional ones never are – a segment over non-integer coordinates still contains every grid point it passes through, and one whose supporting line misses the grid contains none.

A vertical or horizontal segment, a single point included, is answered from the integers of one interval, with no direction to reduce and no fraction to solve. Any other segment over integer coordinates costs one gcd; over fractional ones it solves for a lattice point on its supporting line, exactly and at the price of an extended gcd.

Template Parameters
ResultNumberInteger coordinate type of the points: the segment's own coordinate type when that is a signed integer, the integer a pgl::Rational is built on, and int64_t for anything else.
Returns
The lattice points, in increasing order, carrying no label.
Exceptions
std::logic_errorIf a coordinate is not finite, or a lattice point of the segment does not fit ResultNumber.
std::length_errorIf there are more of them than a vector holds.

◆ length()

template<class PointType, class LabelType>
template<class ApproximateNumber>
ApproximateNumber pgl::Segment< PointType, LabelType >::length ( ) const
nodiscard

Returns the Euclidean length.

Template Parameters
ApproximateNumberFloating-point return type.
Returns
Euclidean length.

◆ lengthL1()

template<class PointType, class LabelType>
auto pgl::Segment< PointType, LabelType >::lengthL1 ( ) const
nodiscardconstexpr

Returns the Manhattan length.

Returns
L1 length.

◆ lengthLInf()

template<class PointType, class LabelType>
auto pgl::Segment< PointType, LabelType >::lengthLInf ( ) const
nodiscardconstexpr

Returns the Chebyshev length.

Returns
L infinity length.

◆ max()

template<class TPoint, class TLabel>
const PointType & pgl::Segment< TPoint, TLabel >::max ( ) const
inlineconstexpr

Returns the largest stored endpoint.

Returns
Reference to the second endpoint.

◆ midpoint()

template<class PointType, class LabelType>
template<class ResultNumber>
Point< ResultNumber > pgl::Segment< PointType, LabelType >::midpoint ( ) const
nodiscardconstexpr

Returns the midpoint of the segment.

Template Parameters
ResultNumberCoordinate type of the midpoint.
Returns
Midpoint with no label.
Warning
Divides coordinates by 2. Inexact for odd integer coordinates.

◆ min()

template<class TPoint, class TLabel>
const PointType & pgl::Segment< TPoint, TLabel >::min ( ) const
inlineconstexpr

Returns the smallest stored endpoint.

Returns
Reference to the first endpoint.

◆ minkowskiErosion() [1/2]

template<class TPoint, class TLabel>
template<class OtherShape>
requires (!MinkowskiSummableConcept<Segment<TPoint, TLabel>, OtherShape> && BoundedPolygonalConcept<OtherShape>)
auto pgl::Segment< TPoint, TLabel >::minkowskiErosion ( const OtherShape & other) const
nodiscardconstexpr

Returns the Minkowski erosion of this shape by a bounded polygonal one (A ⊖ B).

The pairs MinkowskiSummableConcept turns away, which are exactly the ones whose sum needs a region: a sum sweeps the operand's concavity into its answer, so it is the operand that decides the result type, and minkowskiSum hands the pair over to it.

An erosion reads the operand only through its support function, and a support function sees no further than the convex hull – A ⊖ B is A ⊖ hull(B) for a convex A. So this shape keeps the pair and answers it with the same convex region it erodes to by any other operand, at a cost linear in the two sizes: a Polygon, a PolygonWithHoles, a PolygonSet, a Polyline and a MonotoneChain are all as cheap here as their vertex count.

Template Parameters
OtherShapeType of the shape to erode by.
Parameters
otherShape to erode by.
Returns
The erosion, as a HalfplaneIntersection – the whole plane when other covers no point.

◆ minkowskiErosion() [2/2]

template<class PointType_, class TLabel>
requires MinkowskiSummableConcept<Segment<TPoint, TLabel>, OtherShape>
template<class OtherShape>
requires MinkowskiSummableConcept<Segment<TPoint, TLabel>, OtherShape>
auto pgl::Segment< PointType_, TLabel >::minkowskiErosion ( const OtherShape & other) const
nodiscardconstexpr

Returns the Minkowski erosion of this shape by another (A ⊖ B).

The erosion is the point set {x : x ⊕ B ⊆ A}, the translations of other that keep it inside this shape – equivalently ⋂ {A - b : b ∈ B}. It is the morphological dual of minkowskiSum and is defined for the same pairs, but it is not commutative.

Eroding by a Point is the translation by its negation, so it returns this shape's own type; the other pairs come back as the convex region they are, a HalfplaneIntersection, which holds a lower-dimensional erosion and the empty one as readily as a two-dimensional one. A segment erodes to the sub-segment of itself the operand's width leaves.

Eroding by a shape that covers no point is the whole plane, which a HalfplaneIntersection returns and the tighter result types cannot.

Template Parameters
OtherShapeType of the shape to erode by.
Parameters
otherShape to erode by.
Returns
The erosion, in the tightest type that represents it.

◆ minkowskiSum() [1/2]

template<class TPoint, class TLabel>
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires (!MinkowskiSummableConcept<Segment<TPoint, TLabel>, OtherShape> && (detail::shapeRank<OtherShape> > detail::shapeRank
<Segment>) && requires(const OtherShape& o, const Segment& self) { o.template minkowskiSum<ResultNumber>(self); })
auto pgl::Segment< TPoint, TLabel >::minkowskiSum ( const OtherShape & other) const
inlinenodiscard

Returns the regularized Minkowski sum of the two shapes (A ⊕ B).

The pairs MinkowskiSummableConcept rejects are exactly the ones whose sum needs a region-valued result rather than one bounded convex shape; they are implemented on Polygon, PolygonWithHoles and Polyline. Forwards to the other shape's implementation so that each unordered pair needs the sum defined only once, on the higher-ranked shape.

◆ minkowskiSum() [2/2]

template<class PointType, class LabelType>
requires MinkowskiSummableConcept<Segment<TPoint, TLabel>, OtherShape>
template<class OtherShape>
requires MinkowskiSummableConcept<Segment<TPoint, TLabel>, OtherShape>
auto pgl::Segment< PointType, LabelType >::minkowskiSum ( const OtherShape & other) const
nodiscardconstexpr

Returns the Minkowski sum of this shape and another (A ⊕ B).

The sum is the point set {a + b : a ∈ A, b ∈ B}. Summing with a Point is a translation, so it returns this shape's own type; two bounded convex shapes sum to a Convex, or to a Rectangle when both are rectangles. See MinkowskiSummableConcept for the pairs a Minkowski sum is defined for.

Template Parameters
OtherShapeType of the other shape.
Parameters
otherShape to sum with.
Returns
The Minkowski sum, in the tightest type that represents it.

◆ operator Line< PointType >()

template<class PointType, class LabelType>
pgl::Segment< PointType, LabelType >::operator Line< PointType > ( ) const
explicitnodiscardconstexpr

Converts to the supporting unoriented line.

Direct initialization and explicit casts are allowed once Line is available.

Returns
Supporting line through both endpoints.

◆ operator*=() [1/2]

template<class TPoint, class TLabel>
template<class Scalar>
requires (!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
Segment< PointType, LabelType > & pgl::Segment< TPoint, TLabel >::operator*= ( const Scalar & scalar)
constexpr

◆ operator*=() [2/2]

template<class TPoint, class TLabel>
template<class Scalar>
requires (!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
Segment & pgl::Segment< TPoint, TLabel >::operator*= ( const Scalar & scalar)
constexpr

Scales the segment around the origin by a scalar in place.

◆ operator+=() [1/2]

template<class TPoint, class TLabel>
template<PointConcept OtherPoint>
Segment< PointType, LabelType > & pgl::Segment< TPoint, TLabel >::operator+= ( const OtherPoint & translation)
constexpr

◆ operator+=() [2/2]

template<class TPoint, class TLabel>
template<PointConcept OtherPoint>
Segment & pgl::Segment< TPoint, TLabel >::operator+= ( const OtherPoint & translation)
constexpr

Translates the segment by the given point in place.

◆ operator-=() [1/2]

template<class TPoint, class TLabel>
template<PointConcept OtherPoint>
Segment< PointType, LabelType > & pgl::Segment< TPoint, TLabel >::operator-= ( const OtherPoint & translation)
constexpr

◆ operator-=() [2/2]

template<class TPoint, class TLabel>
template<PointConcept OtherPoint>
Segment & pgl::Segment< TPoint, TLabel >::operator-= ( const OtherPoint & translation)
constexpr

Translates the segment by the negation of the given point in place.

◆ operator/=() [1/2]

template<class TPoint, class TLabel>
template<class Scalar>
requires (!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
Segment< PointType, LabelType > & pgl::Segment< TPoint, TLabel >::operator/= ( const Scalar & scalar)
constexpr

◆ operator/=() [2/2]

template<class TPoint, class TLabel>
template<class Scalar>
requires (!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
Segment & pgl::Segment< TPoint, TLabel >::operator/= ( const Scalar & scalar)
constexpr

Divides the segment coordinates by a scalar in place.

◆ operator<=>()

template<class TPoint, class TLabel>
auto pgl::Segment< TPoint, TLabel >::operator<=> ( const Segment< TPoint, TLabel > & other) const
inlineconstexpr

Provides lexicographic ordering on (x1,y1),(x2,y2).

The label is ignored, mirroring Point and Disk.

Parameters
otherSegment to compare with.
Returns
-1, 0, or 1.

◆ operator=()

template<class TPoint, class TLabel>
template<PointConcept OtherPointType, class OtherLabelType>
requires (std::constructible_from<PointType, const OtherPointType&>)
Segment & pgl::Segment< TPoint, TLabel >::operator= ( const Segment< OtherPointType, OtherLabelType > & other)
inlineconstexpr

Assigns from a segment with compatible point and label types.

◆ operator==()

template<class TPoint, class TLabel>
bool pgl::Segment< TPoint, TLabel >::operator== ( const Segment< TPoint, TLabel > & other) const
inlineconstexpr

Compares two segments by their endpoints; the label is ignored.

Parameters
otherSegment to compare with.
Returns
true if both segments have the same endpoints.

◆ operator[]()

template<class TPoint, class TLabel>
const PointType & pgl::Segment< TPoint, TLabel >::operator[] ( std::size_t index) const
inlineconstexpr

Returns endpoint 0 or 1.

Parameters
indexEndpoint index.
Returns
Reference to the selected endpoint.

◆ orientedEdges()

template<class PointType, class LabelType>
std::array< OrientedSegment< PointType >, 1 > pgl::Segment< PointType, LabelType >::orientedEdges ( ) const
nodiscardconstexpr

Returns the unique oriented boundary edge in canonical order.

Returns
Array containing min() -> max().

◆ parallel() [1/5]

template<class PointType, class LabelType>
template<LineConcept OtherLine>
bool pgl::Segment< PointType, LabelType >::parallel ( const OtherLine & other) const
nodiscardconstexpr

Returns whether a line is parallel to this segment.

Template Parameters
OtherPointType of the other segment endpoints.
Parameters
otherOther line.
Returns
true if both slopes are the same.

◆ parallel() [2/5]

template<class PointType, class LabelType>
template<OrientedLineConcept OtherOrientedLine>
bool pgl::Segment< PointType, LabelType >::parallel ( const OtherOrientedLine & other) const
nodiscardconstexpr

Returns whether an oriented line is parallel to this segment.

Template Parameters
OtherNumberCoordinate type of the line defining points.
OtherPoint::LabelTypeLabel type of the line defining points.
Parameters
otherOther oriented line.
Returns
true if both slopes are the same.

◆ parallel() [3/5]

template<class PointType, class LabelType>
template<OrientedSegmentConcept OtherOrientedSegment>
bool pgl::Segment< PointType, LabelType >::parallel ( const OtherOrientedSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Returns whether an oriented segment is parallel to this one.

Template Parameters
OtherPointType of the other segment endpoints.
Parameters
otherOther oriented segment.
Returns
true if both slopes are the same.

◆ parallel() [4/5]

template<class PointType, class LabelType>
template<RayConcept OtherRay>
bool pgl::Segment< PointType, LabelType >::parallel ( const OtherRay & other) const
nodiscardconstexpr

Returns whether a ray is parallel to this segment.

Template Parameters
OtherNumberCoordinate type of the ray defining points.
OtherPoint::LabelTypeLabel type of the ray defining points.
Parameters
otherOther ray.
Returns
true if both slopes are the same.

◆ parallel() [5/5]

template<class PointType, class LabelType>
template<SegmentConcept OtherSegment>
bool pgl::Segment< PointType, LabelType >::parallel ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Returns whether another segment is parallel to this one.

Template Parameters
OtherPointType of the other segment endpoints.
Parameters
otherOther segment.
Returns
true if both slopes are the same.

◆ pointInside()

template<class PointType, class LabelType>
template<class ResultNumber>
Point< ResultNumber > pgl::Segment< PointType, LabelType >::pointInside ( ) const
nodiscardconstexpr

Returns a point inside the segment.

For a segment, this is its midpoint.

Template Parameters
ResultNumberCoordinate type of the midpoint.
Returns
Midpoint with no label.
Warning
Divides coordinates by 2. Inexact for odd integer coordinates.

◆ pointInsideInteriorContainedIn()

template<class PointType, class LabelType>
template<class OtherShape>
bool pgl::Segment< PointType, LabelType >::pointInsideInteriorContainedIn ( const OtherShape & shape) const
nodiscardconstexpr

Tests whether some point in this shape's relative interior lies in the strict interior of shape.

Uses pointInside as the witness. When integer truncation rounds that witness onto or outside the boundary, this shape and shape are scaled so the witness is exact, leaving the containment relation unchanged.

◆ rotate90()

template<class PointType, class LabelType>
void pgl::Segment< PointType, LabelType >::rotate90 ( int k = 1)
constexpr

Rotates the segment by 90k degrees around the origin in place.

Endpoints are re-normalized after rotation.

Parameters
kNumber of 90-degree CCW rotations (may be negative).

◆ rotated90()

template<class PointType, class LabelType>
Segment< PointType, LabelType > pgl::Segment< PointType, LabelType >::rotated90 ( int k = 1) const
nodiscardconstexpr

Returns the segment rotated by 90k degrees around the origin.

Endpoints are re-normalized after rotation.

Parameters
kNumber of 90-degree CCW rotations (may be negative).
Returns
Rotated segment.

◆ samePointSet()

template<class PointType, class LabelType>
template<AnyShapeConcept OtherShape>
bool pgl::Segment< PointType, LabelType >::samePointSet ( const OtherShape & other) const
nodiscardconstexpr

Tests whether another shape defines exactly the same point set.

◆ scaledDownX() [1/2]

template<class TPoint, class TLabel>
template<class OtherNumber>
Segment< PointType, LabelType > pgl::Segment< TPoint, TLabel >::scaledDownX ( const OtherNumber scalar) const
constexpr

◆ scaledDownX() [2/2]

template<class TPoint, class TLabel>
template<class OtherNumber>
Segment pgl::Segment< TPoint, TLabel >::scaledDownX ( const OtherNumber scalar) const
nodiscardconstexpr

Returns the segment with its x-coordinates divided by a divisor.

◆ scaledDownY() [1/2]

template<class TPoint, class TLabel>
template<class OtherNumber>
Segment< PointType, LabelType > pgl::Segment< TPoint, TLabel >::scaledDownY ( const OtherNumber scalar) const
constexpr

◆ scaledDownY() [2/2]

template<class TPoint, class TLabel>
template<class OtherNumber>
Segment pgl::Segment< TPoint, TLabel >::scaledDownY ( const OtherNumber scalar) const
nodiscardconstexpr

Returns the segment with its y-coordinates divided by a divisor.

◆ scaleDownX()

template<class PointType, class LabelType>
template<class OtherNumber>
void pgl::Segment< PointType, LabelType >::scaleDownX ( const OtherNumber scalar)
constexpr

Divides the segment's x-coordinates by a divisor in place.

◆ scaleDownY()

template<class PointType, class LabelType>
template<class OtherNumber>
void pgl::Segment< PointType, LabelType >::scaleDownY ( const OtherNumber scalar)
constexpr

Divides the segment's y-coordinates by a divisor in place.

◆ scaledUpX() [1/2]

template<class TPoint, class TLabel>
template<class OtherNumber>
Segment< PointType, LabelType > pgl::Segment< TPoint, TLabel >::scaledUpX ( const OtherNumber scalar) const
constexpr

◆ scaledUpX() [2/2]

template<class TPoint, class TLabel>
template<class OtherNumber>
Segment pgl::Segment< TPoint, TLabel >::scaledUpX ( const OtherNumber scalar) const
nodiscardconstexpr

Returns the segment with its x-coordinates multiplied by a factor.

◆ scaledUpY() [1/2]

template<class TPoint, class TLabel>
template<class OtherNumber>
Segment< PointType, LabelType > pgl::Segment< TPoint, TLabel >::scaledUpY ( const OtherNumber scalar) const
constexpr

◆ scaledUpY() [2/2]

template<class TPoint, class TLabel>
template<class OtherNumber>
Segment pgl::Segment< TPoint, TLabel >::scaledUpY ( const OtherNumber scalar) const
nodiscardconstexpr

Returns the segment with its y-coordinates multiplied by a factor.

◆ scaleUpX()

template<class PointType, class LabelType>
template<class OtherNumber>
void pgl::Segment< PointType, LabelType >::scaleUpX ( const OtherNumber scalar)
constexpr

Multiplies the segment's x-coordinates by a factor in place.

◆ scaleUpY()

template<class PointType, class LabelType>
template<class OtherNumber>
void pgl::Segment< PointType, LabelType >::scaleUpY ( const OtherNumber scalar)
constexpr

Multiplies the segment's y-coordinates by a factor in place.

◆ separates() [1/19]

template<class TPoint, class TLabel>
template<class EmptyPoint>
bool pgl::Segment< TPoint, TLabel >::separates ( const EmptyShape< EmptyPoint > & ) const
inlinenodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ separates() [2/19]

template<class PointType, class LabelType>
template<MonotoneChainConcept OtherChain>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherChain & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ separates() [3/19]

template<class PointType, class LabelType>
template<ConvexConcept OtherConvex>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherConvex & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ separates() [4/19]

template<class PointType, class LabelType>
template<DiskConcept OtherDisk>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherDisk & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ separates() [5/19]

template<class PointType, class LabelType>
template<HalfplaneConcept OtherHalfplane>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherHalfplane & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ separates() [6/19]

template<class PointType, class LabelType>
template<LineConcept OtherLine>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherLine & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ separates() [7/19]

template<class PointType, class LabelType>
template<OrientedLineConcept OtherOrientedLine>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherOrientedLine & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ separates() [8/19]

template<class PointType, class LabelType>
template<OrientedSegmentConcept OtherOrientedSegment>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherOrientedSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ separates() [9/19]

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherPoint & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

Segment

Segment endpoint, boundary, containment, collinearity, intersection, and topological predicates, including the generic separates / crosses dispatch used against 1D and area targets.

◆ separates() [10/19]

template<class PointType, class LabelType>
template<PolygonConcept OtherPolygon>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherPolygon & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

Walks the polygon boundary once and counts its contacts with the segment: each is either a maximal run of boundary vertices lying on the segment, or an edge that cuts transversally through the segment's interior. Two such contacts mean the segment carries a chord clear across the polygon, so removing it splits the polygon in two.

Complexity: O(n) for n polygon vertices.

◆ separates() [11/19]

template<class PointType, class LabelType>
template<PolylineConcept OtherPolyline>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherPolyline & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ separates() [12/19]

template<class PointType, class LabelType>
template<RayConcept OtherRay>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherRay & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ separates() [13/19]

template<class PointType, class LabelType>
template<RectangleConcept OtherRectangle>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherRectangle & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ separates() [14/19]

template<class PointType, class LabelType>
template<PolygonWithHolesConcept OtherRegion>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherRegion & other) const
nodiscard

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

The region is settled by the cell engine of implementation/separates.hpp; see the notes on pgl::PolygonWithHoles::separates for what a region admits that a simply connected target does not.

◆ separates() [15/19]

template<class PointType, class LabelType>
template<HalfplaneIntersectionConcept OtherRegion>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherRegion & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ separates() [16/19]

template<class PointType, class LabelType>
template<SegmentConcept OtherSegment>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

Tests whether the this segment intersects the other segment in a single point that is not an endpoint of the other segment. Performs at most 4 orientation tests.

Template Parameters
OtherNumberCoordinate type of the other segment endpoints.
OtherPoint::LabelTypeLabel type of the other segment endpoints.
Parameters
otherOther segment.
Returns
true if removing this segment splits the other one.

◆ separates() [17/19]

template<class PointType, class LabelType>
template<PolygonSetConcept OtherSet>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherSet & other) const
nodiscard

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

A set of regions is the one target that may already be in several pieces before anything is removed, so this neither folds over its components nor answers false for a remover that misses it. See implementation/separates.hpp.

◆ separates() [18/19]

template<class PointType, class LabelType>
template<TriangleConcept OtherTriangle>
bool pgl::Segment< PointType, LabelType >::separates ( const OtherTriangle & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ separates() [19/19]

template<class PointType, class LabelType>
bool pgl::Segment< PointType, LabelType >::separates ( const Shape< PointType > & other) const
nodiscardconstexpr

Tests whether removing this shape disconnects the other shape (B∖A is disconnected).

◆ size()

template<class TPoint, class TLabel>
constexpr std::size_t pgl::Segment< TPoint, TLabel >::size ( )
inlinestaticconstexpr

Returns the number of endpoints (always 2).

◆ slope()

template<class PointType, class LabelType>
template<class ResultNumber>
ResultNumber pgl::Segment< PointType, LabelType >::slope ( ) const
nodiscardconstexpr

Returns the slope of the segment.

Undefined behavior for vertical segments.

Template Parameters
ResultNumberCoordinate type of the returned slope.
Returns
Slope.

◆ squaredDistance() [1/4]

template<class TPoint, class TLabel>
template<class ResultNumber = double, class DiskPointType, class DiskLabel>
detail::floating_result_t< ResultNumber > pgl::Segment< TPoint, TLabel >::squaredDistance ( const Disk< DiskPointType, DiskLabel > & disk) const
inlinenodiscard

Returns the squared Euclidean distance to a disk.

Forwards to Disk::squaredDistance. Reports in detail::floating_result_t<ResultNumber>: a distance realized on a circle is generally irrational, so a floating-point ResultNumber is honoured as asked and any other request falls back to double.

◆ squaredDistance() [2/4]

template<class PointType, class LabelType>
template<class ResultNumber, PointConcept OtherPoint>
auto pgl::Segment< PointType, LabelType >::squaredDistance ( const OtherPoint & point) const
nodiscardconstexpr

Returns the squared Euclidean distance to the given shape.

The computation uses a projection on the supporting line and divides by the squared segment length when the closest point lies in the interior.

Template Parameters
ResultNumberCoordinate type of the returned distance (default: division_result_t).
OtherPointType of the point.
Parameters
pointPoint to measure from.
Returns
Squared Euclidean distance.
Warning
With an integer ResultNumber the exact squared distance is generally a fraction, so the internal division truncates and the result is inexact. Request a floating-point or pgl::Rational result type, e.g. squaredDistance<double>(point), for an accurate value.

◆ squaredDistance() [3/4]

template<class PointType, class LabelType>
template<class ResultNumber, SegmentConcept OtherSegment>
auto pgl::Segment< PointType, LabelType >::squaredDistance ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Returns the squared Euclidean distance to the given shape.

Template Parameters
ResultNumberCoordinate type of the returned distance (default: division_result_t).
OtherNumberCoordinate type of the other segment endpoints.
OtherPoint::LabelTypeLabel type of the other segment endpoints.
Parameters
otherOther segment.
Returns
Squared Euclidean distance.
Warning
With an integer ResultNumber the exact squared distance is generally a fraction, so the internal division truncates and the result is inexact. Request a floating-point or pgl::Rational result type, e.g. squaredDistance<double>(other), for an accurate value.

◆ squaredDistance() [4/4]

template<class TPoint, class TLabel>
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape& o, const Segment& self)
{ o.template squaredDistance<ResultNumber>(self); })
auto pgl::Segment< TPoint, TLabel >::squaredDistance ( const OtherShape & other) const
inlinenodiscardconstexpr

Returns the squared Euclidean distance to the given shape.

Forwards to the other shape's implementation so that each unordered pair needs squaredDistance defined only once, on the higher-ranked shape.

◆ squaredHausdorffDistance() [1/3]

template<class PointType, class LabelType>
template<class ResultNumber, PointConcept OtherPoint>
auto pgl::Segment< PointType, LabelType >::squaredHausdorffDistance ( const OtherPoint & point) const
nodiscardconstexpr

Returns the squared Hausdorff distance to a point.

Template Parameters
ResultNumberCoordinate type of the returned distance (default: NumberType).
OtherPointType of the point.
Parameters
pointPoint to measure from.
Returns
Squared Hausdorff distance.

◆ squaredHausdorffDistance() [2/3]

template<class PointType, class LabelType>
template<class ResultNumber, SegmentConcept OtherSegment>
auto pgl::Segment< PointType, LabelType >::squaredHausdorffDistance ( const OtherSegment< TPoint, TLabel > & other) const
nodiscardconstexpr

Returns the squared Hausdorff distance to another segment.

Since the distance to a segment is convex along a segment, the directed Hausdorff distance is attained at an endpoint.

Template Parameters
ResultNumberCoordinate type of the returned distance (default: division_result_t).
OtherNumberCoordinate type of the other segment endpoints.
OtherPoint::LabelTypeLabel type of the other segment endpoints.
Parameters
otherOther segment.
Returns
Squared Hausdorff distance.
Warning
With an integer ResultNumber the exact squared distance is generally a fraction, so the internal division truncates and the result is inexact. Request a floating-point or pgl::Rational result type, e.g. squaredHausdorffDistance<double>(other), for an accurate value.

◆ squaredHausdorffDistance() [3/3]

template<class TPoint, class TLabel>
template<class ResultNumber = division_result_t<NumberType>, typename OtherShape>
requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>) && requires(const OtherShape& o, const Segment& self)
{ o.template squaredHausdorffDistance<ResultNumber>(self); })
auto pgl::Segment< TPoint, TLabel >::squaredHausdorffDistance ( const OtherShape & other) const
inlinenodiscardconstexpr

Returns the squared Hausdorff distance to the given shape.

Forwards to the other shape's implementation so that each unordered pair needs squaredHausdorffDistance defined only once, on the higher-ranked shape.

◆ squaredLength()

template<class PointType, class LabelType>
auto pgl::Segment< PointType, LabelType >::squaredLength ( ) const
nodiscardconstexpr

Returns the squared Euclidean length.

Returns
Squared Euclidean length.

◆ twiceArea()

template<class PointType, class LabelType>
Segment< PointType, LabelType >::NumberType pgl::Segment< PointType, LabelType >::twiceArea ( ) const
nodiscardconstexpr

Returns twice the area of the segment.

A segment is one-dimensional, so this is always zero.

Returns
Zero.

◆ vertices()

template<class PointType, class LabelType>
std::array< PointType, 2 > pgl::Segment< PointType, LabelType >::vertices ( ) const
nodiscardconstexpr

Returns the two endpoints in canonical order.

Returns
Array {min(), max()}.

◆ verticesContain()

template<class PointType, class LabelType>
template<PointConcept OtherPoint>
bool pgl::Segment< PointType, LabelType >::verticesContain ( const OtherPoint & point) const
nodiscardconstexpr

Returns whether one endpoint equals the given point.

Template Parameters
OtherPointType of the point.
Parameters
pointPoint to test.
Returns
true if the point is an endpoint of the segment.

◆ xAtY()

template<class PointType, class LabelType>
template<class ResultNumber, class OtherNumber>
std::optional< ResultNumber > pgl::Segment< PointType, LabelType >::xAtY ( const OtherNumber & y) const
nodiscardconstexpr

Returns the value of the x coordinate for a given y, if it exists.

Evaluates the x-coordinate of a segment at a given y-coordinate.

If the segment is horizontal at the given coordinate y, then we return the min x coordinate.

Template Parameters
ResultNumberNumber type of the return value.
OtherNumberCoordinate type of the y coordinate.
Parameters
yGiven y coordinate.
Returns
An std::optional of ResultNumber corresponding to the x coordinate.
Warning
Divides coordinates after casting to ResultNumber.

The value is returned only when y lies within the segment's vertical extent. Endpoints are handled exactly.

Template Parameters
ResultNumberReturn coordinate type.
OtherNumberQuery y-coordinate type.
Parameters
yQuery y-coordinate.
Returns
Interpolated x-coordinate, or empty when y is outside the segment.

◆ yAtX()

template<class PointType, class LabelType>
template<class ResultNumber, class OtherNumber>
std::optional< ResultNumber > pgl::Segment< PointType, LabelType >::yAtX ( const OtherNumber & x) const
nodiscardconstexpr

Returns the value of the y coordinate for a given x, if it exists.

Evaluates the y-coordinate of a segment at a given x-coordinate.

If the segment is vertical at the given coordinate x, then we return the min y coordinate.

Template Parameters
ResultNumberNumber type of the return value.
OtherNumberCoordinate type of the x coordinate.
Parameters
xGiven x coordinate.
Returns
An std::optional of ResultNumber corresponding to the y coordinate.
Warning
Divides coordinates after casting to ResultNumber.

The value is returned only when x lies within the segment's horizontal extent. Endpoints are handled exactly.

Template Parameters
ResultNumberReturn coordinate type.
OtherNumberQuery x-coordinate type.
Parameters
xQuery x-coordinate.
Returns
Interpolated y-coordinate, or empty when x is outside the segment.