Pangolin
Header-only C++20 plane computational geometry library
Loading...
Searching...
No Matches
halfplane.hpp
Go to the documentation of this file.
1#pragma once
2
4
12
13#include <array>
14#include <cassert>
15#include <compare>
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 Halfplane;
30
32
33template <class PointType>
35
36template <class PointType, class A>
38
39template <class Number>
40Halfplane(Number, Number, Number, Number) -> Halfplane<Point<Number>, NoLabel>;
41
50template <class PointType_, class TLabel>
51struct Halfplane {
52 using PointType = PointType_;
54 using LabelType = TLabel;
55 using CoordinateType = detail::promoted_number_t<NumberType>;
56
57 static_assert(detail::is_point_v<PointType>, "Halfplane requires pgl::Point defining points");
58
62 constexpr Halfplane() = default;
63
73 : points_{std::move(source), std::move(target)} {}
74
84 : Halfplane(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&&>)
102 : Halfplane(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 : Halfplane(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 Halfplane& operator=(const Halfplane<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 Halfplane opposite() const {
224 return Halfplane(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
277 [[nodiscard]] constexpr bool operator==(const Halfplane& other) const;
278
280 template<AnyShapeConcept OtherShape>
281 [[nodiscard]] constexpr bool samePointSet(const OtherShape& other) const;
282
290 [[nodiscard]] constexpr auto operator<=>(const Halfplane& other) const;
291
300 template <class A = LabelType>
301 requires(detail::has_label_v<A>)
302 constexpr A& label() const {
303 return label_;
304 }
305
311 [[nodiscard]] constexpr explicit operator Line<PointType>() const;
312
318 [[nodiscard]] constexpr Line<PointType> asLine() const {
319 return static_cast<Line<PointType>>(*this);
320 }
321
327 [[nodiscard]] constexpr explicit operator OrientedLine<PointType>() const;
328
334 [[nodiscard]] constexpr OrientedLine<PointType> asOrientedLine() const {
335 return static_cast<OrientedLine<PointType>>(*this);
336 }
337
343 [[nodiscard]] constexpr explicit operator HalfplaneIntersection<PointType>() const {
345 }
346
353 return static_cast<HalfplaneIntersection<PointType>>(*this);
354 }
355
362 [[nodiscard]] constexpr Halfplane rotated90(int k = 1) const;
363
369 constexpr void rotate90(int k = 1);
370
372 template <class OtherNumber>
373 [[nodiscard]] constexpr Halfplane scaledUpX(const OtherNumber scalar) const;
374
376 template <class OtherNumber>
377 constexpr void scaleUpX(const OtherNumber scalar);
378
380 template <class OtherNumber>
381 [[nodiscard]] constexpr Halfplane scaledUpY(const OtherNumber scalar) const;
382
384 template <class OtherNumber>
385 constexpr void scaleUpY(const OtherNumber scalar);
386
388 template <class OtherNumber>
389 [[nodiscard]] constexpr Halfplane scaledDownX(const OtherNumber scalar) const;
390
392 template <class OtherNumber>
393 constexpr void scaleDownX(const OtherNumber scalar);
394
396 template <class OtherNumber>
397 [[nodiscard]] constexpr Halfplane scaledDownY(const OtherNumber scalar) const;
398
400 template <class OtherNumber>
401 constexpr void scaleDownY(const OtherNumber scalar);
402
408 [[nodiscard]] constexpr bool isDegenerate() const;
409
422 [[nodiscard]] constexpr bool isUndefined() const;
423
429 [[nodiscard]] constexpr bool isVertical() const;
430
436 [[nodiscard]] constexpr bool isHorizontal() const;
437
439 template<PointConcept OtherPoint>
440 [[nodiscard]] constexpr bool verticesContain(const OtherPoint& point) const;
441
443 template<PointConcept OtherPoint>
444 [[nodiscard]] constexpr bool boundaryContains(const OtherPoint& point) const;
445
446 // The boundary of a half-plane is its edge line. A 1D shape lies on the
447 // boundary iff its defining points do; an area must additionally be
448 // degenerate (collapsed onto that line). See the implementations.
450 template<SegmentConcept OtherSegment>
451 [[nodiscard]] constexpr bool boundaryContains(const OtherSegment& other) const;
453 template<LineConcept OtherLine>
454 [[nodiscard]] constexpr bool boundaryContains(const OtherLine& other) const;
456 template<OrientedSegmentConcept OtherOrientedSegment>
457 [[nodiscard]] constexpr bool boundaryContains(const OtherOrientedSegment& other) const;
459 template<OrientedLineConcept OtherOrientedLine>
460 [[nodiscard]] constexpr bool boundaryContains(const OtherOrientedLine& other) const;
462 template<RayConcept OtherRay>
463 [[nodiscard]] constexpr bool boundaryContains(const OtherRay& other) const;
465 template<RectangleConcept OtherRectangle>
466 [[nodiscard]] constexpr bool boundaryContains(const OtherRectangle& other) const;
468 template<TriangleConcept OtherTriangle>
469 [[nodiscard]] constexpr bool boundaryContains(const OtherTriangle& other) const;
471 template<HalfplaneConcept OtherHalfplane>
472 [[nodiscard]] constexpr bool boundaryContains(const OtherHalfplane& other) const;
474 template<ConvexConcept OtherConvex>
475 [[nodiscard]] constexpr bool boundaryContains(const OtherConvex& other) const {
476 return detail::reduceDegenerateGuarded(
477 other, [this](const auto& carrier) { return this->boundaryContains(carrier); });
478 }
479
480 template<PolygonConcept OtherPolygon>
481 [[nodiscard]] constexpr bool boundaryContains(const OtherPolygon& other) const {
482 return detail::reduceDegenerate(
483 other, [this](const auto& carrier) { return this->boundaryContains(carrier); });
484 }
485
486 template<DiskConcept OtherDisk>
487 [[nodiscard]] constexpr bool boundaryContains(const OtherDisk& other) const {
488 return detail::reduceDegenerate(
489 other, [this](const auto& carrier) { return this->boundaryContains(carrier); });
490 }
491
493 template<PointConcept OtherPoint>
494 [[nodiscard]] constexpr bool contains(const OtherPoint& point) const;
495
497 template<LineConcept OtherLine>
498 [[nodiscard]] constexpr bool contains(const OtherLine& other) const;
499
501 template<OrientedLineConcept OtherOrientedLine>
502 [[nodiscard]] constexpr bool contains(const OtherOrientedLine& other) const;
503
505 template<SegmentConcept OtherSegment>
506 [[nodiscard]] constexpr bool contains(const OtherSegment& other) const;
507
509 template<OrientedSegmentConcept OtherOrientedSegment>
510 [[nodiscard]] constexpr bool contains(const OtherOrientedSegment& other) const;
511
513 template<RayConcept OtherRay>
514 [[nodiscard]] constexpr bool contains(const OtherRay& other) const;
515
517 template<RectangleConcept OtherRectangle>
518 [[nodiscard]] constexpr bool contains(const OtherRectangle& other) const;
519
521 template<HalfplaneConcept OtherHalfplane>
522 [[nodiscard]] constexpr bool contains(const OtherHalfplane& other) const;
523
525 template<TriangleConcept OtherTriangle>
526 [[nodiscard]] constexpr bool contains(const OtherTriangle& other) const;
527
529 template<ConvexConcept OtherConvex>
530 [[nodiscard]] constexpr bool contains(const OtherConvex& other) const;
531
533 template<PolygonConcept OtherPolygon>
534 [[nodiscard]] constexpr bool contains(const OtherPolygon& other) const;
535
537 template<DiskConcept OtherDisk>
538 [[nodiscard]] constexpr bool contains(const OtherDisk& other) const;
539
541 [[nodiscard]] constexpr bool contains(const Shape<PointType>& other) const;
542
544 [[nodiscard]] constexpr bool boundaryContains(const Shape<PointType>& other) const;
545
546 // The empty set is a subset of every shape (contained in all of them) and
547 // disjoint from all of them, so containment is true while separation is
548 // false. These overloads let an EmptyShape flow through Shape's variant
549 // dispatch without special-casing.
551 template <class EmptyPoint>
552 [[nodiscard]] constexpr bool contains(const EmptyShape<EmptyPoint>&) const {
553 return true;
554 }
555
556 template <class EmptyPoint>
557 [[nodiscard]] constexpr bool boundaryContains(const EmptyShape<EmptyPoint>&) const {
558 return true;
559 }
560
561 template <class EmptyPoint>
562 [[nodiscard]] constexpr bool interiorContains(const EmptyShape<EmptyPoint>&) const {
563 return true;
564 }
565
566 template <class EmptyPoint>
567 [[nodiscard]] constexpr bool separates(const EmptyShape<EmptyPoint>&) const {
568 return false;
569 }
570
572 template<PointConcept OtherPoint>
573 [[nodiscard]] constexpr bool interiorContains(const OtherPoint& point) const;
574
576 template<LineConcept OtherLine>
577 [[nodiscard]] constexpr bool interiorContains(const OtherLine& other) const;
578
580 template<OrientedLineConcept OtherOrientedLine>
581 [[nodiscard]] constexpr bool interiorContains(const OtherOrientedLine& other) const;
582
584 template<SegmentConcept OtherSegment>
585 [[nodiscard]] constexpr bool interiorContains(const OtherSegment& other) const;
586
588 template<OrientedSegmentConcept OtherOrientedSegment>
589 [[nodiscard]] constexpr bool interiorContains(const OtherOrientedSegment& other) const;
590
592 template<RayConcept OtherRay>
593 [[nodiscard]] constexpr bool interiorContains(const OtherRay& other) const;
594
596 template<RectangleConcept OtherRectangle>
597 [[nodiscard]] constexpr bool interiorContains(const OtherRectangle& other) const;
598
600 template<HalfplaneConcept OtherHalfplane>
601 [[nodiscard]] constexpr bool interiorContains(const OtherHalfplane& other) const;
602
604 template<TriangleConcept OtherTriangle>
605 [[nodiscard]] constexpr bool interiorContains(const OtherTriangle& other) const;
606
608 template<ConvexConcept OtherConvex>
609 [[nodiscard]] constexpr bool interiorContains(const OtherConvex& other) const;
610
612 template<DiskConcept OtherDisk>
613 [[nodiscard]] constexpr bool interiorContains(const OtherDisk& other) const;
614
616 template<PointConcept OtherPoint>
617 [[nodiscard]] constexpr bool intersects(const OtherPoint& other) const;
618
620 template<LineConcept OtherLine>
621 [[nodiscard]] constexpr bool intersects(const OtherLine& other) const;
622
624 template<OrientedLineConcept OtherOrientedLine>
625 [[nodiscard]] constexpr bool intersects(const OtherOrientedLine& other) const;
626
628 template<SegmentConcept OtherSegment>
629 [[nodiscard]] constexpr bool intersects(const OtherSegment& other) const;
630
632 template<OrientedSegmentConcept OtherOrientedSegment>
633 [[nodiscard]] constexpr bool intersects(const OtherOrientedSegment& other) const;
634
636 template<RayConcept OtherRay>
637 [[nodiscard]] constexpr bool intersects(const OtherRay& other) const;
638
640 template<HalfplaneConcept OtherHalfplane>
641 [[nodiscard]] constexpr bool intersects(const OtherHalfplane& other) const;
642
644 [[nodiscard]] constexpr bool intersects(const Shape<PointType>& other) const;
645
647 template<typename OtherShape>
648 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Halfplane>)
649 [[nodiscard]] constexpr bool intersects(const OtherShape& other) const {
650 return other.intersects(*this);
651 }
652
654 template <class EmptyPoint>
655 [[nodiscard]] constexpr bool intersects(const EmptyShape<EmptyPoint>&) const {
656 return false;
657 }
658
660 template<PointConcept OtherPoint>
661 [[nodiscard]] constexpr bool interiorsIntersect(const OtherPoint& other) const;
662
664 template<LineConcept OtherLine>
665 [[nodiscard]] constexpr bool interiorsIntersect(const OtherLine& other) const;
666
668 template<OrientedLineConcept OtherOrientedLine>
669 [[nodiscard]] constexpr bool interiorsIntersect(const OtherOrientedLine& other) const;
670
672 template<SegmentConcept OtherSegment>
673 [[nodiscard]] constexpr bool interiorsIntersect(const OtherSegment& other) const;
674
676 template<OrientedSegmentConcept OtherOrientedSegment>
677 [[nodiscard]] constexpr bool interiorsIntersect(const OtherOrientedSegment& other) const;
678
680 template<RayConcept OtherRay>
681 [[nodiscard]] constexpr bool interiorsIntersect(const OtherRay& other) const;
682
684 template<HalfplaneConcept OtherHalfplane>
685 [[nodiscard]] constexpr bool interiorsIntersect(const OtherHalfplane& other) const;
686
688 template<typename OtherShape>
689 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Halfplane>)
690 [[nodiscard]] constexpr bool interiorsIntersect(const OtherShape& other) const {
691 return other.interiorsIntersect(*this);
692 }
693
695 template <class EmptyPoint>
696 [[nodiscard]] constexpr bool interiorsIntersect(const EmptyShape<EmptyPoint>&) const {
697 return false;
698 }
699
701 [[nodiscard]] constexpr bool interiorsIntersect(const Shape<PointType>& other) const;
702
704 template<LineConcept OtherLine>
705 [[nodiscard]] constexpr bool separates(const OtherLine& other) const;
706
708 template<PointConcept OtherPoint>
709 [[nodiscard]] constexpr bool separates(const OtherPoint& other) const;
710
712 template<OrientedLineConcept OtherOrientedLine>
713 [[nodiscard]] constexpr bool separates(const OtherOrientedLine& other) const;
714
716 template<SegmentConcept OtherSegment>
717 [[nodiscard]] constexpr bool separates(const OtherSegment& other) const;
718
720 template<OrientedSegmentConcept OtherOrientedSegment>
721 [[nodiscard]] constexpr bool separates(const OtherOrientedSegment& other) const;
722
724 template<RayConcept OtherRay>
725 [[nodiscard]] constexpr bool separates(const OtherRay& other) const;
726
728 template<RectangleConcept OtherRectangle>
729 [[nodiscard]] constexpr bool separates(const OtherRectangle& other) const;
730
732 template<HalfplaneConcept OtherHalfplane>
733 [[nodiscard]] constexpr bool separates(const OtherHalfplane& other) const;
734
736 template<TriangleConcept OtherTriangle>
737 [[nodiscard]] constexpr bool separates(const OtherTriangle& other) const;
738
740 template<ConvexConcept OtherConvex>
741 [[nodiscard]] constexpr bool separates(const OtherConvex& other) const;
742
744 template<PolygonConcept OtherPolygon>
745 [[nodiscard]] constexpr bool separates(const OtherPolygon& other) const;
746
748 template<MonotoneChainConcept OtherChain>
749 [[nodiscard]] constexpr bool contains(const OtherChain& other) const;
750
752 template<MonotoneChainConcept OtherChain>
753 [[nodiscard]] constexpr bool boundaryContains(const OtherChain& other) const;
754
756 template<MonotoneChainConcept OtherChain>
757 [[nodiscard]] constexpr bool interiorContains(const OtherChain& other) const;
758
760 template<MonotoneChainConcept OtherChain>
761 [[nodiscard]] constexpr bool separates(const OtherChain& other) const;
762
764 template<PolylineConcept OtherPolyline>
765 [[nodiscard]] constexpr bool contains(const OtherPolyline& other) const;
766
768 template<PolylineConcept OtherPolyline>
769 [[nodiscard]] constexpr bool boundaryContains(const OtherPolyline& other) const;
770
772 template<PolylineConcept OtherPolyline>
773 [[nodiscard]] constexpr bool interiorContains(const OtherPolyline& other) const;
774
776 template<PolylineConcept OtherPolyline>
777 [[nodiscard]] constexpr bool separates(const OtherPolyline& other) const;
778
780 template<HalfplaneIntersectionConcept OtherRegion>
781 [[nodiscard]] constexpr bool contains(const OtherRegion& other) const;
782
784 template<HalfplaneIntersectionConcept OtherRegion>
785 [[nodiscard]] constexpr bool boundaryContains(const OtherRegion& other) const;
786
788 template<HalfplaneIntersectionConcept OtherRegion>
789 [[nodiscard]] constexpr bool interiorContains(const OtherRegion& other) const;
790
792 template<HalfplaneIntersectionConcept OtherRegion>
793 [[nodiscard]] constexpr bool separates(const OtherRegion& other) const;
794
802 template<PolygonWithHolesConcept OtherRegion>
803 [[nodiscard]] constexpr bool contains(const OtherRegion& other) const;
804
811 template<PolygonWithHolesConcept OtherRegion>
812 [[nodiscard]] constexpr bool boundaryContains(const OtherRegion& other) const;
813
815 template<PolygonWithHolesConcept OtherRegion>
816 [[nodiscard]] constexpr bool interiorContains(const OtherRegion& other) const;
817
825 template<PolygonWithHolesConcept OtherRegion>
826 [[nodiscard]] bool separates(const OtherRegion& other) const;
827
828 // -------------------------------------------------------------------------
829 // A set of regions
830 //
831 // It outranks every other shape, so the symmetric relations reach it through
832 // the rank-based forwarders and only the asymmetric ones are answered here.
833 // A set is the union of its components, so it is contained exactly when
834 // every component is — no matter what this shape is.
835
837 template<PolygonSetConcept OtherSet>
838 [[nodiscard]] constexpr bool contains(const OtherSet& other) const {
839 for (const auto& component : other) {
840 if (!contains(component)) {
841 return false;
842 }
843 }
844 return true;
845 }
846
848 template<PolygonSetConcept OtherSet>
849 [[nodiscard]] constexpr bool boundaryContains(const OtherSet& other) const {
850 for (const auto& component : other) {
851 if (!boundaryContains(component)) {
852 return false;
853 }
854 }
855 return true;
856 }
857
859 template<PolygonSetConcept OtherSet>
860 [[nodiscard]] constexpr bool interiorContains(const OtherSet& other) const {
861 for (const auto& component : other) {
862 if (!interiorContains(component)) {
863 return false;
864 }
865 }
866 return true;
867 }
868
877 template<PolygonSetConcept OtherSet>
878 [[nodiscard]] bool separates(const OtherSet& other) const;
879
881 template<DiskConcept OtherDisk>
882 [[nodiscard]] constexpr bool separates(const OtherDisk& other) const;
883
885 [[nodiscard]] constexpr bool separates(const Shape<PointType>& other) const;
886
887 // --- not-yet-implemented predicate pairs (throw); see implementation ---
889 template<PolygonConcept OtherPolygon>
890 [[nodiscard]] constexpr bool interiorContains(const OtherPolygon& other) const;
891
892
894 template<LineConcept OtherLine>
895 [[nodiscard]] constexpr bool crosses(const OtherLine& other) const;
896
898 template<PointConcept OtherPoint>
899 [[nodiscard]] constexpr bool crosses(const OtherPoint& other) const;
900
902 template<OrientedLineConcept OtherOrientedLine>
903 [[nodiscard]] constexpr bool crosses(const OtherOrientedLine& other) const;
904
906 template<SegmentConcept OtherSegment>
907 [[nodiscard]] constexpr bool crosses(const OtherSegment& other) const;
908
910 template<OrientedSegmentConcept OtherOrientedSegment>
911 [[nodiscard]] constexpr bool crosses(const OtherOrientedSegment& other) const;
912
914 template<RayConcept OtherRay>
915 [[nodiscard]] constexpr bool crosses(const OtherRay& other) const;
916
918 template<HalfplaneConcept OtherHalfplane>
919 [[nodiscard]] constexpr bool crosses(const OtherHalfplane& other) const;
920
922 template<typename OtherShape>
923 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Halfplane>)
924 [[nodiscard]] constexpr bool crosses(const OtherShape& other) const {
925 return other.crosses(*this);
926 }
927
929 template <class EmptyPoint>
930 [[nodiscard]] constexpr bool crosses(const EmptyShape<EmptyPoint>&) const {
931 return false;
932 }
933
935 [[nodiscard]] constexpr bool crosses(const Shape<PointType>& other) const;
936
938 template <class ResultNumber = NumberType, PointConcept OtherPoint>
939 [[nodiscard]] constexpr std::optional<Point<ResultNumber, typename PointType::LabelType>>
940 intersection(const OtherPoint& other) const;
941
943 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
944 [[nodiscard]] constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Line<Point<ResultNumber, typename PointType::LabelType>>, Ray<Point<ResultNumber, typename PointType::LabelType>>>>
945 intersection(const OtherLine& other) const;
946
948 template <class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
949 [[nodiscard]] constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Line<Point<ResultNumber, typename PointType::LabelType>>, Ray<Point<ResultNumber, typename PointType::LabelType>>>>
950 intersection(const OtherOrientedLine& other) const;
951
953 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
954 [[nodiscard]] constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>>>
955 intersection(const OtherSegment& other) const;
956
958 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
959 [[nodiscard]] constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>>>
960 intersection(const OtherOrientedSegment& other) const;
961
963 template <class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
964 [[nodiscard]] constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>, Ray<Point<ResultNumber, typename PointType::LabelType>>>>
965 intersection(const OtherRay& other) const;
966
978 template <class ResultNumber = NumberType, HalfplaneConcept OtherHalfplane>
980 intersection(const OtherHalfplane& other) const;
981
983 template <class ResultNumber = NumberType, HalfplaneIntersectionConcept OtherRegion>
984 [[nodiscard]] constexpr auto intersection(const OtherRegion& other) const {
985 return other.template intersection<ResultNumber>(*this);
986 }
987
989 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
990 requires (!PointConcept<OtherShape>
992 && (detail::shapeRank<OtherShape> > detail::shapeRank<Halfplane>)
993 && requires(const OtherShape& o, const Halfplane& self) {
994 o.template intersection<ResultNumber>(self);
995 })
996 [[nodiscard]] constexpr auto intersection(const OtherShape& other) const {
997 return other.template intersection<ResultNumber>(*this);
998 }
999
1001 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1002 requires (!PointConcept<OtherShape>
1003 && (detail::shapeRank<OtherShape> > detail::shapeRank<Halfplane>)
1004 && requires(const OtherShape& o, const Halfplane& self) {
1006 })
1007 [[nodiscard]] constexpr auto regularizedIntersection(const OtherShape& other) const {
1008 return other.template regularizedIntersection<ResultNumber>(*this);
1009 }
1010
1012 template <class ResultNumber = NumberType, class EmptyPoint>
1013 [[nodiscard]] constexpr EmptyShape<EmptyPoint> intersection(const EmptyShape<EmptyPoint>&) const {
1014 return {};
1015 }
1016
1032 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1033 [[nodiscard]] constexpr auto squaredDistance(const OtherPoint& point) const;
1034
1036 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1037 [[nodiscard]] constexpr auto squaredDistance(const OtherSegment& other) const;
1038
1040 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
1041 [[nodiscard]] constexpr auto squaredDistance(const OtherOrientedSegment& other) const;
1042
1044 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
1045 [[nodiscard]] constexpr auto squaredDistance(const OtherLine& other) const;
1046
1048 template <class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
1049 [[nodiscard]] constexpr auto squaredDistance(const OtherOrientedLine& other) const;
1050
1052 template <class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
1053 [[nodiscard]] constexpr auto squaredDistance(const OtherRay& other) const;
1054
1056 template <class ResultNumber = division_result_t<NumberType>, HalfplaneConcept OtherHalfplane>
1057 [[nodiscard]] constexpr auto squaredDistance(const OtherHalfplane& other) const;
1058
1065 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1066 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Halfplane>)
1067 && requires(const OtherShape& o, const Halfplane& self) {
1068 o.template squaredDistance<ResultNumber>(self);
1069 })
1070 [[nodiscard]] constexpr auto squaredDistance(const OtherShape& other) const {
1071 return other.template squaredDistance<ResultNumber>(*this);
1072 }
1073
1081 template <class ResultNumber = double, class DiskPointType, class DiskLabel>
1082 [[nodiscard]] detail::floating_result_t<ResultNumber> squaredDistance(const Disk<DiskPointType, DiskLabel>& disk) const {
1083 return disk.template squaredDistance<ResultNumber>(*this);
1084 }
1085
1101 template <class ResultNumber = division_result_t<NumberType>, class OtherShape>
1102 requires detail::ClosestPointsPairConcept<Halfplane<PointType_, TLabel>, OtherShape>
1103 [[nodiscard]] constexpr auto closestPoints(const OtherShape& other) const;
1104
1106 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1107 [[nodiscard]] constexpr auto distanceL1(const OtherPoint& point) const;
1108
1110 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1111 [[nodiscard]] constexpr auto distanceL1(const OtherSegment& other) const;
1112
1114 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
1115 [[nodiscard]] constexpr auto distanceL1(const OtherOrientedSegment& other) const;
1116
1118 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
1119 [[nodiscard]] constexpr auto distanceL1(const OtherLine& other) const;
1120
1122 template <class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
1123 [[nodiscard]] constexpr auto distanceL1(const OtherOrientedLine& other) const;
1124
1126 template <class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
1127 [[nodiscard]] constexpr auto distanceL1(const OtherRay& other) const;
1128
1130 template <class ResultNumber = division_result_t<NumberType>, HalfplaneConcept OtherHalfplane>
1131 [[nodiscard]] constexpr auto distanceL1(const OtherHalfplane& other) const;
1132
1139 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1140 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Halfplane>)
1141 && requires(const OtherShape& o, const Halfplane& self) {
1142 o.template distanceL1<ResultNumber>(self);
1143 })
1144 [[nodiscard]] constexpr auto distanceL1(const OtherShape& other) const {
1145 return other.template distanceL1<ResultNumber>(*this);
1146 }
1147
1163 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1164 [[nodiscard]] constexpr auto intersection(const Shape<OtherPoint>& other) const {
1165 return other.template intersection<ResultNumber>(*this);
1166 }
1167
1169 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1170 [[nodiscard]] auto regularizedIntersection(const Shape<OtherPoint>& other) const {
1171 return other.template regularizedIntersection<ResultNumber>(*this);
1172 }
1173
1182 template <class ResultNumber = double, PointConcept OtherPoint>
1183 [[nodiscard]] constexpr auto distanceL1(const Shape<OtherPoint>& other) const {
1184 return other.template distanceL1<ResultNumber>(*this);
1185 }
1186
1188 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
1189 [[nodiscard]] constexpr auto distanceLInf(const OtherPoint& point) const;
1190
1192 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1193 [[nodiscard]] constexpr auto distanceLInf(const OtherSegment& other) const;
1194
1196 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
1197 [[nodiscard]] constexpr auto distanceLInf(const OtherOrientedSegment& other) const;
1198
1200 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
1201 [[nodiscard]] constexpr auto distanceLInf(const OtherLine& other) const;
1202
1204 template <class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
1205 [[nodiscard]] constexpr auto distanceLInf(const OtherOrientedLine& other) const;
1206
1208 template <class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
1209 [[nodiscard]] constexpr auto distanceLInf(const OtherRay& other) const;
1210
1212 template <class ResultNumber = division_result_t<NumberType>, HalfplaneConcept OtherHalfplane>
1213 [[nodiscard]] constexpr auto distanceLInf(const OtherHalfplane& other) const;
1214
1221 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
1222 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Halfplane>)
1223 && requires(const OtherShape& o, const Halfplane& self) {
1224 o.template distanceLInf<ResultNumber>(self);
1225 })
1226 [[nodiscard]] constexpr auto distanceLInf(const OtherShape& other) const {
1227 return other.template distanceLInf<ResultNumber>(*this);
1228 }
1229
1238 template <class ResultNumber = double, PointConcept OtherPoint>
1239 [[nodiscard]] constexpr auto distanceLInf(const Shape<OtherPoint>& other) const {
1240 return other.template distanceLInf<ResultNumber>(*this);
1241 }
1242
1251 template <class ResultNumber = division_result_t<NumberType>>
1252 [[nodiscard]] constexpr ResultNumber slope() const;
1253
1275 template <class OtherShape>
1277 [[nodiscard]] constexpr auto minkowskiSum(const OtherShape& other) const;
1278
1302 template <class OtherShape>
1304 [[nodiscard]] constexpr auto minkowskiErosion(const OtherShape& other) const;
1305
1321 template <class ResultNumber = double, DiskConcept OtherDisk>
1323 minkowskiErosion(const OtherDisk& other) const;
1324
1351 template <class ResultNumber = double, DiskConcept OtherDisk>
1353 minkowskiSum(const OtherDisk& other) const;
1354
1356 template<PointConcept OtherPoint>
1357 constexpr Halfplane& operator+=(const OtherPoint& translation);
1358
1360 template<PointConcept OtherPoint>
1361 constexpr Halfplane& operator-=(const OtherPoint& translation);
1362
1364 template <class Scalar>
1365 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1366 constexpr Halfplane& operator*=(const Scalar& scalar);
1367
1369 template <class Scalar>
1370 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1371 constexpr Halfplane& operator/=(const Scalar& scalar);
1372
1378 template <class ResultNumber = NumberType>
1379 [[nodiscard]] constexpr Point<ResultNumber> pointInside() const;
1380
1388 template <class OtherShape>
1389 [[nodiscard]] constexpr bool pointInsideInteriorContainedIn(const OtherShape& shape) const;
1390
1391 private:
1392
1393 std::array<PointType, 2> points_{};
1394 [[no_unique_address]] mutable LabelType label_{};
1395};
1396
1397template <class PointType, class LabelType, class TranslationNumber, class TranslationLabel>
1398constexpr auto operator-(const Halfplane<PointType, LabelType>& halfplane, const Point<TranslationNumber, TranslationLabel>& translation);
1399
1400template <class PointType, class LabelType, class Scalar>
1401 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1402constexpr auto operator*(const Halfplane<PointType, LabelType>& halfplane, const Scalar& scalar);
1403
1404template <class Scalar, class PointType, class LabelType>
1405 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1406constexpr auto operator*(const Scalar& scalar, const Halfplane<PointType, LabelType>& halfplane);
1407
1408template <class PointType, class LabelType, class Scalar>
1409 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
1410constexpr auto operator/(const Halfplane<PointType, LabelType>& halfplane, const Scalar& scalar);
1411
1412template <class PointType, class LabelType>
1413std::ostream& operator<<(std::ostream& stream, const Halfplane<PointType, LabelType>& halfplane);
1414
1415} // namespace pgl
Definition forward.hpp:319
Shape pairs whose Minkowski sum Pangolin can represent.
Definition forward.hpp:476
Definition forward.hpp:306
Definition forward.hpp:324
Definition arrangement.hpp:67
HalfplaneIntersection() -> HalfplaneIntersection< Point<>, NoLabel >
Definition halfplaneintersection.hpp:2308
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
Halfplane() -> Halfplane< Point<>, NoLabel >
OrientedLine() -> OrientedLine< Point<>, NoLabel >
Public declaration of pgl::OrientedSegment.
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
constexpr Halfplane rotated90(int k=1) const
Returns the half-plane rotated by 90k degrees around the origin.
Definition transformations.hpp:1457
constexpr bool samePointSet(const OtherShape &other) const
Tests whether another shape defines exactly the same point set.
Definition samepointset.hpp:1977
constexpr bool boundaryContains(const OtherSegment &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:414
auto regularizedIntersection(const Shape< OtherPoint > &other) const
Re-dispatches a regularized intersection through a runtime shape.
Definition halfplane.hpp:1170
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Line< 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:593
constexpr bool interiorContains(const OtherLine &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:667
constexpr bool separates(const OtherRectangle &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1417
constexpr Halfplane scaledDownY(const OtherNumber scalar) const
Returns the half-plane with its y-coordinates divided by a divisor.
constexpr auto operator<=>(const Halfplane &other) const
Provides an ordering compatible with half-plane equality.
Definition predicates.hpp:946
constexpr bool separates(const OtherPoint &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1376
constexpr void scaleDownX(const OtherNumber scalar)
Divides the half-plane's x-coordinates by a divisor in place.
Definition transformations.hpp:1516
constexpr bool contains(const OtherOrientedLine &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:891
constexpr bool interiorContains(const OtherTriangle &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:782
constexpr bool interiorContains(const OtherRay &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:707
constexpr bool crosses(const OtherShape &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition halfplane.hpp:924
constexpr bool contains(const OtherSet &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition halfplane.hpp:838
constexpr bool boundaryContains(const OtherOrientedLine &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:432
constexpr bool intersects(const OtherRay &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:675
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:505
constexpr bool separates(const OtherPolygon &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1458
constexpr bool contains(const OtherRegion &other) const
Tests whether this shape contains the other shape (A ⊇ B).
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Line< 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:538
constexpr auto end() const
Returns an iterator past the target defining point.
Definition halfplane.hpp:253
constexpr bool boundaryContains(const OtherSet &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition halfplane.hpp:849
constexpr bool separates(const OtherOrientedLine &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1389
constexpr bool interiorContains(const OtherConvex &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:737
constexpr bool intersects(const OtherOrientedLine &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:644
constexpr Halfplane & operator+=(const OtherPoint &translation)
Translates the half-plane by the given point in place.
constexpr bool interiorContains(const OtherPolygon &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1286
constexpr std::ptrdiff_t index(const PointType &point) const
Definition halfplane.hpp:167
constexpr Point< ResultNumber > pointInside() const
Returns a point inside the halfplane.
Definition measures.hpp:486
constexpr void scaleDownY(const OtherNumber scalar)
Divides the half-plane's y-coordinates by a divisor in place.
Definition transformations.hpp:1534
constexpr bool interiorContains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition halfplane.hpp:562
constexpr bool contains(const OtherTriangle &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:969
constexpr HalfplaneIntersection< Point< ResultNumber, typename PointType::LabelType > > intersection(const OtherHalfplane &other) const
Returns the intersection of the two half-planes as a half-plane intersection.
Definition intersection.hpp:703
TLabel LabelType
Definition halfplane.hpp:54
constexpr auto distanceL1(const OtherLine &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:434
constexpr bool separates(const OtherTriangle &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1435
constexpr bool separates(const OtherRegion &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:4630
constexpr bool boundaryContains(const OtherRegion &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1686
constexpr bool separates(const OtherConvex &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1442
constexpr bool contains(const OtherConvex &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:975
constexpr auto distanceLInf(const OtherPoint &point) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:395
constexpr bool separates(const OtherRay &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1410
constexpr auto squaredDistance(const OtherOrientedLine &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:427
constexpr auto squaredDistance(const OtherOrientedSegment &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:409
static constexpr std::size_t size()
Returns the number of defining points (always 2).
Definition halfplane.hpp:146
constexpr void rotate90(int k=1)
Rotates the half-plane by 90k degrees around the origin in place.
Definition transformations.hpp:1462
constexpr bool boundaryContains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition halfplane.hpp:557
constexpr bool interiorsIntersect(const OtherPoint &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:682
constexpr bool contains(const OtherSegment &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:897
constexpr void scaleUpX(const OtherNumber scalar)
Multiplies the half-plane's x-coordinates by a factor in place.
Definition transformations.hpp:1480
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 halfplane.hpp:1164
constexpr bool contains(const OtherHalfplane &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:948
constexpr Halfplane(NumberType x1, NumberType y1, NumberType x2, NumberType y2)
Creates a half-plane from four coordinates.
Definition halfplane.hpp:83
constexpr const PointType & max() const
Returns the lexicographically largest defining point.
Definition halfplane.hpp:214
constexpr bool boundaryContains(const OtherPolygon &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition halfplane.hpp:481
constexpr auto begin() const
Returns an iterator to the source defining point.
Definition halfplane.hpp:232
constexpr bool interiorsIntersect(const OtherShape &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition halfplane.hpp:690
constexpr bool intersects(const OtherLine &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:628
constexpr auto begin()
Definition halfplane.hpp:235
constexpr Halfplane opposite() const
Returns the complementary half-plane with reversed boundary orientation.
Definition halfplane.hpp:223
constexpr bool boundaryContains(const OtherPolyline &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1293
constexpr A & label() const
Definition halfplane.hpp:302
constexpr bool contains(const Shape< PointType > &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1002
constexpr bool interiorContains(const OtherOrientedSegment &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:698
constexpr auto intersection(const OtherShape &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition halfplane.hpp:996
constexpr bool separates(const Shape< PointType > &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1508
constexpr auto squaredDistance(const OtherPoint &point) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:391
constexpr bool contains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition halfplane.hpp:552
constexpr const PointType & min() const
Returns the lexicographically smallest defining point.
Definition halfplane.hpp:205
constexpr bool separates(const OtherPolyline &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:3984
PointType::NumberType NumberType
Definition halfplane.hpp:53
constexpr PointType & get(std::ptrdiff_t index)
Definition halfplane.hpp:158
constexpr bool contains(const OtherRay &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:915
constexpr bool interiorsIntersect(const OtherOrientedLine &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:704
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:603
constexpr auto distanceLInf(const OtherLine &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:422
constexpr auto distanceL1(const OtherPoint &point) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:407
constexpr bool boundaryContains(const OtherLine &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:420
constexpr auto squaredDistance(const OtherShape &other) const
Returns the squared Euclidean distance to the given shape.
Definition halfplane.hpp:1070
constexpr bool interiorContains(const OtherOrientedLine &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:679
constexpr auto squaredDistance(const OtherHalfplane &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:445
constexpr PointType & source()
Definition halfplane.hpp:184
constexpr Halfplane(const Halfplane< OtherPointType, OtherLabelType > &other)
Converts a half-plane with a different point and/or label type.
Definition halfplane.hpp:112
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:524
constexpr bool crosses(const Shape< PointType > &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:537
constexpr bool interiorContains(const OtherChain &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1499
constexpr bool boundaryContains(const OtherRectangle &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:444
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 halfplane.hpp:1239
constexpr EmptyShape< EmptyPoint > intersection(const EmptyShape< EmptyPoint > &) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition halfplane.hpp:1013
constexpr Halfplane(NumberType x1, NumberType y1, NumberType x2, NumberType y2, A &&label)
Same as the four-coordinate constructor, and stores a label.
Definition halfplane.hpp:101
constexpr bool intersects(const OtherOrientedSegment &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:666
constexpr Halfplane(PointType source, PointType target, A &&label)
Creates a half-plane from an oriented boundary and stores a label.
Definition halfplane.hpp:95
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 halfplane.hpp:154
constexpr bool intersects(const Shape< PointType > &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:702
constexpr bool boundaryContains(const OtherOrientedSegment &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.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:1725
constexpr bool verticesContain(const OtherPoint &point) const
Returns whether the given point is one of the stored defining points.
Definition predicates.hpp:973
detail::promoted_number_t< NumberType > CoordinateType
Definition halfplane.hpp:55
constexpr PointType & operator[](std::size_t index)
Returns defining point 0 for the source and 1 for the target.
Definition halfplane.hpp:138
constexpr auto distanceLInf(const OtherShape &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition halfplane.hpp:1226
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 halfplane.hpp:1183
constexpr bool intersects(const OtherPoint &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:622
constexpr bool intersects(const EmptyShape< EmptyPoint > &) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition halfplane.hpp:655
constexpr bool isVertical() const
Returns whether the boundary line is vertical.
Definition predicates.hpp:962
constexpr bool interiorsIntersect(const Shape< PointType > &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:790
constexpr bool contains(const OtherLine &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:882
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:650
constexpr bool interiorsIntersect(const OtherOrientedSegment &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:732
constexpr bool operator==(const Halfplane &other) const
Tests equality of the represented half-plane.
Definition predicates.hpp:940
constexpr bool interiorsIntersect(const OtherLine &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:689
constexpr Halfplane & operator-=(const OtherPoint &translation)
Translates the half-plane by the negation of the given point in place.
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:661
constexpr bool crosses(const EmptyShape< EmptyPoint > &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition halfplane.hpp:930
constexpr bool interiorsIntersect(const OtherSegment &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:719
constexpr bool boundaryContains(const OtherTriangle &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:457
constexpr auto distanceL1(const OtherShape &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition halfplane.hpp:1144
constexpr auto regularizedIntersection(const OtherShape &other) const
Forwards a regularized intersection to the shape that owns it.
Definition halfplane.hpp:1007
constexpr auto distanceLInf(const OtherOrientedLine &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:431
constexpr const PointType & target() const
Definition halfplane.hpp:193
constexpr bool interiorsIntersect(const OtherRay &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:745
constexpr auto distanceLInf(const OtherOrientedSegment &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:413
constexpr auto squaredDistance(const OtherRay &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:436
constexpr Halfplane(PointType source, PointType target)
Creates a half-plane from an oriented boundary line.
Definition halfplane.hpp:72
constexpr bool interiorsIntersect(const EmptyShape< EmptyPoint > &) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition halfplane.hpp:696
constexpr auto distanceLInf(const OtherSegment &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:404
constexpr bool crosses(const OtherRay &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:524
constexpr bool separates(const OtherDisk &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1448
constexpr bool crosses(const OtherSegment &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:510
constexpr bool crosses(const OtherOrientedLine &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:503
constexpr bool contains(const OtherPoint &point) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:872
constexpr bool boundaryContains(const OtherDisk &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition halfplane.hpp:487
constexpr bool intersects(const OtherSegment &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:657
constexpr bool separates(const OtherHalfplane &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1428
constexpr auto closestPoints(const OtherShape &other) const
Returns the pair of points realizing the distance, nothing when the shapes meet.
Definition closest.hpp:475
constexpr bool intersects(const OtherHalfplane &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:688
constexpr bool contains(const OtherPolyline &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2411
bool separates(const OtherSet &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:5951
constexpr bool contains(const OtherRectangle &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:931
constexpr bool contains(const OtherRegion &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2786
constexpr auto distanceL1(const OtherRay &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:452
constexpr bool contains(const OtherChain &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2049
constexpr const PointType & operator[](std::size_t index) const
Returns defining point 0 for the source and 1 for the target.
Definition halfplane.hpp:133
constexpr bool crosses(const OtherLine &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:496
constexpr bool contains(const OtherPolygon &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1756
constexpr bool separates(const OtherSegment &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1396
detail::floating_result_t< ResultNumber > squaredDistance(const Disk< DiskPointType, DiskLabel > &disk) const
Returns the squared Euclidean distance to a disk.
Definition halfplane.hpp:1082
constexpr bool boundaryContains(const Shape< PointType > &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1125
constexpr Halfplane scaledDownX(const OtherNumber scalar) const
Returns the half-plane with its x-coordinates divided by a divisor.
constexpr bool boundaryContains(const OtherPoint &point) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:405
constexpr bool isUndefined() const
Returns whether the half-plane is degenerate without collapsing to a point or to a segment.
Definition predicates.hpp:957
constexpr bool interiorContains(const OtherRegion &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:2088
constexpr auto distanceL1(const OtherOrientedSegment &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:425
constexpr PointType & target()
Definition halfplane.hpp:196
constexpr void scaleUpY(const OtherNumber scalar)
Multiplies the half-plane's y-coordinates by a factor in place.
Definition transformations.hpp:1498
constexpr bool separates(const OtherOrientedSegment &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1403
constexpr bool interiorContains(const OtherSegment &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:689
constexpr bool interiorContains(const OtherSet &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition halfplane.hpp:860
constexpr bool separates(const OtherChain &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:3179
constexpr bool boundaryContains(const OtherChain &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1184
constexpr Halfplane scaledUpX(const OtherNumber scalar) const
Returns the half-plane with its x-coordinates multiplied by a factor.
constexpr bool interiorsIntersect(const OtherHalfplane &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:762
constexpr bool crosses(const OtherHalfplane &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:531
constexpr bool interiorContains(const OtherDisk &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:747
constexpr auto cend() const
Returns an iterator past the target defining point.
Definition halfplane.hpp:265
constexpr bool intersects(const OtherShape &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition halfplane.hpp:649
constexpr bool boundaryContains(const OtherHalfplane &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:466
constexpr auto distanceL1(const OtherOrientedLine &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:443
constexpr HalfplaneIntersection< PointType > asHalfplaneIntersection() const
Returns the half-plane as a half-plane intersection.
Definition halfplane.hpp:352
constexpr auto squaredDistance(const OtherSegment &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:400
constexpr bool crosses(const OtherOrientedSegment &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:517
constexpr auto minkowskiSum(const OtherShape &other) const
Returns the Minkowski sum of this shape and another (A ⊕ B).
Definition minkowski.hpp:799
constexpr bool separates(const OtherLine &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1382
constexpr auto intersection(const OtherRegion &other) const
Adds this half-plane to an existing half-plane intersection without deriving vertices.
Definition halfplane.hpp:984
constexpr Line< PointType > asLine() const
Returns the boundary line without orientation.
Definition halfplane.hpp:318
constexpr bool interiorContains(const OtherPoint &point) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:661
constexpr OrientedLine< PointType > asOrientedLine() const
Returns the oriented boundary line.
Definition halfplane.hpp:334
constexpr bool boundaryContains(const OtherRay &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:438
bool separates(const OtherRegion &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:5695
constexpr bool isHorizontal() const
Returns whether the boundary line is horizontal.
Definition predicates.hpp:967
constexpr auto distanceL1(const OtherHalfplane &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:461
constexpr bool crosses(const OtherPoint &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:490
constexpr auto cbegin() const
Returns an iterator to the source defining point.
Definition halfplane.hpp:244
constexpr bool interiorContains(const OtherRegion &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
constexpr const PointType & source() const
Definition halfplane.hpp:181
constexpr bool isDegenerate() const
Returns whether the defining points coincide.
Definition predicates.hpp:952
constexpr auto minkowskiErosion(const OtherShape &other) const
Returns the Minkowski erosion of this shape by another (A ⊖ B).
Definition minkowskierosion.hpp:632
constexpr bool separates(const EmptyShape< EmptyPoint > &) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition halfplane.hpp:567
Halfplane< Point< ResultNumber, typename PointType_::LabelType > > minkowskiSum(const OtherDisk &other) const
Returns the Minkowski sum of this half-plane and a disk (A ⊕ B), a half-plane.
Definition minkowski.hpp:837
constexpr ResultNumber slope() const
Returns the slope of the boundary line.
Definition measures.hpp:478
constexpr auto squaredDistance(const OtherLine &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:418
constexpr auto end()
Definition halfplane.hpp:256
constexpr bool contains(const OtherDisk &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:991
constexpr auto distanceLInf(const OtherRay &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:440
constexpr auto distanceL1(const OtherSegment &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:416
constexpr bool interiorContains(const OtherHalfplane &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:765
constexpr bool boundaryContains(const OtherRegion &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
constexpr bool interiorContains(const OtherRectangle &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:717
constexpr bool boundaryContains(const OtherConvex &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition halfplane.hpp:475
constexpr bool contains(const OtherOrientedSegment &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:906
constexpr Halfplane()=default
Creates the degenerate half-plane (0,0)->(0,0).
constexpr auto distanceLInf(const OtherHalfplane &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:449
Halfplane< Point< ResultNumber, typename PointType_::LabelType > > minkowskiErosion(const OtherDisk &other) const
Returns the Minkowski erosion of this half-plane by a disk (A ⊖ B), a half-plane.
Definition minkowskierosion.hpp:772
constexpr Halfplane scaledUpY(const OtherNumber scalar) const
Returns the half-plane with its y-coordinates multiplied by a factor.
EPoint PointType
Definition halfplane.hpp:52
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
ERational NumberType
Definition point.hpp:131
Half-infinite line starting from one source point plus optional ray label.
Definition ray.hpp:51
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