Pangolin
Header-only C++20 plane computational geometry library
Loading...
Searching...
No Matches
segment.hpp
Go to the documentation of this file.
1#pragma once
2
4
12
13#include <array>
14#include <cassert>
15#include <cmath>
16#include <concepts>
17#include <cstddef>
18#include <functional>
19#include <ostream>
20#include <type_traits>
21#include <utility>
22#include <variant>
23#include <vector>
24#include <optional>
25
26
27namespace pgl {
28
29template <class PointType = Point<>, class Label>
30struct Segment;
31
33
34template <class PointType>
35Segment(PointType, PointType) -> Segment<PointType, NoLabel>;
36
37template <class PointType, class A>
38Segment(PointType, PointType, A) -> Segment<PointType, std::decay_t<A>>;
39
40template <class Number>
41Segment(Number, Number, Number, Number) -> Segment<Point<Number>, NoLabel>;
42
57template <class TPoint, class TLabel>
58struct Segment {
59 using PointType = TPoint;
60 using NumberType = PointType::NumberType;
61 using LabelType = TLabel;
62
63 static_assert(detail::is_point_v<PointType>, "Segment requires pgl::Point endpoints");
64
68 constexpr Segment() = default;
69
78 constexpr Segment(PointType first, PointType second) {
79 if (second < first) {
80 std::swap(first, second);
81 }
82 points_[0] = std::move(first);
83 points_[1] = std::move(second);
84 }
85
95 : Segment(PointType(x1, y1), PointType(x2, y2)) {}
96
107 template <class A>
108 requires(detail::has_label_v<LabelType> && std::constructible_from<LabelType, A&&>)
109 constexpr Segment(PointType first, PointType second, A&& label)
110 : Segment(std::move(first), std::move(second)) {
111 label_ = std::forward<A>(label);
112 }
113
115 template <class A>
116 requires(detail::has_label_v<LabelType> && std::constructible_from<LabelType, A&&>)
118 : Segment(PointType(x1, y1), PointType(x2, y2), std::forward<A>(label)) {}
119
126 template<PointConcept OtherPointType, class OtherLabelType>
127 requires(std::constructible_from<PointType, const OtherPointType&>)
129 : Segment(PointType(other.min()), PointType(other.max())) {
130 label_ = detail::copyLabel<LabelType>(other);
131 }
132
136 template<PointConcept OtherPointType, class OtherLabelType>
137 requires(std::constructible_from<PointType, const OtherPointType&>)
138 constexpr Segment& operator=(const Segment<OtherPointType, OtherLabelType>& other) {
139 points_[0] = PointType(other.min());
140 points_[1] = PointType(other.max());
141 label_ = detail::copyLabel<LabelType>(other);
142 return *this;
143 }
144
151 constexpr const PointType& operator[](std::size_t index) const {
152 assert(index < size());
153 return points_[index];
154 }
155
159 static constexpr std::size_t size() {
160 return 2;
161 }
162
167 constexpr const PointType& get(std::ptrdiff_t index) const {
168 const std::ptrdiff_t n = static_cast<std::ptrdiff_t>(size());
169 return (*this)[static_cast<std::size_t>(((index % n) + n) % n)];
170 }
171
176 constexpr std::ptrdiff_t index(const PointType& point) const {
177 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(size()); ++i) {
178 if ((*this)[static_cast<std::size_t>(i)] == point) {
179 return i;
180 }
181 }
182 return -1;
183 }
184
190 constexpr const PointType& min() const {
191 return points_[0];
192 }
193
199 constexpr const PointType& max() const {
200 return points_[1];
201 }
202
208 constexpr auto begin() const {
209 return points_.cbegin();
210 }
211
217 constexpr auto cbegin() const {
218 return points_.cbegin();
219 }
220
226 constexpr auto end() const {
227 return points_.cend();
228 }
229
235 constexpr auto cend() const {
236 return points_.cend();
237 }
238
245 constexpr bool operator==(const Segment& other) const {
246 return points_ == other.points_;
247 }
248
250 template<AnyShapeConcept OtherShape>
251 [[nodiscard]] constexpr bool samePointSet(const OtherShape& other) const;
252
261 constexpr auto operator<=>(const Segment& other) const {
262 return points_ <=> other.points_;
263 }
264
273 template <class A = LabelType>
274 requires(detail::has_label_v<A>)
275 constexpr A& label() const {
276 return label_;
277 }
278
287 [[nodiscard]] constexpr explicit operator Line<PointType>() const;
288
294 [[nodiscard]] constexpr Line<PointType> asLine() const {
295 return static_cast<Line<PointType>>(*this);
296 }
297
309 }
310
319 [[nodiscard]] constexpr Segment rotated90(int k = 1) const;
320
328 constexpr void rotate90(int k = 1);
329
331 template <class OtherNumber>
332 [[nodiscard]] constexpr Segment scaledUpX(const OtherNumber scalar) const;
333
335 template <class OtherNumber>
336 constexpr void scaleUpX(const OtherNumber scalar);
337
339 template <class OtherNumber>
340 [[nodiscard]] constexpr Segment scaledUpY(const OtherNumber scalar) const;
341
343 template <class OtherNumber>
344 constexpr void scaleUpY(const OtherNumber scalar);
345
347 template <class OtherNumber>
348 [[nodiscard]] constexpr Segment scaledDownX(const OtherNumber scalar) const;
349
351 template <class OtherNumber>
352 constexpr void scaleDownX(const OtherNumber scalar);
353
355 template <class OtherNumber>
356 [[nodiscard]] constexpr Segment scaledDownY(const OtherNumber scalar) const;
357
359 template <class OtherNumber>
360 constexpr void scaleDownY(const OtherNumber scalar);
361
362
368 [[nodiscard]] constexpr bool isDegenerate() const;
369
380 [[nodiscard]] constexpr bool isPoint() const;
381
389 [[nodiscard]] constexpr std::optional<PointType> getIfPoint() const;
390
403 [[nodiscard]] constexpr bool isUndefined() const;
404
410 [[nodiscard]] constexpr bool isVertical() const;
411
417 [[nodiscard]] constexpr bool isHorizontal() const;
418
427 template <class ResultNumber = NumberType>
428 [[nodiscard]] constexpr ResultNumber area() const;
429
437 [[nodiscard]] constexpr NumberType twiceArea() const;
438
444 [[nodiscard]] constexpr auto squaredLength() const;
445
452 template <class ApproximateNumber = double>
453 [[nodiscard]] ApproximateNumber length() const;
454
460 [[nodiscard]] constexpr auto lengthL1() const;
461
467 [[nodiscard]] constexpr auto lengthLInf() const;
468
477 template<PointConcept OtherPoint>
478 [[nodiscard]] constexpr bool verticesContain(const OtherPoint& point) const;
479
490 template<PointConcept OtherPoint>
491 [[nodiscard]] constexpr bool containsEndpoint(const OtherPoint& point) const;
492
503 template<PointConcept OtherPoint>
504 [[nodiscard]] constexpr bool boundaryContains(const OtherPoint& point) const;
505
516 // The boundary of a segment is exactly its two endpoints, a finite point
517 // set, so it contains no positive-length or two-dimensional shape.
519 template<SegmentConcept OtherSegment>
520 [[nodiscard]] constexpr bool boundaryContains(const OtherSegment& other) const {
521 return detail::reduceDegenerateToPoint(
522 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
523 }
524
525 template<OrientedSegmentConcept OtherOrientedSegment>
526 [[nodiscard]] constexpr bool boundaryContains(const OtherOrientedSegment& other) const {
527 return detail::reduceDegenerateToPoint(
528 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
529 }
530
531 template<LineConcept OtherLine>
532 [[nodiscard]] constexpr bool boundaryContains(const OtherLine&) const { return false; }
534 template<OrientedLineConcept OtherOrientedLine>
535 [[nodiscard]] constexpr bool boundaryContains(const OtherOrientedLine&) const { return false; }
537 template<RayConcept OtherRay>
538 [[nodiscard]] constexpr bool boundaryContains(const OtherRay&) const { return false; }
540 template<HalfplaneConcept OtherHalfplane>
541 [[nodiscard]] constexpr bool boundaryContains(const OtherHalfplane&) const { return false; }
543 template<RectangleConcept OtherRectangle>
544 [[nodiscard]] constexpr bool boundaryContains(const OtherRectangle& other) const {
545 return detail::reduceDegenerateToPoint(
546 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
547 }
548
549 template<TriangleConcept OtherTriangle>
550 [[nodiscard]] constexpr bool boundaryContains(const OtherTriangle& other) const {
551 return detail::reduceDegenerateToPoint(
552 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
553 }
554
555 template<ConvexConcept OtherConvex>
556 [[nodiscard]] constexpr bool boundaryContains(const OtherConvex& other) const {
557 return detail::reduceDegenerateToPoint(
558 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
559 }
560
561 template<PolygonConcept OtherPolygon>
562 [[nodiscard]] constexpr bool boundaryContains(const OtherPolygon& other) const {
563 return detail::reduceDegenerateToPoint(
564 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
565 }
566
567 template<DiskConcept OtherDisk>
568 [[nodiscard]] constexpr bool boundaryContains(const OtherDisk& other) const {
569 return detail::reduceDegenerateToPoint(
570 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
571 }
572
583 template<PointConcept OtherPoint>
584 [[nodiscard]] constexpr bool containsCollinear(const OtherPoint& point) const;
585
596 template<PointConcept OtherPoint>
597 [[nodiscard]] constexpr bool contains(const OtherPoint& point) const;
598
606 template<SegmentConcept OtherSegment>
607 [[nodiscard]] constexpr bool contains(const OtherSegment& other) const;
608
616 template<OrientedSegmentConcept OtherOrientedSegment>
617 [[nodiscard]] constexpr bool contains(const OtherOrientedSegment& other) const;
618
626 template<LineConcept OtherLine>
627 [[nodiscard]] constexpr bool contains(const OtherLine& other) const;
628
636 template<OrientedLineConcept OtherOrientedLine>
637 [[nodiscard]] constexpr bool contains(const OtherOrientedLine& other) const;
638
646 template<RayConcept OtherRay>
647 [[nodiscard]] constexpr bool contains(const OtherRay& other) const;
648
656 template<HalfplaneConcept OtherHalfplane>
657 [[nodiscard]] constexpr bool contains(const OtherHalfplane& other) const;
658
666 template<RectangleConcept OtherRectangle>
667 [[nodiscard]] constexpr bool contains(const OtherRectangle& other) const;
668
676 template<TriangleConcept OtherTriangle>
677 [[nodiscard]] constexpr bool contains(const OtherTriangle& other) const;
678
688 template<ConvexConcept OtherConvex>
689 [[nodiscard]] constexpr bool contains(const OtherConvex& other) const;
690
692 template<PolygonConcept OtherPolygon>
693 [[nodiscard]] constexpr bool contains(const OtherPolygon& other) const;
694
703 template<DiskConcept OtherDisk>
704 [[nodiscard]] constexpr bool contains(const OtherDisk& other) const;
705
713 template<PointConcept OtherPoint>
714 [[nodiscard]] constexpr bool contains(const Shape<OtherPoint>& other) const;
715
717 template<PointConcept OtherPoint>
718 [[nodiscard]] constexpr bool boundaryContains(const Shape<OtherPoint>& other) const;
719
720 // The empty set is a subset of every shape (contained in all of them) and
721 // disjoint from all of them, so containment is true while separation is
722 // false. These overloads let an EmptyShape flow through Shape's variant
723 // dispatch without special-casing.
725 template <class EmptyPoint>
726 [[nodiscard]] constexpr bool contains(const EmptyShape<EmptyPoint>&) const {
727 return true;
728 }
729
730 template <class EmptyPoint>
731 [[nodiscard]] constexpr bool boundaryContains(const EmptyShape<EmptyPoint>&) const {
732 return true;
733 }
734
735 template <class EmptyPoint>
736 [[nodiscard]] constexpr bool interiorContains(const EmptyShape<EmptyPoint>&) const {
737 return true;
738 }
739
740 template <class EmptyPoint>
741 [[nodiscard]] constexpr bool separates(const EmptyShape<EmptyPoint>&) const {
742 return false;
743 }
744
752 template<PointConcept OtherPoint>
753 [[nodiscard]] constexpr bool interiorContains(const OtherPoint& point) const;
754
762 template<SegmentConcept OtherSegment>
763 [[nodiscard]] constexpr bool interiorContains(const OtherSegment& other) const;
764
772 template<OrientedSegmentConcept OtherOrientedSegment>
773 [[nodiscard]] constexpr bool interiorContains(const OtherOrientedSegment& other) const;
774
782 template<TriangleConcept OtherTriangle>
783 [[nodiscard]] constexpr bool interiorContains(const OtherTriangle& other) const;
784
785 // A segment is one-dimensional: its interior is the open segment, which
786 // cannot contain any unbounded or two-dimensional shape.
788 template<LineConcept OtherLine>
789 [[nodiscard]] constexpr bool interiorContains(const OtherLine&) const { return false; }
791 template<OrientedLineConcept OtherOrientedLine>
792 [[nodiscard]] constexpr bool interiorContains(const OtherOrientedLine&) const { return false; }
794 template<RayConcept OtherRay>
795 [[nodiscard]] constexpr bool interiorContains(const OtherRay&) const { return false; }
797 template<HalfplaneConcept OtherHalfplane>
798 [[nodiscard]] constexpr bool interiorContains(const OtherHalfplane&) const { return false; }
800 template<RectangleConcept OtherRectangle>
801 [[nodiscard]] constexpr bool interiorContains(const OtherRectangle& other) const {
802 return detail::reduceDegenerateGuarded(
803 other, [this](const auto& carrier) { return this->interiorContains(carrier); });
804 }
805
806 template<ConvexConcept OtherConvex>
807 [[nodiscard]] constexpr bool interiorContains(const OtherConvex& other) const {
808 return detail::reduceDegenerateGuarded(
809 other, [this](const auto& carrier) { return this->interiorContains(carrier); });
810 }
811
812 template<PolygonConcept OtherPolygon>
813 [[nodiscard]] constexpr bool interiorContains(const OtherPolygon& other) const {
814 return detail::reduceDegenerate(
815 other, [this](const auto& carrier) { return this->interiorContains(carrier); });
816 }
817
818 template<DiskConcept OtherDisk>
819 [[nodiscard]] constexpr bool interiorContains(const OtherDisk& other) const {
820 return detail::reduceDegenerate(
821 other, [this](const auto& carrier) { return this->interiorContains(carrier); });
822 }
823
825 template<PointConcept OtherPoint>
826 [[nodiscard]] constexpr bool interiorContains(const Shape<OtherPoint>& other) const;
827
835 template<PointConcept OtherPoint>
836 [[nodiscard]] constexpr bool collinear(const OtherPoint& point) const;
837
845 template<SegmentConcept OtherSegment>
846 [[nodiscard]] constexpr bool collinear(const OtherSegment& other) const;
847
855 template<OrientedSegmentConcept OtherOrientedSegment>
856 [[nodiscard]] constexpr bool collinear(const OtherOrientedSegment& other) const;
857
862 template<LineConcept OtherLine>
863 [[nodiscard]] constexpr bool collinear(const OtherLine& other) const;
864
869 template<OrientedLineConcept OtherOrientedLine>
870 [[nodiscard]] constexpr bool collinear(const OtherOrientedLine& other) const;
871
876 template<RayConcept OtherRay>
877 [[nodiscard]] constexpr bool collinear(const OtherRay& other) const;
878
887 template <class ResultNumber = division_result_t<NumberType>>
888 [[nodiscard]] constexpr ResultNumber slope() const;
889
897 template<SegmentConcept OtherSegment>
898 [[nodiscard]] constexpr bool parallel(const OtherSegment& other) const;
899
907 template<OrientedSegmentConcept OtherOrientedSegment>
908 [[nodiscard]] constexpr bool parallel(const OtherOrientedSegment& other) const;
909
917 template<LineConcept OtherLine>
918 [[nodiscard]] constexpr bool parallel(const OtherLine& other) const;
919
928 template<OrientedLineConcept OtherOrientedLine>
929 [[nodiscard]] constexpr bool parallel(const OtherOrientedLine& other) const;
930
939 template<RayConcept OtherRay>
940 [[nodiscard]] constexpr bool parallel(const OtherRay& other) const;
941
943 template<PointConcept OtherPoint>
944 [[nodiscard]] constexpr bool intersects(const OtherPoint& other) const;
945
956 template<SegmentConcept OtherSegment>
957 [[nodiscard]] constexpr bool intersects(const OtherSegment& other) const;
958
960 [[nodiscard]] constexpr bool intersects(const Shape<PointType>& other) const;
961
963 template<typename OtherShape>
964 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
965 [[nodiscard]] constexpr bool intersects(const OtherShape& other) const {
966 return other.intersects(*this);
967 }
968
970 template <class EmptyPoint>
971 [[nodiscard]] constexpr bool intersects(const EmptyShape<EmptyPoint>&) const {
972 return false;
973 }
974
988 template <class ResultNumber = NumberType, PointConcept OtherPoint>
989 [[nodiscard]] constexpr std::optional<Point<ResultNumber, typename PointType::LabelType>>
990 intersection(const OtherPoint& other) const;
991
993 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
994 [[nodiscard]] constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>>>
995 intersection(const OtherSegment& other) const;
996
998 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
999 requires (!PointConcept<OtherShape>
1000 && (detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
1001 && requires(const OtherShape& o, const Segment& self) {
1002 o.template intersection<ResultNumber>(self);
1003 })
1004 [[nodiscard]] constexpr auto intersection(const OtherShape& other) const {
1005 return other.template intersection<ResultNumber>(*this);
1006 }
1007
1009 template <class ResultNumber = NumberType, class EmptyPoint>
1010 [[nodiscard]] constexpr EmptyShape<EmptyPoint> intersection(const EmptyShape<EmptyPoint>&) const {
1011 return {};
1012 }
1013
1026 template <class ResultNumber = division_result_t<NumberType>, class OtherNumber>
1027 [[nodiscard]] constexpr std::optional<ResultNumber>
1028 yAtX(const OtherNumber &x) const;
1029
1042 template <class ResultNumber = division_result_t<NumberType>, class OtherNumber>
1043 [[nodiscard]] constexpr std::optional<ResultNumber>
1044 xAtY(const OtherNumber &y) const;
1045
1049 template<PointConcept OtherPoint>
1050 [[nodiscard]] constexpr bool separates(const OtherPoint& other) const;
1051
1064 template<SegmentConcept OtherSegment>
1065 [[nodiscard]] constexpr bool separates(const OtherSegment& other) const;
1066
1068 template<OrientedSegmentConcept OtherOrientedSegment>
1069 [[nodiscard]] constexpr bool separates(const OtherOrientedSegment& other) const;
1070
1072 template<LineConcept OtherLine>
1073 [[nodiscard]] constexpr bool separates(const OtherLine& other) const;
1074
1076 template<OrientedLineConcept OtherOrientedLine>
1077 [[nodiscard]] constexpr bool separates(const OtherOrientedLine& other) const;
1078
1080 template<RayConcept OtherRay>
1081 [[nodiscard]] constexpr bool separates(const OtherRay& other) const;
1082
1084 template<RectangleConcept OtherRectangle>
1085 [[nodiscard]] constexpr bool separates(const OtherRectangle& other) const;
1086
1088 template<TriangleConcept OtherTriangle>
1089 [[nodiscard]] constexpr bool separates(const OtherTriangle& other) const;
1090
1092 template<HalfplaneConcept OtherHalfplane>
1093 [[nodiscard]] constexpr bool separates(const OtherHalfplane& other) const;
1094
1096 template<ConvexConcept OtherConvex>
1097 [[nodiscard]] constexpr bool separates(const OtherConvex& other) const;
1098
1110 template<PolygonConcept OtherPolygon>
1111 [[nodiscard]] constexpr bool separates(const OtherPolygon& other) const;
1112
1114 template<MonotoneChainConcept OtherChain>
1115 [[nodiscard]] constexpr bool contains(const OtherChain& other) const;
1116
1118 template<MonotoneChainConcept OtherChain>
1119 [[nodiscard]] constexpr bool boundaryContains(const OtherChain& other) const {
1120 return detail::reduceDegenerateToPoint(
1121 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
1122 }
1123
1125 template<MonotoneChainConcept OtherChain>
1126 [[nodiscard]] constexpr bool interiorContains(const OtherChain& other) const;
1127
1129 template<MonotoneChainConcept OtherChain>
1130 [[nodiscard]] constexpr bool separates(const OtherChain& other) const;
1131
1133 template<PolylineConcept OtherPolyline>
1134 [[nodiscard]] constexpr bool contains(const OtherPolyline& other) const;
1135
1137 template<PolylineConcept OtherPolyline>
1138 [[nodiscard]] constexpr bool boundaryContains(const OtherPolyline& other) const {
1139 return detail::reduceDegenerateToPoint(
1140 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
1141 }
1142
1144 template<PolylineConcept OtherPolyline>
1145 [[nodiscard]] constexpr bool interiorContains(const OtherPolyline& other) const;
1146
1148 template<PolylineConcept OtherPolyline>
1149 [[nodiscard]] constexpr bool separates(const OtherPolyline& other) const;
1150
1152 template<HalfplaneIntersectionConcept OtherRegion>
1153 [[nodiscard]] constexpr bool contains(const OtherRegion& other) const;
1154
1156 template<HalfplaneIntersectionConcept OtherRegion>
1157 [[nodiscard]] constexpr bool boundaryContains(const OtherRegion& other) const;
1158
1160 template<HalfplaneIntersectionConcept OtherRegion>
1161 [[nodiscard]] constexpr bool interiorContains(const OtherRegion& other) const;
1162
1164 template<HalfplaneIntersectionConcept OtherRegion>
1165 [[nodiscard]] constexpr bool separates(const OtherRegion& other) const;
1166
1174 template<PolygonWithHolesConcept OtherRegion>
1175 [[nodiscard]] constexpr bool contains(const OtherRegion& other) const;
1176
1183 template<PolygonWithHolesConcept OtherRegion>
1184 [[nodiscard]] constexpr bool boundaryContains(const OtherRegion& other) const;
1185
1187 template<PolygonWithHolesConcept OtherRegion>
1188 [[nodiscard]] constexpr bool interiorContains(const OtherRegion& other) const;
1189
1197 template<PolygonWithHolesConcept OtherRegion>
1198 [[nodiscard]] bool separates(const OtherRegion& other) const;
1199
1200 // -------------------------------------------------------------------------
1201 // A set of regions
1202 //
1203 // It outranks every other shape, so the symmetric relations reach it through
1204 // the rank-based forwarders and only the asymmetric ones are answered here.
1205 // A set is the union of its components, so it is contained exactly when
1206 // every component is — no matter what this shape is.
1207
1209 template<PolygonSetConcept OtherSet>
1210 [[nodiscard]] constexpr bool contains(const OtherSet& other) const {
1211 for (const auto& component : other) {
1212 if (!contains(component)) {
1213 return false;
1214 }
1215 }
1216 return true;
1217 }
1218
1220 template<PolygonSetConcept OtherSet>
1221 [[nodiscard]] constexpr bool boundaryContains(const OtherSet& other) const {
1222 for (const auto& component : other) {
1223 if (!boundaryContains(component)) {
1224 return false;
1225 }
1226 }
1227 return true;
1228 }
1229
1231 template<PolygonSetConcept OtherSet>
1232 [[nodiscard]] constexpr bool interiorContains(const OtherSet& other) const {
1233 for (const auto& component : other) {
1234 if (!interiorContains(component)) {
1235 return false;
1236 }
1237 }
1238 return true;
1239 }
1240
1249 template<PolygonSetConcept OtherSet>
1250 [[nodiscard]] bool separates(const OtherSet& other) const;
1251
1253 template<DiskConcept OtherDisk>
1254 [[nodiscard]] constexpr bool separates(const OtherDisk& other) const;
1255
1257 [[nodiscard]] constexpr bool separates(const Shape<PointType>& other) const;
1258
1269 template<PointConcept OtherPoint>
1270 [[nodiscard]] constexpr bool interiorsIntersect(const OtherPoint& other) const;
1271
1273 template<SegmentConcept OtherSegment>
1274 [[nodiscard]] constexpr bool interiorsIntersect(const OtherSegment& other) const;
1275
1277 template<typename OtherShape>
1278 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
1279 [[nodiscard]] constexpr bool interiorsIntersect(const OtherShape& other) const {
1280 return other.interiorsIntersect(*this);
1281 }
1282
1284 template <class EmptyPoint>
1285 [[nodiscard]] constexpr bool interiorsIntersect(const EmptyShape<EmptyPoint>&) const {
1286 return false;
1287 }
1288
1290 [[nodiscard]] constexpr bool interiorsIntersect(const Shape<PointType>& other) const;
1291
1305 template<SegmentConcept OtherSegment>
1306 [[nodiscard]] constexpr bool crosses(const OtherSegment& other) const;
1307
1309 template<PointConcept OtherPoint>
1310 [[nodiscard]] constexpr bool crosses(const OtherPoint& other) const;
1311
1313 template<typename OtherShape>
1314 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
1315 [[nodiscard]] constexpr bool crosses(const OtherShape& other) const {
1316 return other.crosses(*this);
1317 }
1318
1320 template <class EmptyPoint>
1321 [[nodiscard]] constexpr bool crosses(const EmptyShape<EmptyPoint>&) const {
1322 return false;
1323 }
1324
1326 [[nodiscard]] constexpr bool crosses(const Shape<PointType>& other) const;
1327
1346 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1347 [[nodiscard]] constexpr auto squaredDistance(const OtherPoint& point) const;
1348
1364 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1365 [[nodiscard]] constexpr auto squaredDistance(const OtherSegment& other) const;
1366
1373 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1374 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
1375 && requires(const OtherShape& o, const Segment& self) {
1376 o.template squaredDistance<ResultNumber>(self);
1377 })
1378 [[nodiscard]] constexpr auto squaredDistance(const OtherShape& other) const {
1379 return other.template squaredDistance<ResultNumber>(*this);
1380 }
1381
1389 template <class ResultNumber = double, class DiskPointType, class DiskLabel>
1390 [[nodiscard]] detail::floating_result_t<ResultNumber> squaredDistance(const Disk<DiskPointType, DiskLabel>& disk) const {
1391 return disk.template squaredDistance<ResultNumber>(*this);
1392 }
1393
1406 template <class ResultNumber = NumberType, BoundedPolygonalConcept OtherShape>
1407 requires detail::ClosestPairConcept<Segment<TPoint, TLabel>, OtherShape>
1408 [[nodiscard]] constexpr auto closestSegments(const OtherShape& other) const;
1409
1426 template <class ResultNumber = division_result_t<NumberType>, class OtherShape>
1427 requires detail::ClosestPointsPairConcept<Segment<TPoint, TLabel>, OtherShape>
1428 [[nodiscard]] constexpr auto closestPoints(const OtherShape& other) const;
1429
1438 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1439 [[nodiscard]] constexpr auto distanceL1(const OtherPoint& point) const;
1440
1442 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1443 [[nodiscard]] constexpr auto distanceL1(const OtherSegment& other) const;
1444
1451 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1452 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
1453 && requires(const OtherShape& o, const Segment& self) {
1454 o.template distanceL1<ResultNumber>(self);
1455 })
1456 [[nodiscard]] constexpr auto distanceL1(const OtherShape& other) const {
1457 return other.template distanceL1<ResultNumber>(*this);
1458 }
1459
1475 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1476 [[nodiscard]] constexpr auto intersection(const Shape<OtherPoint>& other) const {
1477 return other.template intersection<ResultNumber>(*this);
1478 }
1479
1488 template <class ResultNumber = double, PointConcept OtherPoint>
1489 [[nodiscard]] constexpr auto distanceL1(const Shape<OtherPoint>& other) const {
1490 return other.template distanceL1<ResultNumber>(*this);
1491 }
1492
1501 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1502 [[nodiscard]] constexpr auto distanceLInf(const OtherPoint& point) const;
1503
1505 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1506 [[nodiscard]] constexpr auto distanceLInf(const OtherSegment& other) const;
1507
1514 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1515 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
1516 && requires(const OtherShape& o, const Segment& self) {
1517 o.template distanceLInf<ResultNumber>(self);
1518 })
1519 [[nodiscard]] constexpr auto distanceLInf(const OtherShape& other) const {
1520 return other.template distanceLInf<ResultNumber>(*this);
1521 }
1522
1531 template <class ResultNumber = double, PointConcept OtherPoint>
1532 [[nodiscard]] constexpr auto distanceLInf(const Shape<OtherPoint>& other) const {
1533 return other.template distanceLInf<ResultNumber>(*this);
1534 }
1535
1537 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1538 [[nodiscard]] constexpr auto hausdorffDistanceL1(const OtherSegment& other) const;
1539
1541 template <class ResultNumber = NumberType, PointConcept OtherPoint>
1542 [[nodiscard]] constexpr auto hausdorffDistanceL1(const OtherPoint& point) const;
1543
1550 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1551 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
1552 && requires(const OtherShape& o, const Segment& self) {
1553 o.template hausdorffDistanceL1<ResultNumber>(self);
1554 })
1555 [[nodiscard]] constexpr auto hausdorffDistanceL1(const OtherShape& other) const {
1556 return other.template hausdorffDistanceL1<ResultNumber>(*this);
1557 }
1558
1567 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1568 [[nodiscard]] constexpr auto hausdorffDistanceL1(const Shape<OtherPoint>& other) const {
1569 return other.template hausdorffDistanceL1<ResultNumber>(*this);
1570 }
1571
1573 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1574 [[nodiscard]] constexpr auto hausdorffDistanceLInf(const OtherSegment& other) const;
1575
1577 template <class ResultNumber = NumberType, PointConcept OtherPoint>
1578 [[nodiscard]] constexpr auto hausdorffDistanceLInf(const OtherPoint& point) const;
1579
1586 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1587 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
1588 && requires(const OtherShape& o, const Segment& self) {
1589 o.template hausdorffDistanceLInf<ResultNumber>(self);
1590 })
1591 [[nodiscard]] constexpr auto hausdorffDistanceLInf(const OtherShape& other) const {
1592 return other.template hausdorffDistanceLInf<ResultNumber>(*this);
1593 }
1594
1603 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1604 [[nodiscard]] constexpr auto hausdorffDistanceLInf(const Shape<OtherPoint>& other) const {
1605 return other.template hausdorffDistanceLInf<ResultNumber>(*this);
1606 }
1607
1626 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1627 [[nodiscard]] constexpr auto squaredHausdorffDistance(const OtherSegment& other) const;
1628
1637 template <class ResultNumber = NumberType, PointConcept OtherPoint>
1638 [[nodiscard]] constexpr auto squaredHausdorffDistance(const OtherPoint& point) const;
1639
1646 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1647 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
1648 && requires(const OtherShape& o, const Segment& self) {
1650 })
1651 [[nodiscard]] constexpr auto squaredHausdorffDistance(const OtherShape& other) const {
1652 return other.template squaredHausdorffDistance<ResultNumber>(*this);
1653 }
1654
1662 [[nodiscard]] constexpr Segment diameter() const;
1663
1671 template <class ResultNumber = division_result_t<NumberType>>
1672 [[nodiscard]] constexpr Point<ResultNumber> midpoint() const;
1673
1683 template <class ResultNumber = division_result_t<NumberType>>
1684 [[nodiscard]] constexpr Point<ResultNumber> pointInside() const;
1685
1694 template <class OtherShape>
1695 [[nodiscard]] constexpr bool pointInsideInteriorContainedIn(const OtherShape& shape) const;
1696
1721 template <class ResultNumber = grid_number_t<typename TPoint::NumberType>>
1722 requires(detail::extended_integral<ResultNumber> || std::same_as<ResultNumber, BigInt>)
1725
1731 [[nodiscard]] constexpr Rectangle<PointType> bbox() const;
1732
1739 template <std::floating_point ResultNumber = double>
1740 [[nodiscard]] constexpr Rectangle<Point<ResultNumber>> fbox() const;
1741
1747 [[nodiscard]] constexpr std::array<PointType, 2> vertices() const;
1748
1754 [[nodiscard]] constexpr Convex<PointType> convexHull() const {
1755 return Convex<PointType>(vertices());
1756 }
1757
1763 [[nodiscard]] constexpr std::array<Segment, 1> edges() const;
1764
1770 [[nodiscard]] constexpr std::array<OrientedSegment<PointType>, 1> orientedEdges() const;
1771
1780 [[nodiscard]] constexpr Polyline<PointType> asPolyline() const;
1781
1795 template <class OtherShape>
1797 [[nodiscard]] constexpr auto minkowskiSum(const OtherShape& other) const;
1798
1821 template <class OtherShape>
1823 [[nodiscard]] constexpr auto minkowskiErosion(const OtherShape& other) const;
1824
1847 template <class OtherShape>
1848 requires (!MinkowskiSummableConcept<Segment<TPoint, TLabel>, OtherShape> &&
1850 [[nodiscard]] constexpr auto minkowskiErosion(const OtherShape& other) const;
1851
1862 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1864 && (detail::shapeRank<OtherShape> > detail::shapeRank<Segment>)
1865 && requires(const OtherShape& o, const Segment& self) {
1866 o.template minkowskiSum<ResultNumber>(self);
1867 })
1868 [[nodiscard]] auto minkowskiSum(const OtherShape& other) const {
1869 return other.template minkowskiSum<ResultNumber>(*this);
1870 }
1871
1873 template<PointConcept OtherPoint>
1874 constexpr Segment& operator+=(const OtherPoint& translation);
1875
1877 template<PointConcept OtherPoint>
1878 constexpr Segment& operator-=(const OtherPoint& translation);
1879
1881 template <class Scalar>
1882 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1883 constexpr Segment& operator*=(const Scalar& scalar);
1884
1886 template <class Scalar>
1887 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1888 constexpr Segment& operator/=(const Scalar& scalar);
1889
1890 private:
1891 template <std::floating_point ResultNumber, class Value>
1892 static constexpr ResultNumber lowerCoordinateBound(const Value& value);
1893
1894 template <std::floating_point ResultNumber, class Value>
1895 static constexpr ResultNumber upperCoordinateBound(const Value& value);
1896
1897 template<SegmentConcept OtherSegment>
1898 constexpr bool boundingBoxesOverlap(const OtherSegment& other) const;
1899
1900 // Returns 0 for no overlap, 1 for overlap but no cross, 2 for cross
1901 template<SegmentConcept OtherSegment>
1902 constexpr int boundingBoxesCross(const OtherSegment& other) const;
1903
1904 std::array<PointType,2> points_{};
1905 [[no_unique_address]] mutable LabelType label_{};
1906};
1907
1919template <class PointType, class LabelType, class TranslationNumber, class TranslationLabel>
1920constexpr auto operator-(const Segment<PointType, LabelType>& segment, const Point<TranslationNumber, TranslationLabel>& translation);
1921
1932template <class PointType, class LabelType, class Scalar>
1933 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1934constexpr auto operator*(const Segment<PointType, LabelType>& segment, const Scalar& scalar);
1935
1946template <class Scalar, class PointType, class LabelType>
1947 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1948constexpr auto operator*(const Scalar& scalar, const Segment<PointType, LabelType>& segment);
1949
1960template <class PointType, class LabelType, class Scalar>
1961 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1962constexpr auto operator/(const Segment<PointType, LabelType>& segment, const Scalar& scalar);
1963
1973template <class PointType, class LabelType>
1974std::ostream& operator<<(std::ostream& stream, const Segment<PointType, LabelType>& segment);
1975
1976} // pgl
Bounded polygonal primitives, convex or not.
Definition forward.hpp:373
Shape pairs whose Minkowski sum Pangolin can represent.
Definition forward.hpp:476
Definition forward.hpp:306
Definition forward.hpp:324
Definition arrangement.hpp:67
HalfplaneIntersection() -> HalfplaneIntersection< Point<>, NoLabel >
Definition halfplaneintersection.hpp:2308
@ y
Definition intervaltree.hpp:24
@ x
Definition intervaltree.hpp:24
@ vertex
Definition bitmatrix.hpp:37
Line() -> Line< Point<>, NoLabel >
constexpr auto operator-(const Point< LeftNumber, LeftLabel > &left, const Point< RightNumber, RightLabel > &right)
Translates a point by the opposite of another point.
Definition transformations.hpp:130
std::ostream & operator<<(std::ostream &stream, const Point< Number, Label > &point)
Streams a point as (x,y) or label:(x,y).
Definition io.hpp:27
Segment() -> Segment< Point<>, NoLabel >
Exact low-level orientation and incircle predicates.
Closed convex polygon stored by its vertices.
Definition convex.hpp:170
Closed Euclidean disk stored by boundary points plus optional disk label.
Definition disk.hpp:66
The empty set of points in the plane.
Definition emptyshape.hpp:33
Intersection of closed half-planes; convex but possibly unbounded or empty.
Definition halfplaneintersection.hpp:244
Unoriented infinite line.
Definition line.hpp:52
Sentinel type used when a point carries no extra label.
Definition point.hpp:31
Two-dimensional point with optional label payload.
Definition point.hpp:129
Open polygonal chain stored in traversal order; may self-intersect.
Definition polyline.hpp:69
Axis-aligned rectangle stored by minimum and maximum corners.
Definition rectangle.hpp:75
Unoriented closed segment between two endpoints plus optional segment label.
Definition segment.hpp:58
constexpr bool boundaryContains(const Shape< OtherPoint > &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1080
constexpr auto minkowskiErosion(const OtherShape &other) const
Returns the Minkowski erosion of this shape by another (A ⊖ B).
Definition minkowskierosion.hpp:627
constexpr const PointType & operator[](std::size_t index) const
Returns endpoint 0 or 1.
Definition segment.hpp:151
constexpr auto distanceLInf(const OtherPoint &point) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:207
auto minkowskiSum(const OtherShape &other) const
Returns the regularized Minkowski sum of the two shapes (A ⊕ B).
Definition segment.hpp:1868
constexpr auto distanceLInf(const OtherShape &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition segment.hpp:1519
constexpr bool boundaryContains(const OtherLine &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:532
constexpr bool contains(const OtherRegion &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2726
constexpr std::ptrdiff_t index(const PointType &point) const
Definition segment.hpp:176
constexpr bool verticesContain(const OtherPoint &point) const
Returns whether one endpoint equals the given point.
Definition predicates.hpp:149
constexpr bool separates(const OtherPolygon &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:493
constexpr bool contains(const OtherPolyline &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2362
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 dist...
Definition segment.hpp:1489
constexpr bool interiorContains(const OtherHalfplane &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition segment.hpp:798
constexpr bool crosses(const OtherSegment &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:38
constexpr bool contains(const OtherChain &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2004
constexpr bool collinear(const OtherLine &other) const
Returns whether a line lies on the same supporting line.
Definition predicates.hpp:194
constexpr bool separates(const OtherOrientedSegment &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:373
constexpr bool contains(const OtherTriangle &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:181
constexpr Rectangle< Point< ResultNumber > > fbox() const
Returns a bounding box of the segment with floating point coordinates.
Definition bounding.hpp:81
constexpr bool interiorsIntersect(const EmptyShape< EmptyPoint > &) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition segment.hpp:1285
constexpr bool boundaryContains(const OtherChain &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:1119
constexpr auto cend() const
Returns an iterator past the last endpoint.
Definition segment.hpp:235
constexpr Segment(PointType first, PointType second)
Creates a segment from two endpoints.
Definition segment.hpp:78
constexpr bool contains(const OtherPoint &point) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:119
constexpr bool collinear(const OtherOrientedSegment &other) const
Returns whether an oriented segment lies on the same supporting line.
Definition predicates.hpp:188
constexpr bool separates(const OtherRegion &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:4563
constexpr std::array< PointType, 2 > vertices() const
Returns the two endpoints in canonical order.
Definition bounding.hpp:93
constexpr Line< PointType > asLine() const
Returns the supporting line.
Definition segment.hpp:294
constexpr auto hausdorffDistanceLInf(const OtherShape &other) const
Returns the Chebyshev (LInf) Hausdorff distance to the given shape.
Definition segment.hpp:1591
bool separates(const OtherRegion &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:5647
constexpr bool boundaryContains(const OtherRegion &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
constexpr bool crosses(const EmptyShape< EmptyPoint > &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition segment.hpp:1321
constexpr bool intersects(const OtherPoint &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:48
constexpr bool separates(const OtherPolyline &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:3499
constexpr bool contains(const OtherHalfplane &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:158
constexpr auto minkowskiSum(const OtherShape &other) const
Returns the Minkowski sum of this shape and another (A ⊕ B).
Definition minkowski.hpp:794
constexpr bool separates(const OtherRectangle &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:401
constexpr auto squaredHausdorffDistance(const OtherPoint &point) const
Returns the squared Hausdorff distance to a point.
Definition distance.hpp:166
constexpr bool interiorContains(const OtherRegion &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:2045
constexpr bool boundaryContains(const OtherConvex &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:556
constexpr Segment(const Segment< OtherPointType, OtherLabelType > &other)
Converts a segment with a different point and/or label type.
Definition segment.hpp:128
constexpr bool isDegenerate() const
Returns whether both endpoints coincide.
Definition predicates.hpp:54
constexpr auto closestSegments(const OtherShape &other) const
Returns the pair of elements realizing the distance, nothing when the shapes meet.
Definition closest.hpp:314
constexpr Segment(PointType first, PointType second, A &&label)
Creates a segment from two endpoints and stores a label.
Definition segment.hpp:109
constexpr Segment scaledUpX(const OtherNumber scalar) const
Returns the segment with its x-coordinates multiplied by a factor.
constexpr auto minkowskiErosion(const OtherShape &other) const
Returns the Minkowski erosion of this shape by a bounded polygonal one (A ⊖ B).
constexpr bool boundaryContains(const OtherPolyline &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:1138
constexpr Segment(NumberType x1, NumberType y1, NumberType x2, NumberType y2, A &&label)
Same as the four-coordinate constructor, and stores a label.
Definition segment.hpp:117
constexpr bool boundaryContains(const OtherSegment &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:520
constexpr bool isUndefined() const
Returns whether the segment is degenerate without collapsing to a point or to a segment.
Definition predicates.hpp:72
constexpr bool contains(const OtherDisk &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:201
constexpr void rotate90(int k=1)
Rotates the segment by 90k degrees around the origin in place.
Definition transformations.hpp:235
constexpr bool intersects(const OtherSegment &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:54
constexpr auto lengthLInf() const
Returns the Chebyshev length.
Definition measures.hpp:60
constexpr bool boundaryContains(const OtherHalfplane &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:541
constexpr bool contains(const OtherRay &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:152
constexpr auto distanceLInf(const OtherSegment &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:214
constexpr EmptyShape< EmptyPoint > intersection(const EmptyShape< EmptyPoint > &) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition segment.hpp:1010
constexpr Rectangle< PointType > bbox() const
Returns the bounding box of the segment.
Definition bounding.hpp:72
TLabel LabelType
Definition segment.hpp:61
constexpr bool parallel(const OtherOrientedSegment &other) const
Returns whether an oriented segment is parallel to this one.
Definition predicates.hpp:212
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.
Definition intersection.hpp:100
constexpr auto closestPoints(const OtherShape &other) const
Returns the pair of points realizing the distance, nothing when the shapes meet.
Definition closest.hpp:321
constexpr bool boundaryContains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:731
constexpr bool pointInsideInteriorContainedIn(const OtherShape &shape) const
Tests whether some point in this shape's relative interior lies in the strict interior of shape.
Definition measures.hpp:94
constexpr bool collinear(const OtherRay &other) const
Returns whether a ray lies on the same supporting line.
Definition predicates.hpp:206
constexpr bool interiorsIntersect(const Shape< PointType > &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:116
constexpr bool separates(const OtherConvex &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:470
constexpr auto intersection(const Shape< OtherPoint > &other) const
Returns the intersection of the two shapes (A ∩ B), re-dispatching through the wrapper's own intersec...
Definition segment.hpp:1476
constexpr bool boundaryContains(const OtherRay &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:538
constexpr bool separates(const OtherSegment &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:321
constexpr bool interiorContains(const OtherRegion &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
constexpr Segment & operator-=(const OtherPoint &translation)
Translates the segment by the negation of the given point in place.
constexpr void scaleDownY(const OtherNumber scalar)
Divides the segment's y-coordinates by a divisor in place.
Definition transformations.hpp:291
constexpr bool crosses(const Shape< PointType > &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:89
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.
Definition intersection.hpp:110
constexpr bool separates(const OtherDisk &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:512
constexpr bool containsCollinear(const OtherPoint &point) const
Returns whether the segment contains the given point that is collinear with the segment.
Definition predicates.hpp:161
constexpr auto lengthL1() const
Returns the Manhattan length.
Definition measures.hpp:55
constexpr bool parallel(const OtherOrientedLine &other) const
Returns whether an oriented line is parallel to this segment.
Definition predicates.hpp:604
constexpr ResultNumber slope() const
Returns the slope of the segment.
Definition measures.hpp:66
constexpr bool boundaryContains(const OtherRectangle &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:544
constexpr auto end() const
Returns an iterator past the last endpoint.
Definition segment.hpp:226
constexpr Segment scaledDownY(const OtherNumber scalar) const
Returns the segment with its y-coordinates divided by a divisor.
constexpr bool contains(const OtherLine &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:140
constexpr bool contains(const OtherRectangle &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:164
constexpr bool isHorizontal() const
Returns whether the segment is horizontal.
Definition predicates.hpp:82
constexpr void scaleUpY(const OtherNumber scalar)
Multiplies the segment's y-coordinates by a factor in place.
Definition transformations.hpp:263
constexpr bool interiorContains(const OtherPoint &point) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:110
constexpr auto begin() const
Returns an iterator to the first endpoint.
Definition segment.hpp:208
constexpr Point< ResultNumber > midpoint() const
Returns the midpoint of the segment.
Definition measures.hpp:79
constexpr bool separates(const OtherChain &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:3149
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 haus...
Definition segment.hpp:1568
constexpr auto hausdorffDistanceL1(const OtherShape &other) const
Returns the Manhattan (L1) Hausdorff distance to the given shape.
Definition segment.hpp:1555
constexpr auto distanceL1(const OtherShape &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition segment.hpp:1456
constexpr std::array< Segment, 1 > edges() const
Returns the unique boundary edge of the segment.
Definition bounding.hpp:98
detail::floating_result_t< ResultNumber > squaredDistance(const Disk< DiskPointType, DiskLabel > &disk) const
Returns the squared Euclidean distance to a disk.
Definition segment.hpp:1390
constexpr bool contains(const OtherPolygon &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1706
constexpr auto operator<=>(const Segment &other) const
Provides lexicographic ordering on (x1,y1),(x2,y2).
Definition segment.hpp:261
constexpr bool separates(const OtherOrientedLine &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:385
constexpr Segment scaledUpY(const OtherNumber scalar) const
Returns the segment with its y-coordinates multiplied by a factor.
constexpr bool contains(const OtherOrientedLine &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:146
constexpr bool interiorContains(const OtherRay &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition segment.hpp:795
constexpr const PointType & max() const
Returns the largest stored endpoint.
Definition segment.hpp:199
std::vector< Point< ResultNumber, typename PointType::LabelType > > latticePoints() const
Returns the integer points the segment contains.
Definition lattice.hpp:373
constexpr bool crosses(const OtherPoint &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:84
constexpr bool separates(const EmptyShape< EmptyPoint > &) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition segment.hpp:741
constexpr bool intersects(const OtherShape &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition segment.hpp:965
constexpr bool interiorContains(const OtherSegment &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:116
static constexpr std::size_t size()
Returns the number of endpoints (always 2).
Definition segment.hpp:159
constexpr bool contains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition segment.hpp:726
PointType PointType
Definition segment.hpp:59
constexpr bool interiorContains(const OtherSet &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition segment.hpp:1232
ApproximateNumber length() const
Returns the Euclidean length.
Definition measures.hpp:50
constexpr const PointType & min() const
Returns the smallest stored endpoint.
Definition segment.hpp:190
constexpr bool isPoint() const
Returns whether the segment collapses to a single point.
Definition predicates.hpp:59
constexpr auto cbegin() const
Returns an iterator to the first endpoint.
Definition segment.hpp:217
constexpr bool containsEndpoint(const OtherPoint &point) const
Returns whether the given point is one endpoint.
Definition predicates.hpp:155
constexpr bool separates(const OtherLine &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:379
PointType::NumberType NumberType
Definition segment.hpp:60
constexpr auto squaredDistance(const OtherSegment &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:134
constexpr bool interiorContains(const OtherConvex &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition segment.hpp:807
constexpr bool boundaryContains(const OtherSet &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:1221
constexpr HalfplaneIntersection< PointType > asHalfplaneIntersection() const
Returns the segment as a (degenerate) half-plane intersection.
Definition segment.hpp:307
constexpr ResultNumber area() const
Returns the area of the segment.
Definition measures.hpp:34
constexpr bool interiorsIntersect(const OtherShape &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition segment.hpp:1279
constexpr const PointType & get(std::ptrdiff_t index) const
Cyclic access: same as operator[] but index is taken modulo size(); negative indices wrap from the en...
Definition segment.hpp:167
bool separates(const OtherSet &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:5915
constexpr auto squaredDistance(const OtherPoint &point) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:100
constexpr bool intersects(const Shape< PointType > &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:118
constexpr bool collinear(const OtherPoint &point) const
Returns whether the given point lies on the supporting line.
Definition predicates.hpp:167
constexpr bool interiorsIntersect(const OtherPoint &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:39
constexpr bool contains(const OtherConvex &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:187
constexpr Segment rotated90(int k=1) const
Returns the segment rotated by 90k degrees around the origin.
Definition transformations.hpp:230
constexpr bool boundaryContains(const OtherPoint &point) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:110
constexpr bool separates(const OtherHalfplane &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:411
constexpr Segment & operator+=(const OtherPoint &translation)
Translates the segment by the given point in place.
constexpr bool interiorContains(const OtherOrientedSegment &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:122
constexpr bool interiorContains(const OtherPolygon &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition segment.hpp:813
constexpr Polyline< PointType > asPolyline() const
Returns the segment as a two-vertex polyline.
Definition polyline.hpp:2595
constexpr bool collinear(const OtherOrientedLine &other) const
Returns whether an oriented line lies on the same supporting line.
Definition predicates.hpp:200
constexpr auto hausdorffDistanceL1(const OtherPoint &point) const
Returns the Manhattan (L1) Hausdorff distance to the given shape.
Definition distancel1.hpp:969
constexpr auto hausdorffDistanceLInf(const OtherPoint &point) const
Returns the Chebyshev (LInf) Hausdorff distance to the given shape.
Definition distancelinf.hpp:957
constexpr bool interiorContains(const OtherChain &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1459
constexpr auto hausdorffDistanceL1(const OtherSegment &other) const
Returns the Manhattan (L1) Hausdorff distance to the given shape.
Definition distancel1.hpp:961
constexpr bool contains(const OtherSet &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition segment.hpp:1210
constexpr bool boundaryContains(const OtherOrientedSegment &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:526
constexpr auto squaredDistance(const OtherShape &other) const
Returns the squared Euclidean distance to the given shape.
Definition segment.hpp:1378
constexpr bool boundaryContains(const OtherRegion &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1638
constexpr bool parallel(const OtherRay &other) const
Returns whether a ray is parallel to this segment.
Definition predicates.hpp:838
constexpr auto hausdorffDistanceLInf(const OtherSegment &other) const
Returns the Chebyshev (LInf) Hausdorff distance to the given shape.
Definition distancelinf.hpp:949
constexpr auto intersection(const OtherShape &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition segment.hpp:1004
constexpr bool collinear(const OtherSegment &other) const
Returns whether another segment lies on the same supporting line.
Definition predicates.hpp:176
constexpr bool intersects(const EmptyShape< EmptyPoint > &) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition segment.hpp:971
constexpr bool samePointSet(const OtherShape &other) const
Tests whether another shape defines exactly the same point set.
Definition samepointset.hpp:1947
constexpr bool interiorContains(const OtherDisk &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition segment.hpp:819
constexpr void scaleUpX(const OtherNumber scalar)
Multiplies the segment's x-coordinates by a factor in place.
Definition transformations.hpp:249
constexpr bool separates(const Shape< PointType > &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:519
constexpr bool boundaryContains(const OtherDisk &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:568
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 haus...
Definition segment.hpp:1604
constexpr Point< ResultNumber > pointInside() const
Returns a point inside the segment.
Definition measures.hpp:88
constexpr Segment scaledDownX(const OtherNumber scalar) const
Returns the segment with its x-coordinates divided by a divisor.
constexpr bool boundaryContains(const OtherOrientedLine &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:535
constexpr auto distanceL1(const OtherPoint &point) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:219
constexpr bool crosses(const OtherShape &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition segment.hpp:1315
constexpr bool contains(const Shape< OtherPoint > &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:207
constexpr bool interiorContains(const Shape< OtherPoint > &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:134
constexpr bool interiorContains(const OtherLine &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition segment.hpp:789
constexpr bool operator==(const Segment &other) const
Compares two segments by their endpoints; the label is ignored.
Definition segment.hpp:245
constexpr bool boundaryContains(const OtherPolygon &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:562
constexpr bool boundaryContains(const OtherTriangle &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition segment.hpp:550
constexpr bool isVertical() const
Returns whether the segment is vertical.
Definition predicates.hpp:77
constexpr bool contains(const OtherOrientedSegment &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:134
constexpr bool interiorsIntersect(const OtherSegment &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:46
constexpr NumberType twiceArea() const
Returns twice the area of the segment.
Definition measures.hpp:39
constexpr A & label() const
Definition segment.hpp:275
constexpr Segment diameter() const
Returns a segment defining the diameter.
Definition measures.hpp:73
constexpr bool contains(const OtherRegion &other) const
Tests whether this shape contains the other shape (A ⊇ B).
constexpr Segment(NumberType x1, NumberType y1, NumberType x2, NumberType y2)
Creates a segment from four coordinates.
Definition segment.hpp:94
constexpr auto squaredHausdorffDistance(const OtherSegment &other) const
Returns the squared Hausdorff distance to another segment.
Definition distance.hpp:152
constexpr auto squaredLength() const
Returns the squared Euclidean length.
Definition measures.hpp:44
constexpr bool separates(const OtherPoint &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:315
constexpr Segment()=default
Creates the degenerate segment (0,0)--(0,0).
constexpr auto distanceL1(const OtherSegment &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:226
constexpr bool contains(const OtherSegment &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:128
constexpr Convex< PointType > convexHull() const
Returns the convex hull of the segment's endpoints.
Definition segment.hpp:1754
constexpr bool interiorContains(const OtherTriangle &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:128
constexpr std::array< OrientedSegment< PointType >, 1 > orientedEdges() const
Returns the unique oriented boundary edge in canonical order.
Definition bounding.hpp:103
constexpr void scaleDownX(const OtherNumber scalar)
Divides the segment's x-coordinates by a divisor in place.
Definition transformations.hpp:277
constexpr bool interiorContains(const OtherOrientedLine &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition segment.hpp:792
constexpr bool separates(const OtherTriangle &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:417
constexpr auto squaredHausdorffDistance(const OtherShape &other) const
Returns the squared Hausdorff distance to the given shape.
Definition segment.hpp:1651
constexpr bool parallel(const OtherLine &other) const
Returns whether a line is parallel to this segment.
Definition predicates.hpp:472
constexpr bool interiorContains(const OtherPolyline &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1682
constexpr std::optional< ResultNumber > yAtX(const OtherNumber &x) const
Returns the value of the y coordinate for a given x, if it exists.
Definition atxy.hpp:30
constexpr bool separates(const OtherRay &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:391
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 dist...
Definition segment.hpp:1532
constexpr bool parallel(const OtherSegment &other) const
Returns whether another segment is parallel to this one.
Definition predicates.hpp:182
constexpr std::optional< ResultNumber > xAtY(const OtherNumber &y) const
Returns the value of the x coordinate for a given y, if it exists.
Definition atxy.hpp:61
constexpr std::optional< PointType > getIfPoint() const
Returns the point the segment collapses to, if it does.
Definition predicates.hpp:64
constexpr bool interiorContains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition segment.hpp:736
constexpr bool interiorContains(const OtherRectangle &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition segment.hpp:801
Runtime variant wrapper over the supported primitive shapes.
Definition shape.hpp:160