Pangolin
Header-only C++20 plane computational geometry library
Loading...
Searching...
No Matches
line.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "shape/halfplane.hpp"
4
12
13#include <array>
14#include <cassert>
15#include <cmath>
16#include <concepts>
17#include <cstddef>
18#include <functional>
19#include <optional>
20#include <ostream>
21#include <type_traits>
22#include <utility>
23#include <variant>
24
25
26namespace pgl {
27
28template <class PointType = Point<>, class Label>
29struct Line;
30
32
33template <class PointType>
34Line(PointType, PointType) -> Line<PointType, NoLabel>;
35
36template <class PointType, class A>
37Line(PointType, PointType, A) -> Line<PointType, std::decay_t<A>>;
38
39template <class Number>
40Line(Number, Number, Number, Number) -> Line<Point<Number>, NoLabel>;
41
51template <class PointType_, class TLabel>
52struct Line {
53 using PointType = PointType_;
54 using NumberType = PointType::NumberType;
55 using LabelType = TLabel;
56 using CoordinateType = detail::promoted_number_t<NumberType>;
57
58 static_assert(detail::is_point_v<PointType>, "Line requires pgl::Point defining points");
59
63 constexpr Line() = default;
64
73 constexpr Line(PointType first, PointType second) {
74 if (second < first) {
75 std::swap(first, second);
76 }
77 points_[0] = std::move(first);
78 points_[1] = std::move(second);
79 }
80
90 : Line(PointType(x1, y1), PointType(x2, y2)) {}
91
99 template <class A>
100 requires(detail::has_label_v<LabelType> && std::constructible_from<LabelType, A&&>)
101 constexpr Line(PointType first, PointType second, A&& label)
102 : Line(std::move(first), std::move(second)) {
103 label_ = std::forward<A>(label);
104 }
105
107 template <class A>
108 requires(detail::has_label_v<LabelType> && std::constructible_from<LabelType, A&&>)
109 constexpr Line(NumberType x1, NumberType y1, NumberType x2, NumberType y2, A&& label)
110 : Line(PointType(x1, y1), PointType(x2, y2), std::forward<A>(label)) {}
111
118 template<PointConcept OtherPointType, class OtherLabelType>
119 requires(std::constructible_from<PointType, const OtherPointType&>)
121 : Line(PointType(other.min()), PointType(other.max())) {
122 label_ = detail::copyLabel<LabelType>(other);
123 }
124
126 template<PointConcept OtherPointType, class OtherLabelType>
127 requires(std::constructible_from<PointType, const OtherPointType&>)
128 constexpr Line& operator=(const Line<OtherPointType, OtherLabelType>& other) {
129 points_[0] = PointType(other.min());
130 points_[1] = PointType(other.max());
131 label_ = detail::copyLabel<LabelType>(other);
132 return *this;
133 }
134
141 constexpr const PointType& operator[](std::size_t index) const {
142 assert(index < size());
143 return points_[index];
144 }
145
149 static constexpr std::size_t size() {
150 return 2;
151 }
152
157 constexpr const PointType& get(std::ptrdiff_t index) const {
158 const std::ptrdiff_t n = static_cast<std::ptrdiff_t>(size());
159 return (*this)[static_cast<std::size_t>(((index % n) + n) % n)];
160 }
161
166 constexpr std::ptrdiff_t index(const PointType& point) const {
167 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(size()); ++i) {
168 if ((*this)[static_cast<std::size_t>(i)] == point) {
169 return i;
170 }
171 }
172 return -1;
173 }
174
180 constexpr const PointType& min() const {
181 return points_[0];
182 }
183
189 constexpr const PointType& max() const {
190 return points_[1];
191 }
192
198 constexpr auto begin() const {
199 return points_.cbegin();
200 }
201
207 constexpr auto cbegin() const {
208 return points_.cbegin();
209 }
210
216 constexpr auto end() const {
217 return points_.cend();
218 }
219
225 constexpr auto cend() const {
226 return points_.cend();
227 }
228
237 [[nodiscard]] constexpr bool operator==(const Line& other) const;
238
240 template<AnyShapeConcept OtherShape>
241 [[nodiscard]] constexpr bool samePointSet(const OtherShape& other) const;
242
250 [[nodiscard]] constexpr auto operator<=>(const Line& other) const;
251
260 template <class A = LabelType>
261 requires(detail::has_label_v<A>)
262 constexpr A& label() const {
263 return label_;
264 }
265
276 template<PointConcept OtherPoint>
277 [[nodiscard]] constexpr Segment<PointType> asSegmentFor(const Rectangle<OtherPoint> &rect) const {
278 return OrientedLine<PointType>(min(), max()).asOrientedSegmentFor(rect).asSegment();
279 }
280
291 }
292
300 template<class ResultNumber = division_result_t<NumberType>>
302
310 template<class ResultNumber = division_result_t<NumberType>>
312
321 template <class ResultNumber = NumberType>
322 [[nodiscard]] constexpr ResultNumber area() const;
323
331 [[nodiscard]] constexpr NumberType twiceArea() const;
332
339 [[nodiscard]] constexpr Line rotated90(int k = 1) const;
340
346 constexpr void rotate90(int k = 1);
347
349 template <class OtherNumber>
350 [[nodiscard]] constexpr Line scaledUpX(const OtherNumber scalar) const;
351
353 template <class OtherNumber>
354 constexpr void scaleUpX(const OtherNumber scalar);
355
357 template <class OtherNumber>
358 [[nodiscard]] constexpr Line scaledUpY(const OtherNumber scalar) const;
359
361 template <class OtherNumber>
362 constexpr void scaleUpY(const OtherNumber scalar);
363
365 template <class OtherNumber>
366 [[nodiscard]] constexpr Line scaledDownX(const OtherNumber scalar) const;
367
369 template <class OtherNumber>
370 constexpr void scaleDownX(const OtherNumber scalar);
371
373 template <class OtherNumber>
374 [[nodiscard]] constexpr Line scaledDownY(const OtherNumber scalar) const;
375
377 template <class OtherNumber>
378 constexpr void scaleDownY(const OtherNumber scalar);
379
385 [[nodiscard]] constexpr bool isDegenerate() const;
386
398 [[nodiscard]] constexpr bool isUndefined() const;
399
405 [[nodiscard]] constexpr bool isVertical() const;
406
412 [[nodiscard]] constexpr bool isHorizontal() const;
413
422 template<PointConcept OtherPoint>
423 [[nodiscard]] constexpr bool verticesContain(const OtherPoint& point) const;
424
435 template<PointConcept OtherPoint>
436 [[nodiscard]] constexpr bool boundaryContains(const OtherPoint& point) const;
437
438 // A line has empty boundary, so it boundary-contains no non-point shape.
440 template<SegmentConcept OtherSegment>
441 [[nodiscard]] constexpr bool boundaryContains(const OtherSegment&) const { return false; }
443 template<OrientedSegmentConcept OtherOrientedSegment>
444 [[nodiscard]] constexpr bool boundaryContains(const OtherOrientedSegment&) const { return false; }
446 template<LineConcept OtherLine>
447 [[nodiscard]] constexpr bool boundaryContains(const OtherLine&) const { return false; }
449 template<OrientedLineConcept OtherOrientedLine>
450 [[nodiscard]] constexpr bool boundaryContains(const OtherOrientedLine&) const { return false; }
452 template<RayConcept OtherRay>
453 [[nodiscard]] constexpr bool boundaryContains(const OtherRay&) const { return false; }
455 template<HalfplaneConcept OtherHalfplane>
456 [[nodiscard]] constexpr bool boundaryContains(const OtherHalfplane&) const { return false; }
458 template<RectangleConcept OtherRectangle>
459 [[nodiscard]] constexpr bool boundaryContains(const OtherRectangle&) const { return false; }
461 template<TriangleConcept OtherTriangle>
462 [[nodiscard]] constexpr bool boundaryContains(const OtherTriangle&) const { return false; }
464 template<ConvexConcept OtherConvex>
465 [[nodiscard]] constexpr bool boundaryContains(const OtherConvex&) const { return false; }
467 template<PolygonConcept OtherPolygon>
468 [[nodiscard]] constexpr bool boundaryContains(const OtherPolygon&) const { return false; }
470 template<DiskConcept OtherDisk>
471 [[nodiscard]] constexpr bool boundaryContains(const OtherDisk&) const { return false; }
472
484 template<PointConcept OtherPoint>
485 [[nodiscard]] constexpr bool contains(const OtherPoint& point) const;
486
495 template<LineConcept OtherLine>
496 [[nodiscard]] constexpr bool contains(const OtherLine& other) const;
497
506 template<SegmentConcept OtherSegment>
507 [[nodiscard]] constexpr bool contains(const OtherSegment& other) const;
508
517 template<OrientedSegmentConcept OtherOrientedSegment>
518 [[nodiscard]] constexpr bool contains(const OtherOrientedSegment& other) const;
519
521 template<OrientedLineConcept OtherOrientedLine>
522 [[nodiscard]] constexpr bool contains(const OtherOrientedLine& other) const;
523
525 template<RayConcept OtherRay>
526 [[nodiscard]] constexpr bool contains(const OtherRay& other) const;
527
529 template<HalfplaneConcept OtherHalfplane>
530 [[nodiscard]] constexpr bool contains(const OtherHalfplane& other) const;
531
533 template<RectangleConcept OtherRectangle>
534 [[nodiscard]] constexpr bool contains(const OtherRectangle& other) const;
535
537 template<TriangleConcept OtherTriangle>
538 [[nodiscard]] constexpr bool contains(const OtherTriangle& other) const;
539
541 template<ConvexConcept OtherConvex>
542 [[nodiscard]] constexpr bool contains(const OtherConvex& other) const;
543
545 template<PolygonConcept OtherPolygon>
546 [[nodiscard]] constexpr bool contains(const OtherPolygon& other) const;
547
549 template<DiskConcept OtherDisk>
550 [[nodiscard]] constexpr bool contains(const OtherDisk& other) const;
551
553 [[nodiscard]] constexpr bool contains(const Shape<PointType>& other) const;
554
556 [[nodiscard]] constexpr bool boundaryContains(const Shape<PointType>& other) const;
557
558 // The empty set is a subset of every shape (contained in all of them) and
559 // disjoint from all of them, so containment is true while separation is
560 // false. These overloads let an EmptyShape flow through Shape's variant
561 // dispatch without special-casing.
563 template <class EmptyPoint>
564 [[nodiscard]] constexpr bool contains(const EmptyShape<EmptyPoint>&) const {
565 return true;
566 }
567
568 template <class EmptyPoint>
569 [[nodiscard]] constexpr bool boundaryContains(const EmptyShape<EmptyPoint>&) const {
570 return true;
571 }
572
573 template <class EmptyPoint>
574 [[nodiscard]] constexpr bool interiorContains(const EmptyShape<EmptyPoint>&) const {
575 return true;
576 }
577
578 template <class EmptyPoint>
579 [[nodiscard]] constexpr bool separates(const EmptyShape<EmptyPoint>&) const {
580 return false;
581 }
582
584 template<PointConcept OtherPoint>
585 [[nodiscard]] constexpr bool interiorContains(const OtherPoint& point) const;
586
588 template<LineConcept OtherLine>
589 [[nodiscard]] constexpr bool interiorContains(const OtherLine& other) const;
590
592 template<SegmentConcept OtherSegment>
593 [[nodiscard]] constexpr bool interiorContains(const OtherSegment& other) const;
594
596 template<OrientedSegmentConcept OtherOrientedSegment>
597 [[nodiscard]] constexpr bool interiorContains(const OtherOrientedSegment& other) const;
598
600 template<OrientedLineConcept OtherOrientedLine>
601 [[nodiscard]] constexpr bool interiorContains(const OtherOrientedLine& other) const;
602
604 template<RayConcept OtherRay>
605 [[nodiscard]] constexpr bool interiorContains(const OtherRay& other) const;
606
608 template<HalfplaneConcept OtherHalfplane>
609 [[nodiscard]] constexpr bool interiorContains(const OtherHalfplane& other) const;
610
612 template<RectangleConcept OtherRectangle>
613 [[nodiscard]] constexpr bool interiorContains(const OtherRectangle& other) const;
614
616 template<TriangleConcept OtherTriangle>
617 [[nodiscard]] constexpr bool interiorContains(const OtherTriangle& other) const;
618
628 template<PointConcept OtherPoint>
629 [[nodiscard]] constexpr bool collinear(const OtherPoint& point) const;
630
639 template<SegmentConcept OtherSegment>
640 [[nodiscard]] constexpr bool collinear(const OtherSegment& other) const;
641
650 template<OrientedSegmentConcept OtherOrientedSegment>
651 [[nodiscard]] constexpr bool collinear(const OtherOrientedSegment& other) const;
652
661 template<LineConcept OtherLine>
662 [[nodiscard]] constexpr bool collinear(const OtherLine& other) const;
663
671 template<OrientedLineConcept OtherOrientedLine>
672 [[nodiscard]] constexpr bool collinear(const OtherOrientedLine& other) const;
673
681 template<RayConcept OtherRay>
682 [[nodiscard]] constexpr bool collinear(const OtherRay& other) const;
683
693 template <class ResultNumber = division_result_t<NumberType>>
694 [[nodiscard]] constexpr ResultNumber slope() const;
695
708 template <class ResultNumber = division_result_t<NumberType>, class OtherNumber>
709 [[nodiscard]] constexpr std::optional<ResultNumber> yAtX(const OtherNumber& x) const;
710
723 template <class ResultNumber = division_result_t<NumberType>, class OtherNumber>
724 [[nodiscard]] constexpr std::optional<ResultNumber> xAtY(const OtherNumber& y) const;
725
733 [[nodiscard]] constexpr Halfplane<PointType> halfplaneAbove() const;
734
742 [[nodiscard]] constexpr Halfplane<PointType> halfplaneBelow() const;
743
752 template<LineConcept OtherLine>
753 [[nodiscard]] constexpr bool parallel(const OtherLine& other) const;
754
763 template<SegmentConcept OtherSegment>
764 [[nodiscard]] constexpr bool parallel(const OtherSegment& other) const;
765
774 template<OrientedSegmentConcept OtherOrientedSegment>
775 [[nodiscard]] constexpr bool parallel(const OtherOrientedSegment& other) const;
776
784 template<OrientedLineConcept OtherOrientedLine>
785 [[nodiscard]] constexpr bool parallel(const OtherOrientedLine& other) const;
786
794 template<RayConcept OtherRay>
795 [[nodiscard]] constexpr bool parallel(const OtherRay& other) const;
796
798 template<PointConcept OtherPoint>
799 [[nodiscard]] constexpr bool intersects(const OtherPoint& other) const;
800
809 template<LineConcept OtherLine>
810 [[nodiscard]] constexpr bool intersects(const OtherLine& other) const;
811
813 template<SegmentConcept OtherSegment>
814 [[nodiscard]] constexpr bool intersects(const OtherSegment& other) const;
815
817 template<OrientedSegmentConcept OtherOrientedSegment>
818 [[nodiscard]] constexpr bool intersects(const OtherOrientedSegment& other) const;
819
821 [[nodiscard]] constexpr bool intersects(const Shape<PointType>& other) const;
822
824 template<typename OtherShape>
825 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Line>)
826 [[nodiscard]] constexpr bool intersects(const OtherShape& other) const {
827 return other.intersects(*this);
828 }
829
831 template <class EmptyPoint>
832 [[nodiscard]] constexpr bool intersects(const EmptyShape<EmptyPoint>&) const {
833 return false;
834 }
835
846 template<PointConcept OtherPoint>
847 [[nodiscard]] constexpr bool interiorsIntersect(const OtherPoint& other) const;
848
850 template<LineConcept OtherLine>
851 [[nodiscard]] constexpr bool interiorsIntersect(const OtherLine& other) const;
852
854 template<SegmentConcept OtherSegment>
855 [[nodiscard]] constexpr bool interiorsIntersect(const OtherSegment& other) const;
856
858 template<OrientedSegmentConcept OtherOrientedSegment>
859 [[nodiscard]] constexpr bool interiorsIntersect(const OtherOrientedSegment& other) const;
860
862 template<typename OtherShape>
863 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Line>)
864 [[nodiscard]] constexpr bool interiorsIntersect(const OtherShape& other) const {
865 return other.interiorsIntersect(*this);
866 }
867
869 template <class EmptyPoint>
870 [[nodiscard]] constexpr bool interiorsIntersect(const EmptyShape<EmptyPoint>&) const {
871 return false;
872 }
873
875 [[nodiscard]] constexpr bool interiorsIntersect(const Shape<PointType>& other) const;
876
885 template<LineConcept OtherLine>
886 [[nodiscard]] constexpr bool crosses(const OtherLine& other) const;
887
889 template<PointConcept OtherPoint>
890 [[nodiscard]] constexpr bool crosses(const OtherPoint& other) const;
891
893 template<SegmentConcept OtherSegment>
894 [[nodiscard]] constexpr bool crosses(const OtherSegment& other) const;
895
897 template<OrientedSegmentConcept OtherOrientedSegment>
898 [[nodiscard]] constexpr bool crosses(const OtherOrientedSegment& other) const;
899
901 template<typename OtherShape>
902 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Line>)
903 [[nodiscard]] constexpr bool crosses(const OtherShape& other) const {
904 return other.crosses(*this);
905 }
906
908 template <class EmptyPoint>
909 [[nodiscard]] constexpr bool crosses(const EmptyShape<EmptyPoint>&) const {
910 return false;
911 }
912
914 [[nodiscard]] constexpr bool crosses(const Shape<PointType>& other) const;
915
917 template<PointConcept OtherPoint>
918 [[nodiscard]] constexpr bool separates(const OtherPoint& other) const;
919
921 template<SegmentConcept OtherSegment>
922 [[nodiscard]] constexpr bool separates(const OtherSegment& other) const;
923
925 template<OrientedSegmentConcept OtherOrientedSegment>
926 [[nodiscard]] constexpr bool separates(const OtherOrientedSegment& other) const;
927
929 template<LineConcept OtherLine>
930 [[nodiscard]] constexpr bool separates(const OtherLine& other) const;
931
933 template<OrientedLineConcept OtherOrientedLine>
934 [[nodiscard]] constexpr bool separates(const OtherOrientedLine& other) const;
935
937 template<RayConcept OtherRay>
938 [[nodiscard]] constexpr bool separates(const OtherRay& other) const;
939
941 template<RectangleConcept OtherRectangle>
942 [[nodiscard]] constexpr bool separates(const OtherRectangle& other) const;
943
945 template<TriangleConcept OtherTriangle>
946 [[nodiscard]] constexpr bool separates(const OtherTriangle& other) const;
947
949 template<HalfplaneConcept OtherHalfplane>
950 [[nodiscard]] constexpr bool separates(const OtherHalfplane& other) const;
951
953 template<ConvexConcept OtherConvex>
954 [[nodiscard]] constexpr bool separates(const OtherConvex& other) const;
955
957 template<DiskConcept OtherDisk>
958 [[nodiscard]] constexpr bool separates(const OtherDisk& other) const;
959
961 template<PolygonConcept OtherPolygon>
962 [[nodiscard]] constexpr bool separates(const OtherPolygon& other) const;
963
965 template<MonotoneChainConcept OtherChain>
966 [[nodiscard]] constexpr bool contains(const OtherChain& other) const;
967
969 template<MonotoneChainConcept OtherChain>
970 [[nodiscard]] constexpr bool boundaryContains(const OtherChain&) const { return false; }
971
973 template<MonotoneChainConcept OtherChain>
974 [[nodiscard]] constexpr bool interiorContains(const OtherChain& other) const;
975
977 template<MonotoneChainConcept OtherChain>
978 [[nodiscard]] constexpr bool separates(const OtherChain& other) const;
979
981 template<PolylineConcept OtherPolyline>
982 [[nodiscard]] constexpr bool contains(const OtherPolyline& other) const;
983
985 template<PolylineConcept OtherPolyline>
986 [[nodiscard]] constexpr bool boundaryContains(const OtherPolyline&) const { return false; }
987
989 template<PolylineConcept OtherPolyline>
990 [[nodiscard]] constexpr bool interiorContains(const OtherPolyline& other) const;
991
993 template<PolylineConcept OtherPolyline>
994 [[nodiscard]] constexpr bool separates(const OtherPolyline& other) const;
995
997 template<HalfplaneIntersectionConcept OtherRegion>
998 [[nodiscard]] constexpr bool contains(const OtherRegion& other) const;
999
1001 template<HalfplaneIntersectionConcept OtherRegion>
1002 [[nodiscard]] constexpr bool boundaryContains(const OtherRegion& other) const;
1003
1005 template<HalfplaneIntersectionConcept OtherRegion>
1006 [[nodiscard]] constexpr bool interiorContains(const OtherRegion& other) const;
1007
1009 template<HalfplaneIntersectionConcept OtherRegion>
1010 [[nodiscard]] constexpr bool separates(const OtherRegion& other) const;
1011
1019 template<PolygonWithHolesConcept OtherRegion>
1020 [[nodiscard]] constexpr bool contains(const OtherRegion& other) const;
1021
1028 template<PolygonWithHolesConcept OtherRegion>
1029 [[nodiscard]] constexpr bool boundaryContains(const OtherRegion& other) const;
1030
1032 template<PolygonWithHolesConcept OtherRegion>
1033 [[nodiscard]] constexpr bool interiorContains(const OtherRegion& other) const;
1034
1042 template<PolygonWithHolesConcept OtherRegion>
1043 [[nodiscard]] bool separates(const OtherRegion& other) const;
1044
1045 // -------------------------------------------------------------------------
1046 // A set of regions
1047 //
1048 // It outranks every other shape, so the symmetric relations reach it through
1049 // the rank-based forwarders and only the asymmetric ones are answered here.
1050 // A set is the union of its components, so it is contained exactly when
1051 // every component is — no matter what this shape is.
1052
1054 template<PolygonSetConcept OtherSet>
1055 [[nodiscard]] constexpr bool contains(const OtherSet& other) const {
1056 for (const auto& component : other) {
1057 if (!contains(component)) {
1058 return false;
1059 }
1060 }
1061 return true;
1062 }
1063
1065 template<PolygonSetConcept OtherSet>
1066 [[nodiscard]] constexpr bool boundaryContains(const OtherSet& other) const {
1067 for (const auto& component : other) {
1068 if (!boundaryContains(component)) {
1069 return false;
1070 }
1071 }
1072 return true;
1073 }
1074
1076 template<PolygonSetConcept OtherSet>
1077 [[nodiscard]] constexpr bool interiorContains(const OtherSet& other) const {
1078 for (const auto& component : other) {
1079 if (!interiorContains(component)) {
1080 return false;
1081 }
1082 }
1083 return true;
1084 }
1085
1094 template<PolygonSetConcept OtherSet>
1095 [[nodiscard]] bool separates(const OtherSet& other) const;
1096
1098 [[nodiscard]] constexpr bool separates(const Shape<PointType>& other) const;
1099
1100 // --- not-yet-implemented predicate pairs (throw); see implementation ---
1102 template<DiskConcept OtherDisk>
1103 [[nodiscard]] constexpr bool interiorContains(const OtherDisk& other) const;
1104
1106 template<ConvexConcept OtherConvex>
1107 [[nodiscard]] constexpr bool interiorContains(const OtherConvex& other) const;
1108
1110 template<PolygonConcept OtherPolygon>
1111 [[nodiscard]] constexpr bool interiorContains(const OtherPolygon& other) const;
1112
1113
1125 template <class ResultNumber = NumberType, PointConcept OtherPoint>
1126 [[nodiscard]] constexpr std::optional<Point<ResultNumber, typename PointType::LabelType>>
1127 intersection(const OtherPoint& other) const;
1128
1130 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
1131 [[nodiscard]] constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>,Line<Point<ResultNumber, typename PointType::LabelType>>>>
1132 intersection(const OtherLine& other) const;
1133
1135 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1136 [[nodiscard]] constexpr auto intersection(const OtherSegment& other) const;
1137
1139 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
1140 [[nodiscard]] constexpr auto intersection(const OtherOrientedSegment& other) const;
1141
1143 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1144 requires (!PointConcept<OtherShape>
1145 && (detail::shapeRank<OtherShape> > detail::shapeRank<Line>)
1146 && requires(const OtherShape& o, const Line& self) {
1147 o.template intersection<ResultNumber>(self);
1148 })
1149 [[nodiscard]] constexpr auto intersection(const OtherShape& other) const {
1150 return other.template intersection<ResultNumber>(*this);
1151 }
1152
1154 template <class ResultNumber = NumberType, class EmptyPoint>
1155 [[nodiscard]] constexpr EmptyShape<EmptyPoint> intersection(const EmptyShape<EmptyPoint>&) const {
1156 return {};
1157 }
1158
1177 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1178 [[nodiscard]] constexpr auto squaredDistance(const OtherPoint& point) const;
1179
1195 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
1196 [[nodiscard]] constexpr auto squaredDistance(const OtherLine& other) const;
1197
1216 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1217 [[nodiscard]] constexpr auto squaredDistance(const OtherSegment& other) const;
1218
1220 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
1221 [[nodiscard]] constexpr auto squaredDistance(const OtherOrientedSegment& other) const;
1222
1229 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1230 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Line>)
1231 && requires(const OtherShape& o, const Line& self) {
1232 o.template squaredDistance<ResultNumber>(self);
1233 })
1234 [[nodiscard]] constexpr auto squaredDistance(const OtherShape& other) const {
1235 return other.template squaredDistance<ResultNumber>(*this);
1236 }
1237
1245 template <class ResultNumber = double, class DiskPointType, class DiskLabel>
1246 [[nodiscard]] detail::floating_result_t<ResultNumber> squaredDistance(const Disk<DiskPointType, DiskLabel>& disk) const {
1247 return disk.template squaredDistance<ResultNumber>(*this);
1248 }
1249
1265 template <class ResultNumber = division_result_t<NumberType>, class OtherShape>
1266 requires detail::ClosestPointsPairConcept<Line<PointType_, TLabel>, OtherShape>
1267 [[nodiscard]] constexpr auto closestPoints(const OtherShape& other) const;
1268
1270 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1271 [[nodiscard]] constexpr auto distanceL1(const OtherPoint& point) const;
1272
1274 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
1275 [[nodiscard]] constexpr auto distanceL1(const OtherLine& other) const;
1276
1278 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1279 [[nodiscard]] constexpr auto distanceL1(const OtherSegment& other) const;
1280
1282 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
1283 [[nodiscard]] constexpr auto distanceL1(const OtherOrientedSegment& other) const;
1284
1291 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1292 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Line>)
1293 && requires(const OtherShape& o, const Line& self) {
1294 o.template distanceL1<ResultNumber>(self);
1295 })
1296 [[nodiscard]] constexpr auto distanceL1(const OtherShape& other) const {
1297 return other.template distanceL1<ResultNumber>(*this);
1298 }
1299
1315 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1316 [[nodiscard]] constexpr auto intersection(const Shape<OtherPoint>& other) const {
1317 return other.template intersection<ResultNumber>(*this);
1318 }
1319
1328 template <class ResultNumber = double, PointConcept OtherPoint>
1329 [[nodiscard]] constexpr auto distanceL1(const Shape<OtherPoint>& other) const {
1330 return other.template distanceL1<ResultNumber>(*this);
1331 }
1332
1334 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1335 [[nodiscard]] constexpr auto distanceLInf(const OtherPoint& point) const;
1336
1338 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
1339 [[nodiscard]] constexpr auto distanceLInf(const OtherLine& other) const;
1340
1342 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1343 [[nodiscard]] constexpr auto distanceLInf(const OtherSegment& other) const;
1344
1346 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
1347 [[nodiscard]] constexpr auto distanceLInf(const OtherOrientedSegment& other) const;
1348
1355 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1356 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Line>)
1357 && requires(const OtherShape& o, const Line& self) {
1358 o.template distanceLInf<ResultNumber>(self);
1359 })
1360 [[nodiscard]] constexpr auto distanceLInf(const OtherShape& other) const {
1361 return other.template distanceLInf<ResultNumber>(*this);
1362 }
1363
1372 template <class ResultNumber = double, PointConcept OtherPoint>
1373 [[nodiscard]] constexpr auto distanceLInf(const Shape<OtherPoint>& other) const {
1374 return other.template distanceLInf<ResultNumber>(*this);
1375 }
1376
1393 template <class OtherShape>
1395 [[nodiscard]] constexpr auto minkowskiSum(const OtherShape& other) const;
1396
1420 template <class OtherShape>
1422 [[nodiscard]] constexpr auto minkowskiErosion(const OtherShape& other) const;
1423
1432 template<PointConcept OtherPoint>
1433 constexpr Line& operator+=(const OtherPoint& translation);
1434
1443 template<PointConcept OtherPoint>
1444 constexpr Line& operator-=(const OtherPoint& translation);
1445
1453 template <class Scalar>
1454 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1455 constexpr Line& operator*=(const Scalar& scalar);
1456
1464 template <class Scalar>
1465 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1466 constexpr Line& operator/=(const Scalar& scalar);
1467
1475 template <class ResultNumber = NumberType>
1476 [[nodiscard]] constexpr Point<ResultNumber> pointInside() const;
1477
1485 template <class OtherShape>
1486 [[nodiscard]] constexpr bool pointInsideInteriorContainedIn(const OtherShape& shape) const;
1487
1488
1495 template<class ResultNumber>
1496 [[nodiscard]] constexpr auto dualCoordinates() const;
1497
1498 private:
1499 template <class OtherNumber>
1500 using promoted_number_t = std::common_type_t<CoordinateType, detail::promoted_number_t<OtherNumber>>;
1501
1502 template<class ResultNumber>
1503 [[nodiscard]] constexpr auto polarCoordinates() const;
1504
1505 std::array<PointType, 2> points_{};
1506 [[no_unique_address]] mutable LabelType label_{};
1507};
1508
1519template <class PointType, class LabelType, class TranslationNumber, class TranslationLabel>
1520constexpr auto operator-(const Line<PointType, LabelType>& line, const Point<TranslationNumber, TranslationLabel>& translation);
1521
1531template <class PointType, class LabelType, class Scalar>
1532 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1533constexpr auto operator*(const Line<PointType, LabelType>& line, const Scalar& scalar);
1534
1544template <class Scalar, class PointType, class LabelType>
1545 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1546constexpr auto operator*(const Scalar& scalar, const Line<PointType, LabelType>& line);
1547
1557template <class PointType, class LabelType, class Scalar>
1558 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1559constexpr auto operator/(const Line<PointType, LabelType>& line, const Scalar& scalar);
1560
1569template <class PointType, class LabelType>
1570std::ostream& operator<<(std::ostream& stream, const Line<PointType, LabelType>& line);
1571
1572} // namespace pgl
Shape pairs whose Minkowski sum Pangolin can represent.
Definition forward.hpp:476
Definition forward.hpp:306
Definition forward.hpp:324
Public declaration of pgl::Halfplane.
Definition arrangement.hpp:67
HalfplaneIntersection() -> HalfplaneIntersection< Point<>, NoLabel >
Definition halfplaneintersection.hpp:2308
@ y
Definition intervaltree.hpp:24
@ x
Definition intervaltree.hpp:24
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
OrientedLine() -> OrientedLine< Point<>, NoLabel >
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
Closed half-plane defined by an oriented boundary line.
Definition halfplane.hpp:51
Unoriented infinite line.
Definition line.hpp:52
constexpr bool separates(const OtherDisk &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:878
constexpr Point< ResultNumber > pointInside() const
Returns a point inside the line.
Definition measures.hpp:197
constexpr bool boundaryContains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:569
constexpr bool isHorizontal() const
Returns whether the line is horizontal.
Definition predicates.hpp:466
constexpr bool boundaryContains(const OtherHalfplane &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:456
constexpr Line(PointType first, PointType second)
Creates a line from two defining points.
Definition line.hpp:73
constexpr bool boundaryContains(const OtherRegion &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1656
constexpr bool interiorsIntersect(const EmptyShape< EmptyPoint > &) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition line.hpp:870
constexpr auto intersection(const OtherOrientedSegment &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition intersection.hpp:270
constexpr bool parallel(const OtherSegment &other) const
Returns whether a segment is parallel to this line.
Definition predicates.hpp:514
constexpr bool contains(const OtherConvex &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:493
constexpr bool boundaryContains(const OtherRectangle &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:459
constexpr bool interiorContains(const OtherSet &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition line.hpp:1077
constexpr bool contains(const OtherPoint &point) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:428
constexpr bool boundaryContains(const OtherSet &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:1066
constexpr EmptyShape< EmptyPoint > intersection(const EmptyShape< EmptyPoint > &) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition line.hpp:1155
constexpr auto distanceL1(const OtherPoint &point) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:269
constexpr auto cend() const
Returns an iterator past the last defining point.
Definition line.hpp:225
constexpr bool interiorContains(const OtherRegion &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
constexpr auto dualCoordinates() const
Returns normalized dual-line coordinates for the supporting line.
Definition duality.hpp:69
constexpr bool separates(const EmptyShape< EmptyPoint > &) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition line.hpp:579
constexpr bool crosses(const EmptyShape< EmptyPoint > &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition line.hpp:909
constexpr bool separates(const OtherOrientedLine &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:824
constexpr bool boundaryContains(const OtherRegion &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
constexpr bool contains(const OtherTriangle &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:487
constexpr bool contains(const Shape< PointType > &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:515
constexpr bool contains(const OtherOrientedLine &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:455
constexpr bool boundaryContains(const OtherTriangle &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:462
constexpr bool separates(const OtherChain &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:3161
constexpr void rotate90(int k=1)
Rotates the line by 90k degrees around the origin in place.
Definition transformations.hpp:510
constexpr bool interiorsIntersect(const OtherShape &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition line.hpp:864
constexpr const PointType & max() const
Returns the largest stored defining point.
Definition line.hpp:189
constexpr auto minkowskiErosion(const OtherShape &other) const
Returns the Minkowski erosion of this shape by another (A ⊖ B).
Definition minkowskierosion.hpp:629
constexpr bool contains(const OtherPolygon &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1723
constexpr A & label() const
Definition line.hpp:262
constexpr bool collinear(const OtherOrientedLine &other) const
Returns whether an oriented line is collinear with this line.
Definition predicates.hpp:538
constexpr bool boundaryContains(const OtherChain &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:970
constexpr auto squaredDistance(const OtherOrientedSegment &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:258
constexpr bool boundaryContains(const OtherPoint &point) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:228
constexpr bool collinear(const OtherOrientedSegment &other) const
Returns whether the given oriented segment is collinear with the line.
Definition predicates.hpp:496
constexpr Line scaledDownX(const OtherNumber scalar) const
Returns the line with its x-coordinates divided by a divisor.
constexpr Segment< PointType > asSegmentFor(const Rectangle< OtherPoint > &rect) const
Returns the segment that intersects r the same way as this line.
Definition line.hpp:277
constexpr bool interiorsIntersect(const OtherSegment &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:341
PointType PointType
Definition line.hpp:53
constexpr bool crosses(const OtherOrientedSegment &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:232
constexpr bool samePointSet(const OtherShape &other) const
Tests whether another shape defines exactly the same point set.
Definition samepointset.hpp:1959
constexpr auto begin() const
Returns an iterator to the first defining point.
Definition line.hpp:198
constexpr bool intersects(const OtherLine &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:318
constexpr auto distanceLInf(const OtherOrientedSegment &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:285
constexpr bool interiorContains(const OtherChain &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1476
constexpr Line(PointType first, PointType second, A &&label)
Creates a line from two defining points and stores a label.
Definition line.hpp:101
constexpr bool isUndefined() const
Returns whether the line is degenerate without collapsing to a point or to a segment.
Definition predicates.hpp:456
constexpr bool isVertical() const
Returns whether the line is vertical.
Definition predicates.hpp:461
constexpr bool interiorContains(const OtherRectangle &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:365
constexpr bool interiorsIntersect(const OtherLine &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:335
constexpr bool collinear(const OtherPoint &point) const
Returns whether the line interior contains the given point.
Definition predicates.hpp:484
constexpr auto distanceL1(const OtherShape &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition line.hpp:1296
constexpr bool separates(const OtherHalfplane &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:863
constexpr bool parallel(const OtherLine &other) const
Returns whether another line is parallel to this line.
Definition predicates.hpp:508
constexpr bool intersects(const OtherOrientedSegment &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:343
constexpr const PointType & min() const
Returns the smallest stored defining point.
Definition line.hpp:180
constexpr bool intersects(const OtherPoint &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:312
constexpr bool contains(const OtherChain &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2021
constexpr auto closestPoints(const OtherShape &other) const
Returns the pair of points realizing the distance, nothing when the shapes meet.
Definition closest.hpp:454
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:203
constexpr bool interiorContains(const OtherLine &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:329
constexpr auto distanceL1(const OtherLine &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:276
constexpr bool interiorContains(const OtherRay &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:353
constexpr bool separates(const OtherRectangle &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:844
constexpr bool separates(const OtherPoint &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:794
detail::floating_result_t< ResultNumber > squaredDistance(const Disk< DiskPointType, DiskLabel > &disk) const
Returns the squared Euclidean distance to a disk.
Definition line.hpp:1246
constexpr bool contains(const OtherRay &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:461
PointType::NumberType NumberType
Definition line.hpp:54
constexpr bool crosses(const OtherShape &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition line.hpp:903
constexpr ResultNumber slope() const
Returns the slope of the line.
Definition measures.hpp:189
constexpr Halfplane< PointType > halfplaneAbove() const
Returns the half-plane geometrically above this line.
Definition predicates.hpp:549
constexpr bool boundaryContains(const Shape< PointType > &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1098
constexpr Line scaledUpY(const OtherNumber scalar) const
Returns the line with its y-coordinates multiplied by a factor.
constexpr bool boundaryContains(const OtherRay &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:453
constexpr auto squaredDistance(const OtherPoint &point) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:219
constexpr bool separates(const OtherSegment &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:800
constexpr void scaleUpX(const OtherNumber scalar)
Multiplies the line's x-coordinates by a factor in place.
Definition transformations.hpp:524
constexpr std::optional< ResultNumber > xAtY(const OtherNumber &y) const
Returns the x-coordinate of the line at a given y-coordinate, if defined.
Definition atxy.hpp:168
constexpr ResultNumber area() const
Returns the area of the line.
Definition measures.hpp:178
constexpr bool separates(const OtherRegion &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:4591
constexpr bool crosses(const OtherSegment &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:226
constexpr bool crosses(const Shape< PointType > &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:237
constexpr bool crosses(const OtherLine &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:211
constexpr auto distanceL1(const OtherSegment &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:285
constexpr std::optional< ResultNumber > yAtX(const OtherNumber &x) const
Returns the y-coordinate of the line at a given x-coordinate, if defined.
Definition atxy.hpp:130
constexpr bool separates(const Shape< PointType > &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:886
constexpr bool contains(const OtherSegment &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:443
constexpr auto minkowskiSum(const OtherShape &other) const
Returns the Minkowski sum of this shape and another (A ⊕ B).
Definition minkowski.hpp:796
constexpr Line rotated90(int k=1) const
Returns the line rotated by 90k degrees around the origin.
Definition transformations.hpp:505
constexpr bool interiorContains(const OtherOrientedLine &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:347
constexpr bool interiorContains(const OtherOrientedSegment &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:341
constexpr bool contains(const OtherRegion &other) const
Tests whether this shape contains the other shape (A ⊇ B).
detail::promoted_number_t< NumberType > CoordinateType
Definition line.hpp:56
constexpr bool intersects(const Shape< PointType > &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:348
constexpr auto distanceLInf(const OtherShape &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition line.hpp:1360
constexpr bool interiorsIntersect(const Shape< PointType > &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:365
static constexpr std::size_t size()
Returns the number of defining points (always 2).
Definition line.hpp:149
bool separates(const OtherRegion &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:5665
constexpr bool collinear(const OtherLine &other) const
Returns whether another line is collinear with this line.
Definition predicates.hpp:502
constexpr auto distanceLInf(const OtherPoint &point) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:257
constexpr bool interiorsIntersect(const OtherPoint &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:328
constexpr bool boundaryContains(const OtherPolygon &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:468
constexpr bool contains(const OtherDisk &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:507
constexpr auto distanceLInf(const OtherLine &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:264
constexpr bool contains(const OtherRectangle &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:473
constexpr bool boundaryContains(const OtherDisk &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:471
constexpr auto distanceL1(const OtherOrientedSegment &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:297
constexpr bool verticesContain(const OtherPoint &point) const
Returns whether the given point is one of the stored defining points.
Definition predicates.hpp:478
constexpr bool interiorContains(const OtherPoint &point) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:323
constexpr Line()=default
Creates the degenerate line (0,0)--(0,0).
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 line.hpp:1373
constexpr bool separates(const OtherConvex &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:869
bool separates(const OtherSet &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:5927
constexpr bool separates(const OtherPolygon &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:2009
constexpr Point< ResultNumber, typename PointType::LabelType > polar() const
Returns the polar point.
Definition duality.hpp:125
constexpr bool contains(const OtherPolyline &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2383
constexpr bool boundaryContains(const OtherPolyline &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:986
constexpr Line(NumberType x1, NumberType y1, NumberType x2, NumberType y2, A &&label)
Same as the four-coordinate constructor, and stores a label.
Definition line.hpp:109
constexpr bool crosses(const OtherPoint &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:220
constexpr bool parallel(const OtherOrientedSegment &other) const
Returns whether an oriented segment is parallel to this line.
Definition predicates.hpp:520
constexpr void scaleDownY(const OtherNumber scalar)
Divides the line's y-coordinates by a divisor in place.
Definition transformations.hpp:566
constexpr Point< ResultNumber, typename PointType::LabelType > dual() const
Returns the dual point.
Definition duality.hpp:109
constexpr bool boundaryContains(const OtherLine &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:447
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 line.hpp:157
constexpr Line(const Line< OtherPointType, OtherLabelType > &other)
Converts a line with a different point and/or label type.
Definition line.hpp:120
constexpr HalfplaneIntersection< PointType > asHalfplaneIntersection() const
Returns the line as a (degenerate) half-plane intersection.
Definition line.hpp:289
constexpr bool boundaryContains(const OtherOrientedSegment &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:444
constexpr auto end() const
Returns an iterator past the last defining point.
Definition line.hpp:216
constexpr bool interiorContains(const OtherHalfplane &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:359
constexpr bool parallel(const OtherOrientedLine &other) const
Returns whether an oriented line is parallel to this line.
Definition predicates.hpp:526
constexpr auto squaredDistance(const OtherLine &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:236
constexpr bool interiorContains(const OtherSegment &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:335
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:203
constexpr bool interiorsIntersect(const OtherOrientedSegment &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:360
constexpr bool boundaryContains(const OtherSegment &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:441
constexpr bool collinear(const OtherRay &other) const
Returns whether a ray is collinear with this line.
Definition predicates.hpp:544
constexpr auto cbegin() const
Returns an iterator to the first defining point.
Definition line.hpp:207
constexpr bool boundaryContains(const OtherOrientedLine &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:450
constexpr bool boundaryContains(const OtherConvex &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition line.hpp:465
constexpr bool intersects(const EmptyShape< EmptyPoint > &) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition line.hpp:832
constexpr bool interiorContains(const OtherPolygon &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1246
constexpr std::ptrdiff_t index(const PointType &point) const
Definition line.hpp:166
constexpr void scaleDownX(const OtherNumber scalar)
Divides the line's x-coordinates by a divisor in place.
Definition transformations.hpp:552
constexpr auto squaredDistance(const OtherShape &other) const
Returns the squared Euclidean distance to the given shape.
Definition line.hpp:1234
constexpr bool separates(const OtherTriangle &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:854
constexpr auto squaredDistance(const OtherSegment &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:246
constexpr Line & operator+=(const OtherPoint &translation)
Translates both defining points in place.
constexpr bool interiorContains(const OtherRegion &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:2063
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Line< Point< ResultNumber, typename PointType::LabelType > > > > intersection(const OtherLine &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition intersection.hpp:216
constexpr bool interiorContains(const OtherTriangle &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:376
constexpr bool separates(const OtherRay &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:830
constexpr auto intersection(const OtherSegment &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition intersection.hpp:249
constexpr Line scaledUpX(const OtherNumber scalar) const
Returns the line with its x-coordinates multiplied by a factor.
constexpr NumberType twiceArea() const
Returns twice the area of the line.
Definition measures.hpp:183
constexpr bool interiorContains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition line.hpp:574
constexpr bool contains(const OtherSet &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition line.hpp:1055
constexpr Line(NumberType x1, NumberType y1, NumberType x2, NumberType y2)
Creates a line from four coordinates.
Definition line.hpp:89
constexpr bool separates(const OtherOrientedSegment &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:811
constexpr bool contains(const OtherHalfplane &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:467
constexpr bool contains(const OtherLine &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:437
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 line.hpp:1329
constexpr bool interiorContains(const OtherConvex &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:382
constexpr bool separates(const OtherPolyline &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:3966
constexpr bool intersects(const OtherSegment &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:330
constexpr auto distanceLInf(const OtherSegment &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:273
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 line.hpp:1316
constexpr bool isDegenerate() const
Returns whether the defining points coincide.
Definition predicates.hpp:451
constexpr bool separates(const OtherLine &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:817
constexpr Halfplane< PointType > halfplaneBelow() const
Returns the half-plane geometrically below this line.
Definition predicates.hpp:554
constexpr const PointType & operator[](std::size_t index) const
Returns defining point 0 or 1.
Definition line.hpp:141
constexpr bool contains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition line.hpp:564
TLabel LabelType
Definition line.hpp:55
constexpr bool parallel(const OtherRay &other) const
Returns whether a ray is parallel to this line.
Definition predicates.hpp:532
constexpr bool collinear(const OtherSegment &other) const
Returns whether the given segment is collinear with the line.
Definition predicates.hpp:490
constexpr bool interiorContains(const OtherDisk &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1238
constexpr auto operator<=>(const Line &other) const
Provides an ordering compatible with geometric equality.
Definition predicates.hpp:428
constexpr bool contains(const OtherRegion &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2758
constexpr auto intersection(const OtherShape &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition line.hpp:1149
constexpr bool contains(const OtherOrientedSegment &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:449
constexpr void scaleUpY(const OtherNumber scalar)
Multiplies the line's y-coordinates by a factor in place.
Definition transformations.hpp:538
constexpr bool interiorContains(const OtherPolyline &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1699
constexpr bool intersects(const OtherShape &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition line.hpp:826
constexpr bool operator==(const Line &other) const
Tests geometric equality of two lines.
Definition predicates.hpp:423
constexpr Line scaledDownY(const OtherNumber scalar) const
Returns the line with its y-coordinates divided by a divisor.
constexpr Line & operator-=(const OtherPoint &translation)
Translates both defining points by the opposite vector in place.
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
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
Runtime variant wrapper over the supported primitive shapes.
Definition shape.hpp:160