Pangolin
Header-only C++20 plane computational geometry library
Loading...
Searching...
No Matches
ray.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 <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 Ray;
30
32
33template <class PointType>
34Ray(PointType, PointType) -> Ray<PointType, NoLabel>;
35
36template <class PointType, class A>
37Ray(PointType, PointType, A) -> Ray<PointType, std::decay_t<A>>;
38
39template <class Number>
40Ray(Number, Number, Number, Number) -> Ray<Point<Number>, NoLabel>;
41
50template <class PointType_, class TLabel>
51struct Ray {
52 using PointType = PointType_;
53 using NumberType = PointType::NumberType;
54 using LabelType = TLabel;
55 using CoordinateType = detail::promoted_number_t<NumberType>;
56
57 static_assert(detail::is_point_v<PointType>, "Ray requires pgl::Point defining points");
58
62 constexpr Ray() = default;
63
73 : points_{std::move(source), std::move(target)} {}
74
83 constexpr Ray(NumberType x1, NumberType y1, NumberType x2, NumberType y2)
84 : Ray(PointType(x1, y1), PointType(x2, y2)) {}
85
93 template <class A>
94 requires(detail::has_label_v<LabelType> && std::constructible_from<LabelType, A&&>)
96 : points_{std::move(source), std::move(target)}, label_(std::forward<A>(label)) {}
97
99 template <class A>
100 requires(detail::has_label_v<LabelType> && std::constructible_from<LabelType, A&&>)
101 constexpr Ray(NumberType x1, NumberType y1, NumberType x2, NumberType y2, A&& label)
102 : Ray(PointType(x1, y1), PointType(x2, y2), std::forward<A>(label)) {}
103
110 template<PointConcept OtherPointType, class OtherLabelType>
111 requires(std::constructible_from<PointType, const OtherPointType&>)
113 : Ray(PointType(other.source()), PointType(other.target())) {
114 label_ = detail::copyLabel<LabelType>(other);
115 }
116
118 template<PointConcept OtherPointType, class OtherLabelType>
119 requires(std::constructible_from<PointType, const OtherPointType&>)
120 constexpr Ray& operator=(const Ray<OtherPointType, OtherLabelType>& other) {
121 points_[0] = PointType(other.source());
122 points_[1] = PointType(other.target());
123 label_ = detail::copyLabel<LabelType>(other);
124 return *this;
125 }
126
133 constexpr const PointType& operator[](std::size_t index) const {
134 assert(index < size());
135 return points_[index];
136 }
137
138 constexpr PointType& operator[](std::size_t index) {
139 assert(index < size());
140 return points_[index];
141 }
142
146 static constexpr std::size_t size() {
147 return 2;
148 }
149
154 constexpr const PointType& get(std::ptrdiff_t index) const {
155 const std::ptrdiff_t n = static_cast<std::ptrdiff_t>(size());
156 return (*this)[static_cast<std::size_t>(((index % n) + n) % n)];
157 }
158 constexpr PointType& get(std::ptrdiff_t index) {
159 const std::ptrdiff_t n = static_cast<std::ptrdiff_t>(size());
160 return (*this)[static_cast<std::size_t>(((index % n) + n) % n)];
161 }
162
167 constexpr std::ptrdiff_t index(const PointType& point) const {
168 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(size()); ++i) {
169 if ((*this)[static_cast<std::size_t>(i)] == point) {
170 return i;
171 }
172 }
173 return -1;
174 }
175
181 constexpr const PointType& source() const {
182 return points_[0];
183 }
184 constexpr PointType& source() {
185 return points_[0];
186 }
187
193 constexpr const PointType& target() const {
194 return points_[1];
195 }
196 constexpr PointType& target() {
197 return points_[1];
198 }
199
205 constexpr const PointType& min() const {
206 return target() < source() ? target() : source();
207 }
208
214 constexpr const PointType& max() const {
215 return source() < target() ? target() : source();
216 }
217
223 constexpr Ray opposite() const {
224 return Ray(target(), source());
225 }
226
232 constexpr auto begin() const {
233 return points_.cbegin();
234 }
235 constexpr auto begin() {
236 return points_.begin();
237 }
238
244 constexpr auto cbegin() const {
245 return points_.cbegin();
246 }
247
253 constexpr auto end() const {
254 return points_.cend();
255 }
256 constexpr auto end() {
257 return points_.end();
258 }
259
265 constexpr auto cend() const {
266 return points_.cend();
267 }
268
278 [[nodiscard]] constexpr bool operator==(const Ray& other) const;
279
281 template<AnyShapeConcept OtherShape>
282 [[nodiscard]] constexpr bool samePointSet(const OtherShape& other) const;
283
291 [[nodiscard]] constexpr auto operator<=>(const Ray& other) const;
292
301 template <class A = LabelType>
302 requires(detail::has_label_v<A>)
303 constexpr A& label() const {
304 return label_;
305 }
306
312 [[nodiscard]] constexpr explicit operator Line<PointType>() const;
313
319 [[nodiscard]] constexpr Line<PointType> asLine() const {
320 return static_cast<Line<PointType>>(*this);
321 }
322
328 [[nodiscard]] constexpr explicit operator OrientedLine<PointType>() const;
329
335 [[nodiscard]] constexpr OrientedLine<PointType> asOrientedLine() const {
336 return static_cast<OrientedLine<PointType>>(*this);
337 }
338
345 [[nodiscard]] constexpr Ray rotated90(int k = 1) const;
346
352 constexpr void rotate90(int k = 1);
353
355 template <class OtherNumber>
356 [[nodiscard]] constexpr Ray scaledUpX(const OtherNumber scalar) const;
357
359 template <class OtherNumber>
360 constexpr void scaleUpX(const OtherNumber scalar);
361
363 template <class OtherNumber>
364 [[nodiscard]] constexpr Ray scaledUpY(const OtherNumber scalar) const;
365
367 template <class OtherNumber>
368 constexpr void scaleUpY(const OtherNumber scalar);
369
371 template <class OtherNumber>
372 [[nodiscard]] constexpr Ray scaledDownX(const OtherNumber scalar) const;
373
375 template <class OtherNumber>
376 constexpr void scaleDownX(const OtherNumber scalar);
377
379 template <class OtherNumber>
380 [[nodiscard]] constexpr Ray scaledDownY(const OtherNumber scalar) const;
381
383 template <class OtherNumber>
384 constexpr void scaleDownY(const OtherNumber scalar);
385
394 template <class ResultNumber = NumberType>
395 [[nodiscard]] constexpr ResultNumber area() const;
396
404 [[nodiscard]] constexpr NumberType twiceArea() const;
405
411 [[nodiscard]] constexpr bool isDegenerate() const;
412
424 [[nodiscard]] constexpr bool isUndefined() const;
425
431 [[nodiscard]] constexpr bool isVertical() const;
432
438 [[nodiscard]] constexpr bool isHorizontal() const;
439
441 template<PointConcept OtherPoint>
442 [[nodiscard]] constexpr bool verticesContain(const OtherPoint& point) const;
443
445 template<PointConcept OtherPoint>
446 [[nodiscard]] constexpr bool boundaryContains(const OtherPoint& point) const;
447
448 // A ray's boundary is its source point alone, so it boundary-contains no
449 // positive-length or two-dimensional shape.
451 template<SegmentConcept OtherSegment>
452 [[nodiscard]] constexpr bool boundaryContains(const OtherSegment& other) const {
453 return detail::reduceDegenerateToPoint(
454 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
455 }
456
457 template<OrientedSegmentConcept OtherOrientedSegment>
458 [[nodiscard]] constexpr bool boundaryContains(const OtherOrientedSegment& other) const {
459 return detail::reduceDegenerateToPoint(
460 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
461 }
462
463 template<LineConcept OtherLine>
464 [[nodiscard]] constexpr bool boundaryContains(const OtherLine&) const { return false; }
466 template<OrientedLineConcept OtherOrientedLine>
467 [[nodiscard]] constexpr bool boundaryContains(const OtherOrientedLine&) const { return false; }
469 template<RayConcept OtherRay>
470 [[nodiscard]] constexpr bool boundaryContains(const OtherRay&) const { return false; }
472 template<HalfplaneConcept OtherHalfplane>
473 [[nodiscard]] constexpr bool boundaryContains(const OtherHalfplane&) const { return false; }
475 template<RectangleConcept OtherRectangle>
476 [[nodiscard]] constexpr bool boundaryContains(const OtherRectangle& other) const {
477 return detail::reduceDegenerateToPoint(
478 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
479 }
480
481 template<TriangleConcept OtherTriangle>
482 [[nodiscard]] constexpr bool boundaryContains(const OtherTriangle& other) const {
483 return detail::reduceDegenerateToPoint(
484 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
485 }
486
487 template<ConvexConcept OtherConvex>
488 [[nodiscard]] constexpr bool boundaryContains(const OtherConvex& other) const {
489 return detail::reduceDegenerateToPoint(
490 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
491 }
492
493 template<PolygonConcept OtherPolygon>
494 [[nodiscard]] constexpr bool boundaryContains(const OtherPolygon& other) const {
495 return detail::reduceDegenerateToPoint(
496 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
497 }
498
499 template<DiskConcept OtherDisk>
500 [[nodiscard]] constexpr bool boundaryContains(const OtherDisk& other) const {
501 return detail::reduceDegenerateToPoint(
502 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
503 }
504
516 template<PointConcept OtherPoint>
517 [[nodiscard]] constexpr bool containsCollinear(const OtherPoint& point) const;
518
520 template<PointConcept OtherPoint>
521 [[nodiscard]] constexpr bool contains(const OtherPoint& point) const;
522
524 template<LineConcept OtherLine>
525 [[nodiscard]] constexpr bool contains(const OtherLine& other) const;
526
528 template<OrientedLineConcept OtherOrientedLine>
529 [[nodiscard]] constexpr bool contains(const OtherOrientedLine& other) const;
530
532 template<SegmentConcept OtherSegment>
533 [[nodiscard]] constexpr bool contains(const OtherSegment& other) const;
534
536 template<OrientedSegmentConcept OtherOrientedSegment>
537 [[nodiscard]] constexpr bool contains(const OtherOrientedSegment& other) const;
538
540 template<RayConcept OtherRay>
541 [[nodiscard]] constexpr bool contains(const OtherRay& other) const;
542
544 template<HalfplaneConcept OtherHalfplane>
545 [[nodiscard]] constexpr bool contains(const OtherHalfplane& other) const;
546
548 template<RectangleConcept OtherRectangle>
549 [[nodiscard]] constexpr bool contains(const OtherRectangle& other) const;
550
552 template<TriangleConcept OtherTriangle>
553 [[nodiscard]] constexpr bool contains(const OtherTriangle& other) const;
554
556 template<ConvexConcept OtherConvex>
557 [[nodiscard]] constexpr bool contains(const OtherConvex& other) const;
558
560 template<PolygonConcept OtherPolygon>
561 [[nodiscard]] constexpr bool contains(const OtherPolygon& other) const;
562
564 template<DiskConcept OtherDisk>
565 [[nodiscard]] constexpr bool contains(const OtherDisk& other) const;
566
568 [[nodiscard]] constexpr bool contains(const Shape<PointType>& other) const;
569
571 [[nodiscard]] constexpr bool boundaryContains(const Shape<PointType>& other) const;
572
573 // The empty set is a subset of every shape (contained in all of them) and
574 // disjoint from all of them, so containment is true while separation is
575 // false. These overloads let an EmptyShape flow through Shape's variant
576 // dispatch without special-casing.
578 template <class EmptyPoint>
579 [[nodiscard]] constexpr bool contains(const EmptyShape<EmptyPoint>&) const {
580 return true;
581 }
582
583 template <class EmptyPoint>
584 [[nodiscard]] constexpr bool boundaryContains(const EmptyShape<EmptyPoint>&) const {
585 return true;
586 }
587
588 template <class EmptyPoint>
589 [[nodiscard]] constexpr bool interiorContains(const EmptyShape<EmptyPoint>&) const {
590 return true;
591 }
592
593 template <class EmptyPoint>
594 [[nodiscard]] constexpr bool separates(const EmptyShape<EmptyPoint>&) const {
595 return false;
596 }
597
599 template<PointConcept OtherPoint>
600 [[nodiscard]] constexpr bool interiorContains(const OtherPoint& point) const;
601
603 template<LineConcept OtherLine>
604 [[nodiscard]] constexpr bool interiorContains(const OtherLine& other) const;
605
607 template<OrientedLineConcept OtherOrientedLine>
608 [[nodiscard]] constexpr bool interiorContains(const OtherOrientedLine& other) const;
609
611 template<SegmentConcept OtherSegment>
612 [[nodiscard]] constexpr bool interiorContains(const OtherSegment& other) const;
613
615 template<OrientedSegmentConcept OtherOrientedSegment>
616 [[nodiscard]] constexpr bool interiorContains(const OtherOrientedSegment& other) const;
617
619 template<RayConcept OtherRay>
620 [[nodiscard]] constexpr bool interiorContains(const OtherRay& other) const;
621
623 template<HalfplaneConcept OtherHalfplane>
624 [[nodiscard]] constexpr bool interiorContains(const OtherHalfplane& other) const;
625
627 template<RectangleConcept OtherRectangle>
628 [[nodiscard]] constexpr bool interiorContains(const OtherRectangle& other) const;
629
631 template<TriangleConcept OtherTriangle>
632 [[nodiscard]] constexpr bool interiorContains(const OtherTriangle& other) const;
633
635 template<PointConcept OtherPoint>
636 [[nodiscard]] constexpr bool collinear(const OtherPoint& point) const;
637
639 template<LineConcept OtherLine>
640 [[nodiscard]] constexpr bool collinear(const OtherLine& other) const;
641
643 template<OrientedLineConcept OtherOrientedLine>
644 [[nodiscard]] constexpr bool collinear(const OtherOrientedLine& other) const;
645
647 template<SegmentConcept OtherSegment>
648 [[nodiscard]] constexpr bool collinear(const OtherSegment& other) const;
649
651 template<OrientedSegmentConcept OtherOrientedSegment>
652 [[nodiscard]] constexpr bool collinear(const OtherOrientedSegment& other) const;
653
655 template<RayConcept OtherRay>
656 [[nodiscard]] constexpr bool collinear(const OtherRay& other) const;
657
669 template<PointConcept OtherPoint>
670 [[nodiscard]] constexpr std::partial_ordering orientation(const OtherPoint& point) const;
671
680 template <class ResultNumber = division_result_t<NumberType>>
681 [[nodiscard]] constexpr ResultNumber slope() const;
682
691 [[nodiscard]] constexpr Halfplane<PointType> halfplaneAbove() const;
692
701 [[nodiscard]] constexpr Halfplane<PointType> halfplaneBelow() const;
702
708 [[nodiscard]] constexpr Halfplane<PointType> rightHalfplane() const;
709
715 [[nodiscard]] constexpr Halfplane<PointType> leftHalfplane() const;
716
718 template<LineConcept OtherLine>
719 [[nodiscard]] constexpr bool parallel(const OtherLine& other) const;
720
722 template<OrientedLineConcept OtherOrientedLine>
723 [[nodiscard]] constexpr bool parallel(const OtherOrientedLine& other) const;
724
726 template<SegmentConcept OtherSegment>
727 [[nodiscard]] constexpr bool parallel(const OtherSegment& other) const;
728
730 template<OrientedSegmentConcept OtherOrientedSegment>
731 [[nodiscard]] constexpr bool parallel(const OtherOrientedSegment& other) const;
732
734 template<RayConcept OtherRay>
735 [[nodiscard]] constexpr bool parallel(const OtherRay& other) const;
736
738 template<PointConcept OtherPoint>
739 [[nodiscard]] constexpr bool intersects(const OtherPoint& other) const;
740
742 template<LineConcept OtherLine>
743 [[nodiscard]] constexpr bool intersects(const OtherLine& other) const;
744
746 template<OrientedLineConcept OtherOrientedLine>
747 [[nodiscard]] constexpr bool intersects(const OtherOrientedLine& other) const;
748
750 template<SegmentConcept OtherSegment>
751 [[nodiscard]] constexpr bool intersects(const OtherSegment& other) const;
752
754 template<OrientedSegmentConcept OtherOrientedSegment>
755 [[nodiscard]] constexpr bool intersects(const OtherOrientedSegment& other) const;
756
758 template<RayConcept OtherRay>
759 [[nodiscard]] constexpr bool intersects(const OtherRay& other) const;
760
762 [[nodiscard]] constexpr bool intersects(const Shape<PointType>& other) const;
763
765 template<typename OtherShape>
766 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Ray>)
767 [[nodiscard]] constexpr bool intersects(const OtherShape& other) const {
768 return other.intersects(*this);
769 }
770
772 template <class EmptyPoint>
773 [[nodiscard]] constexpr bool intersects(const EmptyShape<EmptyPoint>&) const {
774 return false;
775 }
776
778 template<PointConcept OtherPoint>
779 [[nodiscard]] constexpr bool interiorsIntersect(const OtherPoint& other) const;
780
782 template<LineConcept OtherLine>
783 [[nodiscard]] constexpr bool interiorsIntersect(const OtherLine& other) const;
784
786 template<OrientedLineConcept OtherOrientedLine>
787 [[nodiscard]] constexpr bool interiorsIntersect(const OtherOrientedLine& other) const;
788
790 template<SegmentConcept OtherSegment>
791 [[nodiscard]] constexpr bool interiorsIntersect(const OtherSegment& other) const;
792
794 template<OrientedSegmentConcept OtherOrientedSegment>
795 [[nodiscard]] constexpr bool interiorsIntersect(const OtherOrientedSegment& other) const;
796
798 template<RayConcept OtherRay>
799 [[nodiscard]] constexpr bool interiorsIntersect(const OtherRay& other) const;
800
802 template<typename OtherShape>
803 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Ray>)
804 [[nodiscard]] constexpr bool interiorsIntersect(const OtherShape& other) const {
805 return other.interiorsIntersect(*this);
806 }
807
809 template <class EmptyPoint>
810 [[nodiscard]] constexpr bool interiorsIntersect(const EmptyShape<EmptyPoint>&) const {
811 return false;
812 }
813
815 [[nodiscard]] constexpr bool interiorsIntersect(const Shape<PointType>& other) const;
816
818 template<LineConcept OtherLine>
819 [[nodiscard]] constexpr bool crosses(const OtherLine& other) const;
820
822 template<OrientedLineConcept OtherOrientedLine>
823 [[nodiscard]] constexpr bool crosses(const OtherOrientedLine& other) const;
824
826 template<SegmentConcept OtherSegment>
827 [[nodiscard]] constexpr bool crosses(const OtherSegment& other) const;
828
830 template<OrientedSegmentConcept OtherOrientedSegment>
831 [[nodiscard]] constexpr bool crosses(const OtherOrientedSegment& other) const;
832
834 template<RayConcept OtherRay>
835 [[nodiscard]] constexpr bool crosses(const OtherRay& other) const;
836
838 template<PointConcept OtherPoint>
839 [[nodiscard]] constexpr bool crosses(const OtherPoint& other) const;
840
842 template<typename OtherShape>
843 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Ray>)
844 [[nodiscard]] constexpr bool crosses(const OtherShape& other) const {
845 return other.crosses(*this);
846 }
847
849 template <class EmptyPoint>
850 [[nodiscard]] constexpr bool crosses(const EmptyShape<EmptyPoint>&) const {
851 return false;
852 }
853
855 [[nodiscard]] constexpr bool crosses(const Shape<PointType>& other) const;
856
858 template<PointConcept OtherPoint>
859 [[nodiscard]] constexpr bool separates(const OtherPoint& other) const;
860
862 template<SegmentConcept OtherSegment>
863 [[nodiscard]] constexpr bool separates(const OtherSegment& other) const;
864
866 template<OrientedSegmentConcept OtherOrientedSegment>
867 [[nodiscard]] constexpr bool separates(const OtherOrientedSegment& other) const;
868
870 template<LineConcept OtherLine>
871 [[nodiscard]] constexpr bool separates(const OtherLine& other) const;
872
874 template<OrientedLineConcept OtherOrientedLine>
875 [[nodiscard]] constexpr bool separates(const OtherOrientedLine& other) const;
876
878 template<RayConcept OtherRay>
879 [[nodiscard]] constexpr bool separates(const OtherRay& other) const;
880
882 template<HalfplaneConcept OtherHalfplane>
883 [[nodiscard]] constexpr bool separates(const OtherHalfplane& other) const;
884
886 template<RectangleConcept OtherRectangle>
887 [[nodiscard]] constexpr bool separates(const OtherRectangle& other) const;
888
890 template<TriangleConcept OtherTriangle>
891 [[nodiscard]] constexpr bool separates(const OtherTriangle& other) const;
892
894 template<ConvexConcept OtherConvex>
895 [[nodiscard]] constexpr bool separates(const OtherConvex& other) const;
896
906 template<PolygonConcept OtherPolygon>
907 [[nodiscard]] constexpr bool separates(const OtherPolygon& other) const;
908
910 template<MonotoneChainConcept OtherChain>
911 [[nodiscard]] constexpr bool contains(const OtherChain& other) const;
912
914 template<MonotoneChainConcept OtherChain>
915 [[nodiscard]] constexpr bool boundaryContains(const OtherChain& other) const {
916 return detail::reduceDegenerateToPoint(
917 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
918 }
919
921 template<MonotoneChainConcept OtherChain>
922 [[nodiscard]] constexpr bool interiorContains(const OtherChain& other) const;
923
925 template<MonotoneChainConcept OtherChain>
926 [[nodiscard]] constexpr bool separates(const OtherChain& other) const;
927
929 template<PolylineConcept OtherPolyline>
930 [[nodiscard]] constexpr bool contains(const OtherPolyline& other) const;
931
933 template<PolylineConcept OtherPolyline>
934 [[nodiscard]] constexpr bool boundaryContains(const OtherPolyline& other) const {
935 return detail::reduceDegenerateToPoint(
936 other, [this](const auto& vertex) { return this->boundaryContains(vertex); });
937 }
938
940 template<PolylineConcept OtherPolyline>
941 [[nodiscard]] constexpr bool interiorContains(const OtherPolyline& other) const;
942
944 template<PolylineConcept OtherPolyline>
945 [[nodiscard]] constexpr bool separates(const OtherPolyline& other) const;
946
948 template<HalfplaneIntersectionConcept OtherRegion>
949 [[nodiscard]] constexpr bool contains(const OtherRegion& other) const;
950
952 template<HalfplaneIntersectionConcept OtherRegion>
953 [[nodiscard]] constexpr bool boundaryContains(const OtherRegion& other) const;
954
956 template<HalfplaneIntersectionConcept OtherRegion>
957 [[nodiscard]] constexpr bool interiorContains(const OtherRegion& other) const;
958
960 template<HalfplaneIntersectionConcept OtherRegion>
961 [[nodiscard]] constexpr bool separates(const OtherRegion& other) const;
962
970 template<PolygonWithHolesConcept OtherRegion>
971 [[nodiscard]] constexpr bool contains(const OtherRegion& other) const;
972
979 template<PolygonWithHolesConcept OtherRegion>
980 [[nodiscard]] constexpr bool boundaryContains(const OtherRegion& other) const;
981
983 template<PolygonWithHolesConcept OtherRegion>
984 [[nodiscard]] constexpr bool interiorContains(const OtherRegion& other) const;
985
993 template<PolygonWithHolesConcept OtherRegion>
994 [[nodiscard]] bool separates(const OtherRegion& other) const;
995
996 // -------------------------------------------------------------------------
997 // A set of regions
998 //
999 // It outranks every other shape, so the symmetric relations reach it through
1000 // the rank-based forwarders and only the asymmetric ones are answered here.
1001 // A set is the union of its components, so it is contained exactly when
1002 // every component is — no matter what this shape is.
1003
1005 template<PolygonSetConcept OtherSet>
1006 [[nodiscard]] constexpr bool contains(const OtherSet& other) const {
1007 for (const auto& component : other) {
1008 if (!contains(component)) {
1009 return false;
1010 }
1011 }
1012 return true;
1013 }
1014
1016 template<PolygonSetConcept OtherSet>
1017 [[nodiscard]] constexpr bool boundaryContains(const OtherSet& other) const {
1018 for (const auto& component : other) {
1019 if (!boundaryContains(component)) {
1020 return false;
1021 }
1022 }
1023 return true;
1024 }
1025
1027 template<PolygonSetConcept OtherSet>
1028 [[nodiscard]] constexpr bool interiorContains(const OtherSet& other) const {
1029 for (const auto& component : other) {
1030 if (!interiorContains(component)) {
1031 return false;
1032 }
1033 }
1034 return true;
1035 }
1036
1045 template<PolygonSetConcept OtherSet>
1046 [[nodiscard]] bool separates(const OtherSet& other) const;
1047
1049 template<DiskConcept OtherDisk>
1050 [[nodiscard]] constexpr bool separates(const OtherDisk& other) const;
1051
1053 [[nodiscard]] constexpr bool separates(const Shape<PointType>& other) const;
1054
1055 // --- not-yet-implemented predicate pairs (throw); see implementation ---
1057 template<DiskConcept OtherDisk>
1058 [[nodiscard]] constexpr bool interiorContains(const OtherDisk& other) const;
1059
1061 template<ConvexConcept OtherConvex>
1062 [[nodiscard]] constexpr bool interiorContains(const OtherConvex& other) const;
1063
1065 template<PolygonConcept OtherPolygon>
1066 [[nodiscard]] constexpr bool interiorContains(const OtherPolygon& other) const;
1067
1068
1070 template <class ResultNumber = NumberType, PointConcept OtherPoint>
1071 [[nodiscard]] constexpr std::optional<Point<ResultNumber, typename PointType::LabelType>>
1072 intersection(const OtherPoint& other) const;
1073
1075 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
1076 [[nodiscard]] constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Ray<Point<ResultNumber, typename PointType::LabelType>>>>
1077 intersection(const OtherLine& other) const;
1078
1080 template <class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
1081 [[nodiscard]] constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Ray<Point<ResultNumber, typename PointType::LabelType>>>>
1082 intersection(const OtherOrientedLine& other) const;
1083
1085 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1086 [[nodiscard]] constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>>>
1087 intersection(const OtherSegment& other) const;
1088
1090 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
1091 [[nodiscard]] constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>>>
1092 intersection(const OtherOrientedSegment& other) const;
1093
1095 template <class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
1096 [[nodiscard]] constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>, Ray<Point<ResultNumber, typename PointType::LabelType>>>>
1097 intersection(const OtherRay& other) const;
1098
1100 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1101 requires (!PointConcept<OtherShape>
1102 && (detail::shapeRank<OtherShape> > detail::shapeRank<Ray>)
1103 && requires(const OtherShape& o, const Ray& self) {
1104 o.template intersection<ResultNumber>(self);
1105 })
1106 [[nodiscard]] constexpr auto intersection(const OtherShape& other) const {
1107 return other.template intersection<ResultNumber>(*this);
1108 }
1109
1111 template <class ResultNumber = NumberType, class EmptyPoint>
1112 [[nodiscard]] constexpr EmptyShape<EmptyPoint> intersection(const EmptyShape<EmptyPoint>&) const {
1113 return {};
1114 }
1115
1128 template <class ResultNumber = division_result_t<NumberType>, class OtherNumber>
1129 [[nodiscard]] constexpr std::optional<ResultNumber>
1130 yAtX(const OtherNumber &x) const;
1131
1144 template <class ResultNumber = division_result_t<NumberType>, class OtherNumber>
1145 [[nodiscard]] constexpr std::optional<ResultNumber>
1146 xAtY(const OtherNumber &y) const;
1147
1159 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1160 [[nodiscard]] constexpr auto squaredDistance(const OtherPoint& point) const;
1161
1163 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
1164 [[nodiscard]] constexpr auto squaredDistance(const OtherLine& other) const;
1165
1167 template <class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
1168 [[nodiscard]] constexpr auto squaredDistance(const OtherOrientedLine& other) const;
1169
1171 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1172 [[nodiscard]] constexpr auto squaredDistance(const OtherSegment& other) const;
1173
1175 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
1176 [[nodiscard]] constexpr auto squaredDistance(const OtherOrientedSegment& other) const;
1177
1179 template <class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
1180 [[nodiscard]] constexpr auto squaredDistance(const OtherRay& other) const;
1181
1188 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1189 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Ray>)
1190 && requires(const OtherShape& o, const Ray& self) {
1191 o.template squaredDistance<ResultNumber>(self);
1192 })
1193 [[nodiscard]] constexpr auto squaredDistance(const OtherShape& other) const {
1194 return other.template squaredDistance<ResultNumber>(*this);
1195 }
1196
1204 template <class ResultNumber = double, class DiskPointType, class DiskLabel>
1205 [[nodiscard]] detail::floating_result_t<ResultNumber> squaredDistance(const Disk<DiskPointType, DiskLabel>& disk) const {
1206 return disk.template squaredDistance<ResultNumber>(*this);
1207 }
1208
1224 template <class ResultNumber = division_result_t<NumberType>, class OtherShape>
1225 requires detail::ClosestPointsPairConcept<Ray<PointType_, TLabel>, OtherShape>
1226 [[nodiscard]] constexpr auto closestPoints(const OtherShape& other) const;
1227
1229 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1230 [[nodiscard]] constexpr auto distanceL1(const OtherPoint& point) const;
1231
1233 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
1234 [[nodiscard]] constexpr auto distanceL1(const OtherLine& other) const;
1235
1237 template <class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
1238 [[nodiscard]] constexpr auto distanceL1(const OtherOrientedLine& other) const;
1239
1241 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1242 [[nodiscard]] constexpr auto distanceL1(const OtherSegment& other) const;
1243
1245 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
1246 [[nodiscard]] constexpr auto distanceL1(const OtherOrientedSegment& other) const;
1247
1249 template <class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
1250 [[nodiscard]] constexpr auto distanceL1(const OtherRay& other) const;
1251
1258 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1259 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Ray>)
1260 && requires(const OtherShape& o, const Ray& self) {
1261 o.template distanceL1<ResultNumber>(self);
1262 })
1263 [[nodiscard]] constexpr auto distanceL1(const OtherShape& other) const {
1264 return other.template distanceL1<ResultNumber>(*this);
1265 }
1266
1282 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1283 [[nodiscard]] constexpr auto intersection(const Shape<OtherPoint>& other) const {
1284 return other.template intersection<ResultNumber>(*this);
1285 }
1286
1295 template <class ResultNumber = double, PointConcept OtherPoint>
1296 [[nodiscard]] constexpr auto distanceL1(const Shape<OtherPoint>& other) const {
1297 return other.template distanceL1<ResultNumber>(*this);
1298 }
1299
1301 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1302 [[nodiscard]] constexpr auto distanceLInf(const OtherPoint& point) const;
1303
1305 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
1306 [[nodiscard]] constexpr auto distanceLInf(const OtherLine& other) const;
1307
1309 template <class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
1310 [[nodiscard]] constexpr auto distanceLInf(const OtherOrientedLine& other) const;
1311
1313 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1314 [[nodiscard]] constexpr auto distanceLInf(const OtherSegment& other) const;
1315
1317 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
1318 [[nodiscard]] constexpr auto distanceLInf(const OtherOrientedSegment& other) const;
1319
1321 template <class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
1322 [[nodiscard]] constexpr auto distanceLInf(const OtherRay& other) const;
1323
1330 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1331 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Ray>)
1332 && requires(const OtherShape& o, const Ray& self) {
1333 o.template distanceLInf<ResultNumber>(self);
1334 })
1335 [[nodiscard]] constexpr auto distanceLInf(const OtherShape& other) const {
1336 return other.template distanceLInf<ResultNumber>(*this);
1337 }
1338
1347 template <class ResultNumber = double, PointConcept OtherPoint>
1348 [[nodiscard]] constexpr auto distanceLInf(const Shape<OtherPoint>& other) const {
1349 return other.template distanceLInf<ResultNumber>(*this);
1350 }
1351
1368 template <class OtherShape>
1370 [[nodiscard]] constexpr auto minkowskiSum(const OtherShape& other) const;
1371
1395 template <class OtherShape>
1397 [[nodiscard]] constexpr auto minkowskiErosion(const OtherShape& other) const;
1398
1400 template<PointConcept OtherPoint>
1401 constexpr Ray& operator+=(const OtherPoint& translation);
1402
1404 template<PointConcept OtherPoint>
1405 constexpr Ray& operator-=(const OtherPoint& translation);
1406
1408 template <class Scalar>
1409 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1410 constexpr Ray& operator*=(const Scalar& scalar);
1411
1413 template <class Scalar>
1414 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1415 constexpr Ray& operator/=(const Scalar& scalar);
1416
1424 template <class ResultNumber = NumberType>
1425 [[nodiscard]] constexpr Point<ResultNumber> pointInside() const;
1426
1434 template <class OtherShape>
1435 [[nodiscard]] constexpr bool pointInsideInteriorContainedIn(const OtherShape& shape) const;
1436
1437private:
1438 template <class OtherNumber>
1439 using promoted_number_t = std::common_type_t<CoordinateType, detail::promoted_number_t<OtherNumber>>;
1440
1441 std::array<PointType, 2> points_{};
1442 [[no_unique_address]] mutable LabelType label_{};
1443};
1444
1445template <class PointType, class LabelType, class TranslationNumber, class TranslationLabel>
1446constexpr auto operator-(const Ray<PointType, LabelType>& ray, const Point<TranslationNumber, TranslationLabel>& translation);
1447
1448template <class PointType, class LabelType, class Scalar>
1449 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1450constexpr auto operator*(const Ray<PointType, LabelType>& ray, const Scalar& scalar);
1451
1452template <class Scalar, class PointType, class LabelType>
1453 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1454constexpr auto operator*(const Scalar& scalar, const Ray<PointType, LabelType>& ray);
1455
1456template <class PointType, class LabelType, class Scalar>
1457 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1458constexpr auto operator/(const Ray<PointType, LabelType>& ray, const Scalar& scalar);
1459
1460template <class PointType, class LabelType>
1461std::ostream& operator<<(std::ostream& stream, const Ray<PointType, LabelType>& ray);
1462
1463} // namespace pgl
Shape pairs whose Minkowski sum Pangolin can represent.
Definition forward.hpp:476
Definition forward.hpp:306
Definition forward.hpp:324
Definition arrangement.hpp:67
@ 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
Ray() -> Ray< Point<>, NoLabel >
OrientedLine() -> OrientedLine< Point<>, NoLabel >
Public declaration of pgl::OrientedLine.
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
Closed half-plane defined by an oriented boundary line.
Definition halfplane.hpp:51
Unoriented infinite line.
Definition line.hpp:52
Sentinel type used when a point carries no extra label.
Definition point.hpp:31
Directed infinite line with left/right side semantics plus optional line label.
Definition orientedline.hpp:53
Two-dimensional point with optional label payload.
Definition point.hpp:129
Half-infinite line starting from one source point plus optional ray label.
Definition ray.hpp:51
constexpr Halfplane< PointType > halfplaneAbove() const
Returns the half-plane geometrically above the supporting line.
Definition predicates.hpp:843
constexpr Halfplane< PointType > leftHalfplane() const
Returns the half-plane on the left of the ray direction.
Definition predicates.hpp:858
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 ray.hpp:1296
constexpr bool interiorContains(const OtherLine &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:473
constexpr bool crosses(const OtherSegment &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:345
constexpr bool isVertical() const
Returns whether the ray is vertical.
Definition predicates.hpp:737
constexpr auto cend() const
Returns an iterator past the target point.
Definition ray.hpp:265
constexpr Halfplane< PointType > rightHalfplane() const
Returns the half-plane on the right of the ray direction.
Definition predicates.hpp:853
constexpr bool interiorContains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition ray.hpp:589
constexpr bool interiorsIntersect(const OtherShape &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition ray.hpp:804
constexpr std::partial_ordering orientation(const OtherPoint &point) const
Returns the orientation sign of a point with respect to the ray.
Definition predicates.hpp:802
constexpr bool separates(const OtherRegion &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:4612
constexpr bool contains(const OtherSet &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition ray.hpp:1006
constexpr bool separates(const OtherConvex &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1114
constexpr bool contains(const OtherDisk &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:704
constexpr bool collinear(const OtherOrientedLine &other) const
Returns whether the given oriented line is collinear with the ray.
Definition predicates.hpp:778
constexpr bool separates(const OtherSegment &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:993
constexpr Ray scaledDownY(const OtherNumber scalar) const
Returns the ray with its y-coordinates divided by a divisor.
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:267
constexpr Ray(const Ray< OtherPointType, OtherLabelType > &other)
Converts a ray with a different point and/or label type.
Definition ray.hpp:112
constexpr bool crosses(const OtherPoint &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:363
constexpr Ray(NumberType x1, NumberType y1, NumberType x2, NumberType y2)
Creates a ray from four coordinates.
Definition ray.hpp:83
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 ray.hpp:154
constexpr bool boundaryContains(const OtherRegion &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
constexpr bool intersects(const Shape< PointType > &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:486
constexpr bool boundaryContains(const OtherRay &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:470
constexpr auto minkowskiErosion(const OtherShape &other) const
Returns the Minkowski erosion of this shape by another (A ⊖ B).
Definition minkowskierosion.hpp:631
constexpr bool contains(const OtherRay &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:658
constexpr bool collinear(const OtherPoint &point) const
Returns whether the given point is collinear with the ray.
Definition predicates.hpp:766
constexpr bool operator==(const Ray &other) const
Tests equality of the represented ray.
Definition predicates.hpp:713
constexpr bool interiorContains(const OtherConvex &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:529
constexpr void scaleDownX(const OtherNumber scalar)
Divides the ray's x-coordinates by a divisor in place.
Definition transformations.hpp:1047
constexpr Ray & operator-=(const OtherPoint &translation)
Translates the ray by the negation of the given point in place.
constexpr bool parallel(const OtherLine &other) const
Returns whether the given line is parallel to the ray.
Definition predicates.hpp:808
constexpr bool interiorContains(const OtherHalfplane &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:503
constexpr bool interiorContains(const OtherPolygon &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1273
constexpr bool interiorContains(const OtherRay &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:497
constexpr bool contains(const OtherPolygon &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1745
bool separates(const OtherSet &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:5942
constexpr bool interiorContains(const OtherDisk &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1265
constexpr bool interiorContains(const OtherSegment &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:485
constexpr bool contains(const OtherRegion &other) const
Tests whether this shape contains the other shape (A ⊇ B).
constexpr PointType & target()
Definition ray.hpp:196
constexpr bool intersects(const OtherLine &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:415
constexpr bool containsCollinear(const OtherPoint &point) const
Returns whether the ray contains the given point that is collinear with the ray.
Definition predicates.hpp:754
constexpr std::ptrdiff_t index(const PointType &point) const
Definition ray.hpp:167
constexpr bool separates(const OtherTriangle &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1080
constexpr bool interiorsIntersect(const Shape< PointType > &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:535
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:273
constexpr A & label() const
Definition ray.hpp:303
constexpr bool collinear(const OtherSegment &other) const
Returns whether the given segment is collinear with the ray.
Definition predicates.hpp:784
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 ray.hpp:1283
constexpr bool interiorContains(const OtherRegion &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
constexpr bool contains(const OtherHalfplane &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:664
constexpr auto end() const
Returns an iterator past the target point.
Definition ray.hpp:253
constexpr bool samePointSet(const OtherShape &other) const
Tests whether another shape defines exactly the same point set.
Definition samepointset.hpp:1971
detail::promoted_number_t< NumberType > CoordinateType
Definition ray.hpp:55
constexpr bool contains(const OtherRectangle &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:670
constexpr bool boundaryContains(const OtherRegion &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1674
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Segment< Point< ResultNumber, typename PointType::LabelType > >, Ray< Point< ResultNumber, typename PointType::LabelType > > > > intersection(const OtherRay &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition intersection.hpp:451
constexpr Ray()=default
Creates the degenerate ray (0,0)--(0,0)->.
PointType PointType
Definition ray.hpp:52
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:378
constexpr bool interiorContains(const OtherPoint &point) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:467
constexpr auto distanceLInf(const OtherSegment &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:352
constexpr bool collinear(const OtherOrientedSegment &other) const
Returns whether the given oriented segment is collinear with the ray.
Definition predicates.hpp:790
constexpr ResultNumber area() const
Returns the area of the ray.
Definition measures.hpp:248
constexpr bool crosses(const OtherLine &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:333
detail::floating_result_t< ResultNumber > squaredDistance(const Disk< DiskPointType, DiskLabel > &disk) const
Returns the squared Euclidean distance to a disk.
Definition ray.hpp:1205
constexpr bool separates(const OtherPolygon &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1150
constexpr bool contains(const Shape< PointType > &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:712
constexpr auto operator<=>(const Ray &other) const
Provides an ordering compatible with ray equality.
Definition predicates.hpp:718
constexpr bool interiorsIntersect(const OtherRay &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:501
constexpr bool contains(const OtherConvex &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:690
constexpr bool collinear(const OtherRay &other) const
Returns whether another ray is collinear with this ray.
Definition predicates.hpp:796
constexpr bool crosses(const OtherOrientedLine &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:339
constexpr bool interiorsIntersect(const OtherLine &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:433
constexpr auto distanceL1(const OtherRay &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:392
constexpr bool interiorsIntersect(const OtherSegment &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:458
constexpr bool parallel(const OtherRay &other) const
Returns whether another ray is parallel to this ray.
Definition predicates.hpp:832
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:323
constexpr bool separates(const OtherOrientedSegment &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1018
constexpr bool isDegenerate() const
Returns whether the defining points coincide.
Definition predicates.hpp:727
constexpr Ray scaledUpY(const OtherNumber scalar) const
Returns the ray with its y-coordinates multiplied by a factor.
constexpr Ray(NumberType x1, NumberType y1, NumberType x2, NumberType y2, A &&label)
Same as the four-coordinate constructor, and stores a label.
Definition ray.hpp:101
constexpr bool parallel(const OtherOrientedLine &other) const
Returns whether the given oriented line is parallel to the ray.
Definition predicates.hpp:814
constexpr bool crosses(const OtherRay &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:357
constexpr PointType & source()
Definition ray.hpp:184
constexpr EmptyShape< EmptyPoint > intersection(const EmptyShape< EmptyPoint > &) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition ray.hpp:1112
constexpr PointType & get(std::ptrdiff_t index)
Definition ray.hpp:158
constexpr bool intersects(const EmptyShape< EmptyPoint > &) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition ray.hpp:773
constexpr bool interiorContains(const OtherOrientedSegment &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:491
constexpr auto distanceLInf(const OtherOrientedSegment &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:366
constexpr bool intersects(const OtherOrientedSegment &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:459
constexpr OrientedLine< PointType > asOrientedLine() const
Returns the oriented supporting line.
Definition ray.hpp:335
constexpr void scaleDownY(const OtherNumber scalar)
Divides the ray's y-coordinates by a divisor in place.
Definition transformations.hpp:1060
constexpr bool contains(const OtherPolyline &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2400
constexpr bool contains(const OtherTriangle &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:684
constexpr bool intersects(const OtherShape &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition ray.hpp:767
constexpr Ray opposite() const
Returns the ray obtained by swapping the two stored defining points.
Definition ray.hpp:223
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Ray< Point< ResultNumber, typename PointType::LabelType > > > > intersection(const OtherOrientedLine &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition intersection.hpp:368
constexpr bool contains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition ray.hpp:579
constexpr auto distanceL1(const OtherOrientedSegment &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:378
constexpr bool separates(const OtherRectangle &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1070
constexpr bool separates(const OtherHalfplane &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1064
PointType::NumberType NumberType
Definition ray.hpp:53
constexpr bool boundaryContains(const OtherPolygon &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:494
constexpr auto squaredDistance(const OtherSegment &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:348
constexpr const PointType & max() const
Returns the lexicographically largest stored defining point.
Definition ray.hpp:214
constexpr bool interiorsIntersect(const EmptyShape< EmptyPoint > &) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition ray.hpp:810
constexpr Ray & operator+=(const OtherPoint &translation)
Translates the ray by the given point in place.
constexpr void scaleUpY(const OtherNumber scalar)
Multiplies the ray's y-coordinates by a factor in place.
Definition transformations.hpp:1034
constexpr auto distanceL1(const OtherOrientedLine &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:355
constexpr bool interiorContains(const OtherRegion &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:2076
constexpr const PointType & target() const
Definition ray.hpp:193
constexpr bool separates(const OtherRay &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1037
constexpr auto squaredDistance(const OtherOrientedLine &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:338
constexpr auto squaredDistance(const OtherLine &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:328
constexpr bool crosses(const EmptyShape< EmptyPoint > &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition ray.hpp:850
constexpr bool parallel(const OtherSegment &other) const
Returns whether the given segment is parallel to the ray.
Definition predicates.hpp:820
constexpr bool verticesContain(const OtherPoint &point) const
Returns whether the given point is one of the stored defining points.
Definition predicates.hpp:748
constexpr bool boundaryContains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:584
bool separates(const OtherRegion &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:5683
constexpr auto cbegin() const
Returns an iterator to the source point.
Definition ray.hpp:244
constexpr bool separates(const OtherChain &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:3173
constexpr auto minkowskiSum(const OtherShape &other) const
Returns the Minkowski sum of this shape and another (A ⊕ B).
Definition minkowski.hpp:798
constexpr ResultNumber slope() const
Returns the slope of the supporting line.
Definition measures.hpp:259
constexpr bool boundaryContains(const OtherHalfplane &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:473
constexpr bool separates(const OtherPoint &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:987
constexpr bool boundaryContains(const OtherDisk &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:500
TLabel LabelType
Definition ray.hpp:54
constexpr auto distanceLInf(const OtherRay &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:380
constexpr bool interiorsIntersect(const OtherPoint &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:426
constexpr bool interiorContains(const OtherPolyline &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1714
constexpr bool collinear(const OtherLine &other) const
Returns whether the given line is collinear with the ray.
Definition predicates.hpp:772
constexpr bool intersects(const OtherSegment &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:439
constexpr bool contains(const OtherChain &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2038
constexpr bool interiorsIntersect(const OtherOrientedSegment &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:495
constexpr Ray(PointType source, PointType target, A &&label)
Creates a ray from a source and a second point and stores a label.
Definition ray.hpp:95
constexpr auto squaredDistance(const OtherShape &other) const
Returns the squared Euclidean distance to the given shape.
Definition ray.hpp:1193
constexpr const PointType & operator[](std::size_t index) const
Returns defining point 0 for the source and 1 for the target.
Definition ray.hpp:133
constexpr bool isHorizontal() const
Returns whether the ray is horizontal.
Definition predicates.hpp:742
constexpr Halfplane< PointType > halfplaneBelow() const
Returns the half-plane geometrically below the supporting line.
Definition predicates.hpp:848
constexpr bool boundaryContains(const OtherPoint &point) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:254
constexpr auto end()
Definition ray.hpp:256
constexpr bool separates(const OtherPolyline &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:3978
constexpr auto squaredDistance(const OtherRay &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:376
constexpr void rotate90(int k=1)
Rotates the ray by 90k degrees around the origin in place.
Definition transformations.hpp:1008
constexpr const PointType & min() const
Returns the lexicographically smallest stored defining point.
Definition ray.hpp:205
constexpr bool boundaryContains(const OtherPolyline &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:934
constexpr void scaleUpX(const OtherNumber scalar)
Multiplies the ray's x-coordinates by a factor in place.
Definition transformations.hpp:1021
constexpr PointType & operator[](std::size_t index)
Returns defining point 0 for the source and 1 for the target.
Definition ray.hpp:138
constexpr bool separates(const OtherLine &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1024
constexpr bool interiorsIntersect(const OtherOrientedLine &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:452
constexpr auto distanceLInf(const OtherLine &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:334
constexpr auto squaredDistance(const OtherOrientedSegment &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:362
constexpr bool interiorContains(const OtherSet &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition ray.hpp:1028
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Ray< 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:336
constexpr auto begin()
Definition ray.hpp:235
constexpr bool boundaryContains(const OtherChain &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:915
constexpr auto squaredDistance(const OtherPoint &point) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:300
constexpr auto distanceLInf(const OtherPoint &point) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:327
constexpr bool separates(const Shape< PointType > &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1161
constexpr bool contains(const OtherOrientedLine &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:640
constexpr auto distanceL1(const OtherLine &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:346
static constexpr std::size_t size()
Returns the number of defining points (always 2).
Definition ray.hpp:146
constexpr bool parallel(const OtherOrientedSegment &other) const
Returns whether the given oriented segment is parallel to the ray.
Definition predicates.hpp:826
constexpr bool separates(const OtherDisk &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1133
constexpr bool contains(const OtherLine &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:634
constexpr bool boundaryContains(const OtherOrientedSegment &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:458
constexpr bool interiorContains(const OtherTriangle &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:521
constexpr bool contains(const OtherSegment &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:646
constexpr bool intersects(const OtherPoint &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:409
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:242
constexpr auto distanceL1(const OtherShape &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition ray.hpp:1263
constexpr NumberType twiceArea() const
Returns twice the area of the ray.
Definition measures.hpp:253
constexpr Ray scaledUpX(const OtherNumber scalar) const
Returns the ray with its x-coordinates multiplied by a factor.
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 ray.hpp:1348
constexpr bool contains(const OtherOrientedSegment &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:652
constexpr bool boundaryContains(const OtherConvex &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:488
constexpr Ray(PointType source, PointType target)
Creates a ray from a source and a second point on the ray.
Definition ray.hpp:72
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Segment< Point< ResultNumber, typename PointType::LabelType > > > > intersection(const OtherOrientedSegment &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition intersection.hpp:440
constexpr bool interiorContains(const OtherOrientedLine &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:479
constexpr Ray scaledDownX(const OtherNumber scalar) const
Returns the ray with its x-coordinates divided by a divisor.
constexpr bool boundaryContains(const OtherRectangle &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:476
constexpr bool crosses(const Shape< PointType > &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:368
constexpr Point< ResultNumber > pointInside() const
Returns a point inside the ray.
Definition measures.hpp:267
constexpr bool contains(const OtherPoint &point) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:625
constexpr auto closestPoints(const OtherShape &other) const
Returns the pair of points realizing the distance, nothing when the shapes meet.
Definition closest.hpp:468
constexpr Line< PointType > asLine() const
Returns the supporting line without orientation.
Definition ray.hpp:319
constexpr auto distanceL1(const OtherPoint &point) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:339
constexpr bool interiorContains(const OtherChain &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1488
constexpr bool isUndefined() const
Returns whether the ray is degenerate without collapsing to a point or to a segment.
Definition predicates.hpp:732
constexpr auto distanceL1(const OtherSegment &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:364
constexpr bool boundaryContains(const OtherLine &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:464
constexpr bool boundaryContains(const OtherSegment &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:452
constexpr const PointType & source() const
Definition ray.hpp:181
constexpr bool boundaryContains(const Shape< PointType > &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1116
constexpr auto distanceLInf(const OtherShape &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition ray.hpp:1335
constexpr bool crosses(const OtherShape &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition ray.hpp:844
constexpr auto intersection(const OtherShape &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition ray.hpp:1106
constexpr bool intersects(const OtherOrientedLine &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:433
constexpr bool intersects(const OtherRay &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:465
constexpr bool boundaryContains(const OtherTriangle &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:482
constexpr bool boundaryContains(const OtherOrientedLine &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:467
constexpr bool crosses(const OtherOrientedSegment &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:351
constexpr Ray rotated90(int k=1) const
Returns the ray rotated by 90k degrees around the origin.
Definition transformations.hpp:1003
constexpr bool boundaryContains(const OtherSet &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition ray.hpp:1017
constexpr bool separates(const OtherOrientedLine &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1031
constexpr bool separates(const EmptyShape< EmptyPoint > &) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition ray.hpp:594
constexpr bool contains(const OtherRegion &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2771
constexpr auto begin() const
Returns an iterator to the source point.
Definition ray.hpp:232
constexpr bool interiorContains(const OtherRectangle &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:509
constexpr auto distanceLInf(const OtherOrientedLine &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:343
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