Pangolin
Header-only C++20 plane computational geometry library
Loading...
Searching...
No Matches
convex.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "shape/disk.hpp"
4
5#include <algorithm>
6#include <vector>
7#include <cassert>
8#include <compare>
9#include <concepts>
10#include <cstddef>
11#include <functional>
12#include <iterator>
13#include <limits>
14#include <optional>
15#include <ostream>
16#include <ranges>
17#include <type_traits>
18#include <utility>
19
20
21namespace pgl::detail {
47template <class RandomIt, class Key = std::identity>
48constexpr RandomIt cyclicMax(RandomIt first, RandomIt last, Key key = {}) {
49 using diff_t = typename std::iterator_traits<RandomIt>::difference_type;
50 const diff_t n = last - first;
51
52 if (n == 0)
53 return last;
54
55 diff_t lo = 0;
56 diff_t hi = n - 1;
57
58 while (lo < hi) {
59 const diff_t mid = lo + (hi - lo) / 2;
60 const auto k_lo = key(first[lo]);
61 const auto k_hi = key(first[hi]);
62 const auto k_mid = key(first[mid]);
63 const auto k_next = key(first[mid + 1]);
64
65 if (k_mid < k_next) {
66 // Ascending at mid: head right, unless the left endpoint dominates both
67 // the ongoing ascent and the right endpoint (then the peak is on the left).
68 if (k_next > k_lo || k_hi > k_lo)
69 lo = mid + 1;
70 else
71 hi = mid;
72 } else {
73 // Descending at mid: head left, unless the right endpoint dominates both
74 // mid and the left endpoint (then the peak is on the right).
75 if (k_mid > k_hi || k_lo > k_hi)
76 hi = mid;
77 else
78 lo = mid + 1;
79 }
80 }
81
82 return first + lo;
83}
84
103template <class RandomIt, class Key = std::identity>
104constexpr RandomIt cyclicMaxOrPositive(RandomIt first, RandomIt last, Key key = {}) {
105 using diff_t = typename std::iterator_traits<RandomIt>::difference_type;
106 const diff_t n = last - first;
107
108 if (n == 0)
109 return last;
110
111 diff_t lo = 0;
112 diff_t hi = n - 1;
113
114 while (lo < hi) {
115 const diff_t mid = lo + (hi - lo) / 2;
116 const auto k_lo = key(first[lo]);
117 if (k_lo > 0) return first + lo;
118 const auto k_hi = key(first[hi]);
119 if (k_hi > 0) return first + hi;
120 const auto k_mid = key(first[mid]);
121 if (k_mid > 0) return first + mid;
122 const auto k_next = key(first[mid + 1]);
123 if (k_next > 0) return first + mid + 1;
124
125 if (k_mid < k_next) {
126 // Ascending at mid: head right, unless the left endpoint dominates both
127 // the ongoing ascent and the right endpoint (then the peak is on the left).
128 if (k_next > k_lo || k_hi > k_lo)
129 lo = mid + 1;
130 else
131 hi = mid;
132 } else {
133 // Descending at mid: head left, unless the right endpoint dominates both
134 // mid and the left endpoint (then the peak is on the right).
135 if (k_mid > k_hi || k_lo > k_hi)
136 hi = mid;
137 else
138 lo = mid + 1;
139 }
140 }
141
142 return first + lo;
143}
144
145
146} // namespace pgl::detail
147
148
149namespace pgl {
150
151template <class PointType = Point<>, class Label>
152struct Convex;
153
155
156template <std::ranges::input_range Range>
157requires detail::is_point_v<std::ranges::range_value_t<Range>>
159
160template <class Number>
161requires (!detail::is_point_v<Number>)
162Convex(std::initializer_list<Number>) -> Convex<Point<Number>, NoLabel>;
163
164template <class Number>
165requires (!detail::is_point_v<Number>)
166Convex(std::initializer_list<Number>, bool) -> Convex<Point<Number>, NoLabel>;
167
168
169template <class PointType_, class TLabel>
170struct Convex {
171 using PointType = PointType_;
172 using NumberType = PointType::NumberType;
173 using LabelType = TLabel;
174 static_assert(detail::is_point_v<PointType>, "Convex requires pgl::Point vertices");
175
176 template <bool Oriented>
177 using BoundaryType = std::conditional_t<Oriented, OrientedSegment<PointType>, Segment<PointType>>;
178
179 template <bool Oriented>
180 class BoundaryIterator;
181
182 using EdgeIterator = BoundaryIterator<false>;
183 using OrientedEdgeIterator = BoundaryIterator<true>;
184
188 constexpr Convex() = default;
189
197 template<std::ranges::input_range Range = std::initializer_list<PointType>>
198 requires std::ranges::common_range<Range> &&
199 std::convertible_to<std::ranges::range_value_t<Range>, PointType>
200 constexpr explicit Convex(Range&& points, bool trusted = false) {
201 if (trusted) {
202 points_.reserve(points.size());
203 for (const auto &p : points) {
204 points_.push_back(p);
205 }
206 }
207 else {
208 // Compute the hull in the source point type so the orientation
209 // predicates stay exact, then convert the surviving vertices to
210 // PointType (a no-op move when the types already match).
211 auto hull = grahamScan(points);
212 if constexpr (std::is_same_v<std::remove_cvref_t<decltype(hull)>, std::vector<PointType>>) {
213 points_ = std::move(hull);
214 } else {
215 points_.reserve(hull.size());
216 for (const auto &p : hull) {
217 points_.push_back(PointType(p));
218 }
219 }
220 }
221 }
222
232 constexpr explicit Convex(std::initializer_list<NumberType> coords, bool trusted = false) {
233 assert(coords.size() % 2 == 0);
234 std::vector<PointType> points;
235 points.reserve(coords.size() / 2);
236 for (auto it = coords.begin(); it != coords.end(); ) {
237 NumberType x = *it++;
238 NumberType y = *it++;
239 points.emplace_back(x, y);
240 }
241 if (trusted) {
242 points_ = std::move(points);
243 }
244 else {
245 points_ = grahamScan(points);
246 }
247 }
248
255 template<PointConcept OtherPointType, class OtherLabelType>
256 requires(std::constructible_from<PointType, const OtherPointType&>)
258 : points_(other.begin(), other.end()), label_(detail::copyLabel<LabelType>(other)) {}
259
268 template <class A = LabelType>
269 requires(detail::has_label_v<A>)
270 constexpr A& label() const {
271 return label_;
272 }
273
279 constexpr const PointType operator[](std::size_t index) const {
280 assert(index < size());
281 return points_[index] + translation_;
282 }
283
289 constexpr PointType get(std::ptrdiff_t index) const {
290 const std::ptrdiff_t n = static_cast<std::ptrdiff_t>(size());
291 return (*this)[static_cast<std::size_t>(((index % n) + n) % n)];
292 }
293
298 constexpr auto begin() const {
299 return Iterator(points_.begin(), translation_);
300 }
301
306 constexpr auto cbegin() const {
307 return Iterator(points_.cbegin(), translation_);
308 }
309
314 constexpr auto end() const {
315 return Iterator(points_.end(), translation_);
316 }
317
322 constexpr auto cend() const {
323 return Iterator(points_.cend(), translation_);
324 }
325
331 constexpr auto operator<=>(const Convex& other) const {
332 if (auto cmp = points_.size() <=> other.points_.size(); cmp != 0) {
333 return cmp;
334 }
335 for (std::size_t i = 0; i < points_.size(); ++i) {
336 if (auto cmp = points_[i] + translation_ <=> other.points_[i] + other.translation_; cmp != 0) {
337 return cmp;
338 }
339 }
340 return std::strong_ordering::equal;
341 }
342
348 constexpr bool operator==(const Convex& other) const {
349 if (points_.size() != other.points_.size()) {
350 return false;
351 }
352 for (std::size_t i = 0; i < points_.size(); ++i) {
353 if (points_[i] + translation_ != other.points_[i] + other.translation_) {
354 return false;
355 }
356 }
357 return true;
358 }
359
361 template<AnyShapeConcept OtherShape>
362 [[nodiscard]] constexpr bool samePointSet(const OtherShape& other) const;
363
368 constexpr auto twiceArea() const;
369
375 template <class ResultNumber = division_result_t<NumberType>>
376 constexpr auto area() const;
377
390 [[nodiscard]] constexpr bool empty() const {
391 return size() == 0;
392 }
393
401 constexpr bool isDegenerate() const;
402
414 [[nodiscard]] constexpr bool isPoint() const;
415
423 [[nodiscard]] constexpr std::optional<PointType> getIfPoint() const;
424
435 [[nodiscard]] constexpr bool isSegment() const;
436
445 [[nodiscard]] constexpr std::optional<BoundaryType<false>> getIfSegment() const;
446
460 [[nodiscard]] constexpr bool isUndefined() const;
461
473 constexpr const Rectangle<PointType>& bbox() const;
474
491 template <class ResultNumber = grid_number_t<typename PointType_::NumberType>>
492 requires(detail::extended_integral<ResultNumber> || std::same_as<ResultNumber, BigInt>)
495
501 template <std::floating_point ResultNumber = double>
503
508 constexpr const std::vector<PointType> vertices() const {
509 auto ret = points_;
510 for (auto& vertex : ret) {
511 vertex += translation_;
512 }
513 return ret;
514 }
515
521 [[nodiscard]] constexpr Convex<PointType> convexHull() const {
522 return Convex<PointType>(*this);
523 }
524
529 constexpr std::vector<Segment<PointType>> edges() const {
530 std::vector<Segment<PointType>> result;
531 auto translatedVertices = vertices();
532 for (std::size_t i = 0; i < translatedVertices.size(); ++i) {
533 const auto& p1 = translatedVertices[i];
534 const auto& p2 = translatedVertices[(i + 1) % translatedVertices.size()];
535 result.emplace_back(p1, p2);
536 }
537 return result;
538 }
539
544 constexpr std::vector<OrientedSegment<PointType>> orientedEdges() const {
545 std::vector<OrientedSegment<PointType>> result;
546 auto translatedVertices = vertices();
547 for (std::size_t i = 0; i < translatedVertices.size(); ++i) {
548 const auto& p1 = translatedVertices[i];
549 const auto& p2 = translatedVertices[(i + 1) % translatedVertices.size()];
550 result.emplace_back(p1, p2);
551 }
552 return result;
553 }
554
563 constexpr auto verticesView() const {
564 return std::ranges::subrange(begin(), end());
565 }
566
575 constexpr auto edgesView() const {
576 return std::ranges::subrange(edgesBegin(), edgesEnd());
577 }
578
583 constexpr auto orientedEdgesView() const {
584 return std::ranges::subrange(orientedEdgesBegin(), orientedEdgesEnd());
585 }
586
591 constexpr EdgeIterator edgesBegin() const {
592 return EdgeIterator(this, 0);
593 }
594
599 constexpr EdgeIterator edgesEnd() const {
600 return EdgeIterator(this, size());
601 }
602
608 return OrientedEdgeIterator(this, 0);
609 }
610
616 return OrientedEdgeIterator(this, size());
617 }
618
627 [[nodiscard]] constexpr explicit operator Polygon<PointType>() const {
628 return Polygon<PointType>(*this, !isDegenerate());
629 }
630
636 [[nodiscard]] constexpr Polygon<PointType> asPolygon() const {
637 return static_cast<Polygon<PointType>>(*this);
638 }
639
646 [[nodiscard]] constexpr PolygonWithHoles<PointType> asPolygonWithHoles() const {
648 }
649
659 [[nodiscard]] constexpr PolygonSet<PointType> asPolygonSet() const {
661 }
662
674 }
675
692 if (size() <= 1) {
693 return MonotoneChain<PointType>(vertices(), true);
694 }
695 // Vertices are stored counterclockwise from the lexicographic minimum,
696 // so walking up to the lexicographic maximum traverses the lower chain,
697 // already in increasing lexicographic order.
698 const std::size_t maximum = maxIndex();
699 std::vector<PointType> chain;
700 chain.reserve(maximum + 1);
701 for (std::size_t i = 0; i <= maximum; ++i) {
702 chain.push_back((*this)[i]);
703 }
704 return MonotoneChain<PointType>(chain, true);
705 }
706
719 if (size() <= 1) {
720 return MonotoneChain<PointType>(vertices(), true);
721 }
722 // The upper chain is the rest of the boundary: the lexicographic maximum
723 // back to vertex 0 (the lexicographic minimum). Reading it backwards —
724 // vertex 0, then n-1 down to the maximum — yields increasing
725 // lexicographic order, which is the chain's canonical form.
726 const std::size_t n = size();
727 const std::size_t maximum = maxIndex();
728 std::vector<PointType> chain;
729 chain.reserve(n - maximum + 1);
730 chain.push_back((*this)[0]);
731 for (std::size_t i = n; i > maximum; --i) {
732 chain.push_back((*this)[i - 1]);
733 }
734 return MonotoneChain<PointType>(chain, true);
735 }
736
746 template <PointConcept OtherPoint>
747 constexpr void insert(const OtherPoint& point);
748
761 template <class TShape>
762 requires(!detail::is_point_v<TShape> && requires(const TShape& shape) { shape.vertices(); })
763 constexpr void insert(const TShape& shape);
764
776 template <std::ranges::input_range Range = std::initializer_list<PointType>>
777 requires std::ranges::common_range<Range> &&
778 std::convertible_to<std::ranges::range_value_t<Range>, PointType> &&
779 (!requires(const std::remove_cvref_t<Range>& shape) { shape.vertices(); })
780 constexpr void insert(Range&& range) {
781 // Defined inline so MSVC can match the constrained overload; the
782 // overloaded out-of-line form trips MSVC's C2244.
783 std::vector<PointType> points = vertices();
784 const std::size_t oldSize = points.size();
785 for (const auto& point : range) {
786 points.push_back(static_cast<PointType>(point));
787 }
788 if (points.size() == oldSize) {
789 return;
790 }
791 rebuildHull(points);
792 }
793
800 template <class ResultNumber = division_result_t<NumberType>>
801 constexpr Point<ResultNumber> centroid() const;
802
809 template <class ResultNumber = division_result_t<NumberType>>
811
812
822 template <class ResultNumber = division_result_t<NumberType>>
824
833 template <class OtherShape>
834 [[nodiscard]] constexpr bool pointInsideInteriorContainedIn(const OtherShape& shape) const;
835
840 size_t size() const {
841 return points_.size();
842 }
843
851 constexpr size_t maxIndex() const;
852
862 template<PointConcept OtherPoint>
863 constexpr bool verticesContain(const OtherPoint& point) const;
864
875 constexpr std::ptrdiff_t index(const PointType& point) const;
876
891 constexpr std::vector<std::pair<std::size_t, std::size_t>>
893
906 constexpr Segment<PointType> diameter() const;
907
942
980
1003 template <class ResultNumber = division_result_t<NumberType>>
1004 [[nodiscard]] constexpr ResultNumber squaredMinimumWidth() const;
1005
1022 template <class ApproximateNumber = double>
1023 [[nodiscard]] ApproximateNumber minimumWidth() const;
1024
1042 template <class UniformRandomBitGenerator>
1043 [[nodiscard]] Disk<Point<NumberType>>
1044 smallestEnclosingDisk(UniformRandomBitGenerator&& generator) const;
1045
1062
1063
1073 template<PointConcept OtherPoint>
1074 constexpr bool boundaryContains(const OtherPoint& point) const;
1075
1090 template<SegmentConcept OtherSegment>
1091 constexpr bool boundaryContains(const OtherSegment& other) const;
1092
1098 template<OrientedSegmentConcept OtherOrientedSegment>
1099 constexpr bool boundaryContains(const OtherOrientedSegment& other) const;
1100
1106 template<LineConcept OtherLine>
1107 constexpr bool boundaryContains(const OtherLine& other) const;
1108
1114 template<OrientedLineConcept OtherOrientedLine>
1115 constexpr bool boundaryContains(const OtherOrientedLine& other) const;
1116
1122 template<RayConcept OtherRay>
1123 constexpr bool boundaryContains(const OtherRay& other) const;
1124
1130 template<HalfplaneConcept OtherHalfplane>
1131 constexpr bool boundaryContains(const OtherHalfplane& other) const;
1132
1138 template<RectangleConcept OtherRectangle>
1139 constexpr bool boundaryContains(const OtherRectangle& other) const;
1140
1146 template<TriangleConcept OtherTriangle>
1147 constexpr bool boundaryContains(const OtherTriangle& other) const;
1148
1155 template<ConvexConcept OtherConvex>
1156 constexpr bool boundaryContains(const OtherConvex& other) const;
1157
1159 template<PolygonConcept OtherPolygon>
1160 constexpr bool boundaryContains(const OtherPolygon& other) const;
1161
1168 template<DiskConcept OtherDisk>
1169 constexpr bool boundaryContains(const OtherDisk& other) const;
1170
1174 template<PointConcept OtherPoint>
1175 constexpr bool boundaryContains(const Shape<OtherPoint>& other) const;
1176
1177
1192 template<class OtherNumberType>
1193 constexpr std::optional<std::array<Segment<PointType>, 2>> edgesAtX(OtherNumberType x) const;
1194
1204 template<PointConcept OtherPoint>
1205 constexpr bool contains(const OtherPoint& point) const;
1206
1216 template<SegmentConcept OtherSegment>
1217 constexpr bool contains(const OtherSegment& other) const;
1218
1228 template<OrientedSegmentConcept OtherOrientedSegment>
1229 constexpr bool contains(const OtherOrientedSegment& other) const;
1230
1237 template<LineConcept OtherLine>
1238 constexpr bool contains(const OtherLine&) const;
1239
1246 template<OrientedLineConcept OtherOrientedLine>
1247 constexpr bool contains(const OtherOrientedLine&) const;
1248
1255 template<RayConcept OtherRay>
1256 constexpr bool contains(const OtherRay&) const;
1257
1264 template<HalfplaneConcept OtherHalfplane>
1265 constexpr bool contains(const OtherHalfplane&) const;
1266
1276 template<RectangleConcept OtherRectangle>
1277 constexpr bool contains(const OtherRectangle& other) const;
1278
1279
1289 template<TriangleConcept OtherTriangle>
1290 constexpr bool contains(const OtherTriangle& other) const;
1291
1302 template<ConvexConcept OtherConvex>
1303 constexpr bool contains(const OtherConvex& other) const;
1304
1306 template<PolygonConcept OtherPolygon>
1307 constexpr bool contains(const OtherPolygon& other) const;
1308
1309
1315 template<DiskConcept OtherDisk>
1316 constexpr bool contains(const OtherDisk& other) const;
1317
1321 template<PointConcept OtherPoint>
1322 constexpr bool contains(const Shape<OtherPoint>& other) const;
1323
1324 // The empty set is a subset of every shape, so its containment relations are
1325 // true. separates has no symmetric fallback, so it gets an explicit overload
1326 // too; the symmetric intersection/crossing predicates instead reach the
1327 // empty set through the generic OtherShape fallbacks declared below.
1329 template <class EmptyPoint>
1330 [[nodiscard]] constexpr bool contains(const EmptyShape<EmptyPoint>&) const {
1331 return true;
1332 }
1333
1334 template <class EmptyPoint>
1335 [[nodiscard]] constexpr bool boundaryContains(const EmptyShape<EmptyPoint>&) const {
1336 return true;
1337 }
1338
1339 template <class EmptyPoint>
1340 [[nodiscard]] constexpr bool interiorContains(const EmptyShape<EmptyPoint>&) const {
1341 return true;
1342 }
1343
1344 template <class EmptyPoint>
1345 [[nodiscard]] constexpr bool separates(const EmptyShape<EmptyPoint>&) const {
1346 return false;
1347 }
1348
1358 template<PointConcept OtherPoint>
1359 constexpr bool interiorContains(const OtherPoint& point) const;
1360
1370 template<SegmentConcept OtherSegment>
1371 constexpr bool interiorContains(const OtherSegment& other) const;
1372
1382 template<OrientedSegmentConcept OtherOrientedSegment>
1383 constexpr bool interiorContains(const OtherOrientedSegment& other) const;
1384
1391 template<LineConcept OtherLine>
1392 constexpr bool interiorContains(const OtherLine&) const;
1393
1400 template<OrientedLineConcept OtherOrientedLine>
1401 constexpr bool interiorContains(const OtherOrientedLine&) const;
1402
1409 template<RayConcept OtherRay>
1410 constexpr bool interiorContains(const OtherRay&) const;
1411
1418 template<HalfplaneConcept OtherHalfplane>
1419 constexpr bool interiorContains(const OtherHalfplane&) const;
1420
1430 template<RectangleConcept OtherRectangle>
1431 constexpr bool interiorContains(const OtherRectangle& other) const;
1432
1442 template<TriangleConcept OtherTriangle>
1443 constexpr bool interiorContains(const OtherTriangle& other) const;
1444
1455 template<ConvexConcept OtherConvex>
1456 constexpr bool interiorContains(const OtherConvex& other) const;
1457
1459 template<PolygonConcept OtherPolygon>
1460 constexpr bool interiorContains(const OtherPolygon& other) const;
1461
1467 template<DiskConcept OtherDisk>
1468 constexpr bool interiorContains(const OtherDisk& other) const;
1469
1473 template<PointConcept OtherPoint>
1474 constexpr bool interiorContains(const Shape<OtherPoint>& other) const;
1475
1485 template<SegmentConcept OtherSegment>
1486 constexpr bool intersects(const OtherSegment& other) const;
1487
1497 template<OrientedSegmentConcept OtherOrientedSegment>
1498 constexpr bool intersects(const OtherOrientedSegment& other) const;
1499
1509 template<LineConcept OtherLine>
1510 constexpr bool intersects(const OtherLine& other) const;
1511
1521 template<OrientedLineConcept OtherOrientedLine>
1522 constexpr bool intersects(const OtherOrientedLine& other) const;
1523
1533 template<RayConcept OtherRay>
1534 constexpr bool intersects(const OtherRay& other) const;
1535
1545 template<RectangleConcept OtherRectangle>
1546 constexpr bool intersects(const OtherRectangle& other) const;
1547
1557 template<TriangleConcept OtherTriangle>
1558 constexpr bool intersects(const OtherTriangle& other) const;
1559
1569 template<PointConcept OtherPoint>
1570 constexpr bool intersects(const OtherPoint& other) const;
1571
1581 template<HalfplaneConcept OtherHalfplane>
1582 constexpr bool intersects(const OtherHalfplane& other) const;
1583
1594 template<ConvexConcept OtherConvex>
1595 constexpr bool intersects(const OtherConvex& other) const;
1596
1602 template<DiskConcept OtherDisk>
1603 constexpr bool intersects(const OtherDisk& other) const;
1604
1608 template<PointConcept OtherPoint>
1609 constexpr bool intersects(const Shape<OtherPoint>& other) const;
1610
1612 template<typename OtherShape>
1613 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
1614 [[nodiscard]] constexpr bool intersects(const OtherShape& other) const {
1615 return other.intersects(*this);
1616 }
1617
1619 template <class EmptyPoint>
1620 [[nodiscard]] constexpr bool intersects(const EmptyShape<EmptyPoint>&) const {
1621 return false;
1622 }
1623
1629 template<PointConcept OtherPoint>
1630 constexpr bool interiorsIntersect(const OtherPoint& other) const;
1631
1637 template<LineConcept OtherLine>
1638 constexpr bool interiorsIntersect(const OtherLine& other) const;
1639
1645 template<OrientedLineConcept OtherOrientedLine>
1646 constexpr bool interiorsIntersect(const OtherOrientedLine& other) const;
1647
1657 template<SegmentConcept OtherSegment>
1658 constexpr bool interiorsIntersect(const OtherSegment& other) const;
1659
1665 template<OrientedSegmentConcept OtherOrientedSegment>
1666 constexpr bool interiorsIntersect(const OtherOrientedSegment& other) const;
1667
1677 template<RayConcept OtherRay>
1678 constexpr bool interiorsIntersect(const OtherRay& other) const;
1679
1685 template<HalfplaneConcept OtherHalfplane>
1686 constexpr bool interiorsIntersect(const OtherHalfplane& other) const;
1687
1694 template<RectangleConcept OtherRectangle>
1695 constexpr bool interiorsIntersect(const OtherRectangle& other) const;
1696
1703 template<TriangleConcept OtherTriangle>
1704 constexpr bool interiorsIntersect(const OtherTriangle& other) const;
1705
1712 template<ConvexConcept OtherConvex>
1713 constexpr bool interiorsIntersect(const OtherConvex& other) const;
1714
1720 template<DiskConcept OtherDisk>
1721 constexpr bool interiorsIntersect(const OtherDisk& other) const;
1722
1726 template<PointConcept OtherPoint>
1727 constexpr bool interiorsIntersect(const Shape<OtherPoint>& other) const;
1728
1730 template<typename OtherShape>
1731 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
1732 [[nodiscard]] constexpr bool interiorsIntersect(const OtherShape& other) const {
1733 return other.interiorsIntersect(*this);
1734 }
1735
1737 template <class EmptyPoint>
1738 [[nodiscard]] constexpr bool interiorsIntersect(const EmptyShape<EmptyPoint>&) const {
1739 return false;
1740 }
1741
1747 template<PointConcept OtherPoint>
1748 constexpr bool separates(const OtherPoint&) const;
1749
1761 template<SegmentConcept OtherSegment>
1762 constexpr bool separates(const OtherSegment& other) const;
1763
1769 template<OrientedSegmentConcept OtherOrientedSegment>
1770 constexpr bool separates(const OtherOrientedSegment& other) const;
1771
1777 template<LineConcept OtherLine>
1778 constexpr bool separates(const OtherLine& other) const;
1779
1785 template<OrientedLineConcept OtherOrientedLine>
1786 constexpr bool separates(const OtherOrientedLine& other) const;
1787
1796 template<RayConcept OtherRay>
1797 constexpr bool separates(const OtherRay& other) const;
1798
1804 template<HalfplaneConcept OtherHalfplane>
1805 constexpr bool separates(const OtherHalfplane&) const;
1806
1812 template<RectangleConcept OtherRectangle>
1813 constexpr bool separates(const OtherRectangle& other) const;
1814
1820 template<TriangleConcept OtherTriangle>
1821 constexpr bool separates(const OtherTriangle& other) const;
1822
1828 template<ConvexConcept OtherConvex>
1829 constexpr bool separates(const OtherConvex& other) const;
1830
1845 template<PolygonConcept OtherPolygon>
1846 constexpr bool separates(const OtherPolygon& other) const;
1847
1849 template<MonotoneChainConcept OtherChain>
1850 [[nodiscard]] constexpr bool contains(const OtherChain& other) const;
1851
1853 template<MonotoneChainConcept OtherChain>
1854 [[nodiscard]] constexpr bool boundaryContains(const OtherChain& other) const;
1855
1857 template<MonotoneChainConcept OtherChain>
1858 [[nodiscard]] constexpr bool interiorContains(const OtherChain& other) const;
1859
1861 template<MonotoneChainConcept OtherChain>
1862 [[nodiscard]] constexpr bool separates(const OtherChain& other) const;
1863
1865 template<PolylineConcept OtherPolyline>
1866 [[nodiscard]] constexpr bool contains(const OtherPolyline& other) const;
1867
1869 template<PolylineConcept OtherPolyline>
1870 [[nodiscard]] constexpr bool boundaryContains(const OtherPolyline& other) const;
1871
1873 template<PolylineConcept OtherPolyline>
1874 [[nodiscard]] constexpr bool interiorContains(const OtherPolyline& other) const;
1875
1877 template<PolylineConcept OtherPolyline>
1878 [[nodiscard]] constexpr bool separates(const OtherPolyline& other) const;
1879
1881 template<HalfplaneIntersectionConcept OtherRegion>
1882 [[nodiscard]] constexpr bool contains(const OtherRegion& other) const;
1883
1885 template<HalfplaneIntersectionConcept OtherRegion>
1886 [[nodiscard]] constexpr bool boundaryContains(const OtherRegion& other) const;
1887
1889 template<HalfplaneIntersectionConcept OtherRegion>
1890 [[nodiscard]] constexpr bool interiorContains(const OtherRegion& other) const;
1891
1893 template<HalfplaneIntersectionConcept OtherRegion>
1894 [[nodiscard]] constexpr bool separates(const OtherRegion& other) const;
1895
1903 template<PolygonWithHolesConcept OtherRegion>
1904 [[nodiscard]] constexpr bool contains(const OtherRegion& other) const;
1905
1912 template<PolygonWithHolesConcept OtherRegion>
1913 [[nodiscard]] constexpr bool boundaryContains(const OtherRegion& other) const;
1914
1916 template<PolygonWithHolesConcept OtherRegion>
1917 [[nodiscard]] constexpr bool interiorContains(const OtherRegion& other) const;
1918
1926 template<PolygonWithHolesConcept OtherRegion>
1927 [[nodiscard]] bool separates(const OtherRegion& other) const;
1928
1929 // -------------------------------------------------------------------------
1930 // A set of regions
1931 //
1932 // It outranks every other shape, so the symmetric relations reach it through
1933 // the rank-based forwarders and only the asymmetric ones are answered here.
1934 // A set is the union of its components, so it is contained exactly when
1935 // every component is — no matter what this shape is.
1936
1938 template<PolygonSetConcept OtherSet>
1939 [[nodiscard]] constexpr bool contains(const OtherSet& other) const {
1940 for (const auto& component : other) {
1941 if (!contains(component)) {
1942 return false;
1943 }
1944 }
1945 return true;
1946 }
1947
1949 template<PolygonSetConcept OtherSet>
1950 [[nodiscard]] constexpr bool boundaryContains(const OtherSet& other) const {
1951 for (const auto& component : other) {
1952 if (!boundaryContains(component)) {
1953 return false;
1954 }
1955 }
1956 return true;
1957 }
1958
1960 template<PolygonSetConcept OtherSet>
1961 [[nodiscard]] constexpr bool interiorContains(const OtherSet& other) const {
1962 for (const auto& component : other) {
1963 if (!interiorContains(component)) {
1964 return false;
1965 }
1966 }
1967 return true;
1968 }
1969
1978 template<PolygonSetConcept OtherSet>
1979 [[nodiscard]] bool separates(const OtherSet& other) const;
1980
1986 template<DiskConcept OtherDisk>
1987 constexpr bool separates(const OtherDisk& other) const;
1988
1992 template<PointConcept OtherPoint>
1993 constexpr bool separates(const Shape<OtherPoint>& other) const;
1994
2000 template<PointConcept OtherPoint>
2001 constexpr bool crosses(const OtherPoint&) const;
2002
2008 template<SegmentConcept OtherSegment>
2009 constexpr bool crosses(const OtherSegment& other) const;
2010
2016 template<OrientedSegmentConcept OtherOrientedSegment>
2017 constexpr bool crosses(const OtherOrientedSegment& other) const;
2018
2024 template<LineConcept OtherLine>
2025 constexpr bool crosses(const OtherLine& other) const;
2026
2032 template<OrientedLineConcept OtherOrientedLine>
2033 constexpr bool crosses(const OtherOrientedLine& other) const;
2034
2040 template<RayConcept OtherRay>
2041 constexpr bool crosses(const OtherRay& other) const;
2042
2048 template<HalfplaneConcept OtherHalfplane>
2049 constexpr bool crosses(const OtherHalfplane&) const;
2050
2056 template<RectangleConcept OtherRectangle>
2057 constexpr bool crosses(const OtherRectangle& other) const;
2058
2064 template<TriangleConcept OtherTriangle>
2065 constexpr bool crosses(const OtherTriangle& other) const;
2066
2073 template<ConvexConcept OtherConvex>
2074 constexpr bool crosses(const OtherConvex& other) const;
2075
2081 template<DiskConcept OtherDisk>
2082 constexpr bool crosses(const OtherDisk& other) const;
2083
2087 template<PointConcept OtherPoint>
2088 constexpr bool crosses(const Shape<OtherPoint>& other) const;
2089
2091 template<typename OtherShape>
2092 requires (!PointConcept<OtherShape> && detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
2093 [[nodiscard]] constexpr bool crosses(const OtherShape& other) const {
2094 return other.crosses(*this);
2095 }
2096
2098 template <class EmptyPoint>
2099 [[nodiscard]] constexpr bool crosses(const EmptyShape<EmptyPoint>&) const {
2100 return false;
2101 }
2102
2128 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
2129 [[nodiscard]] constexpr auto squaredDistance(const OtherPoint& point) const;
2130
2160 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
2161 [[nodiscard]] constexpr auto squaredDistance(const OtherSegment& other) const;
2162
2179 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
2180 [[nodiscard]] constexpr auto squaredDistance(const OtherOrientedSegment& other) const;
2181
2209 template <class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
2210 [[nodiscard]] constexpr auto squaredDistance(const OtherConvex& other) const;
2211
2228 template <class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
2229 [[nodiscard]] constexpr auto squaredDistance(const OtherTriangle& other) const;
2230
2247 template <class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
2248 [[nodiscard]] constexpr auto squaredDistance(const OtherRectangle& other) const;
2249
2273 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
2274 [[nodiscard]] constexpr auto squaredDistance(const OtherLine& other) const;
2275
2292 template <class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
2293 [[nodiscard]] constexpr auto squaredDistance(const OtherOrientedLine& other) const;
2294
2322 template <class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
2323 [[nodiscard]] constexpr auto squaredDistance(const OtherRay& other) const;
2324
2343 template <class ResultNumber = division_result_t<NumberType>, HalfplaneConcept OtherHalfplane>
2344 [[nodiscard]] constexpr auto squaredDistance(const OtherHalfplane& other) const;
2345
2362 template <class ResultNumber = double, DiskConcept OtherDisk>
2363 [[nodiscard]] detail::floating_result_t<ResultNumber> squaredDistance(const OtherDisk& other) const;
2364
2372 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
2373 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
2374 && requires(const OtherShape& o, const Convex& self) {
2375 o.template squaredDistance<ResultNumber>(self);
2376 })
2377 [[nodiscard]] constexpr auto squaredDistance(const OtherShape& other) const {
2378 return other.template squaredDistance<ResultNumber>(*this);
2379 }
2380
2393 template <class ResultNumber = NumberType, BoundedPolygonalConcept OtherShape>
2394 requires detail::ClosestPairConcept<Convex<PointType_, TLabel>, OtherShape>
2395 [[nodiscard]] constexpr auto closestSegments(const OtherShape& other) const;
2396
2413 template <class ResultNumber = division_result_t<NumberType>, class OtherShape>
2414 requires detail::ClosestPointsPairConcept<Convex<PointType_, TLabel>, OtherShape>
2415 [[nodiscard]] constexpr auto closestPoints(const OtherShape& other) const;
2416
2425 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
2426 [[nodiscard]] constexpr auto distanceL1(const OtherPoint& point) const;
2427
2429 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
2430 [[nodiscard]] constexpr auto distanceL1(const OtherSegment& other) const;
2431
2433 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
2434 [[nodiscard]] constexpr auto distanceL1(const OtherOrientedSegment& other) const;
2435
2437 template <class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
2438 [[nodiscard]] constexpr auto distanceL1(const OtherConvex& other) const;
2439
2441 template <class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
2442 [[nodiscard]] constexpr auto distanceL1(const OtherTriangle& other) const;
2443
2445 template <class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
2446 [[nodiscard]] constexpr auto distanceL1(const OtherRectangle& other) const;
2447
2449 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
2450 [[nodiscard]] constexpr auto distanceL1(const OtherLine& other) const;
2451
2453 template <class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
2454 [[nodiscard]] constexpr auto distanceL1(const OtherOrientedLine& other) const;
2455
2457 template <class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
2458 [[nodiscard]] constexpr auto distanceL1(const OtherRay& other) const;
2459
2461 template <class ResultNumber = division_result_t<NumberType>, HalfplaneConcept OtherHalfplane>
2462 [[nodiscard]] constexpr auto distanceL1(const OtherHalfplane& other) const;
2463
2471 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
2472 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
2473 && requires(const OtherShape& o, const Convex& self) {
2474 o.template distanceL1<ResultNumber>(self);
2475 })
2476 [[nodiscard]] constexpr auto distanceL1(const OtherShape& other) const {
2477 return other.template distanceL1<ResultNumber>(*this);
2478 }
2479
2495 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
2496 [[nodiscard]] constexpr auto intersection(const Shape<OtherPoint>& other) const {
2497 return other.template intersection<ResultNumber>(*this);
2498 }
2499
2501 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
2502 [[nodiscard]] auto regularizedIntersection(const Shape<OtherPoint>& other) const {
2503 return other.template regularizedIntersection<ResultNumber>(*this);
2504 }
2505
2518 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
2519 [[nodiscard]] auto regularizedUnion(const Shape<OtherPoint>& other) const {
2520 return other.template regularizedUnion<ResultNumber>(*this);
2521 }
2522
2537 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
2538 [[nodiscard]] auto difference(const Shape<OtherPoint>& other) const {
2539 return Shape<OtherPoint>(*this).template difference<ResultNumber>(other);
2540 }
2541
2554 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
2555 [[nodiscard]] auto symmetricDifference(const Shape<OtherPoint>& other) const {
2556 return other.template symmetricDifference<ResultNumber>(*this);
2557 }
2558
2566 template <class ResultNumber = double, PointConcept OtherPoint>
2567 [[nodiscard]] constexpr auto distanceL1(const Shape<OtherPoint>& other) const {
2568 return other.template distanceL1<ResultNumber>(*this);
2569 }
2570
2579 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
2580 [[nodiscard]] constexpr auto distanceLInf(const OtherPoint& point) const;
2581
2583 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
2584 [[nodiscard]] constexpr auto distanceLInf(const OtherSegment& other) const;
2585
2587 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
2588 [[nodiscard]] constexpr auto distanceLInf(const OtherOrientedSegment& other) const;
2589
2591 template <class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
2592 [[nodiscard]] constexpr auto distanceLInf(const OtherConvex& other) const;
2593
2595 template <class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
2596 [[nodiscard]] constexpr auto distanceLInf(const OtherTriangle& other) const;
2597
2599 template <class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
2600 [[nodiscard]] constexpr auto distanceLInf(const OtherRectangle& other) const;
2601
2603 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
2604 [[nodiscard]] constexpr auto distanceLInf(const OtherLine& other) const;
2605
2607 template <class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
2608 [[nodiscard]] constexpr auto distanceLInf(const OtherOrientedLine& other) const;
2609
2611 template <class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
2612 [[nodiscard]] constexpr auto distanceLInf(const OtherRay& other) const;
2613
2615 template <class ResultNumber = division_result_t<NumberType>, HalfplaneConcept OtherHalfplane>
2616 [[nodiscard]] constexpr auto distanceLInf(const OtherHalfplane& other) const;
2617
2625 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
2626 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
2627 && requires(const OtherShape& o, const Convex& self) {
2628 o.template distanceLInf<ResultNumber>(self);
2629 })
2630 [[nodiscard]] constexpr auto distanceLInf(const OtherShape& other) const {
2631 return other.template distanceLInf<ResultNumber>(*this);
2632 }
2633
2635 template <class ResultNumber = double, PointConcept OtherPoint>
2636 [[nodiscard]] constexpr auto distanceLInf(const Shape<OtherPoint>& other) const {
2637 return other.template distanceLInf<ResultNumber>(*this);
2638 }
2639
2641 template <class ResultNumber = NumberType, PointConcept OtherPoint>
2642 [[nodiscard]] constexpr auto hausdorffDistanceL1(const OtherPoint& point) const;
2643
2645 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
2646 [[nodiscard]] constexpr auto hausdorffDistanceL1(const OtherSegment& other) const;
2647
2649 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
2650 [[nodiscard]] constexpr auto hausdorffDistanceL1(const OtherOrientedSegment& other) const;
2651
2653 template <class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
2654 [[nodiscard]] constexpr auto hausdorffDistanceL1(const OtherRectangle& other) const;
2655
2657 template <class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
2658 [[nodiscard]] constexpr auto hausdorffDistanceL1(const OtherTriangle& other) const;
2659
2661 template <class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
2662 [[nodiscard]] constexpr auto hausdorffDistanceL1(const OtherConvex& other) const;
2663
2671 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
2672 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
2673 && requires(const OtherShape& o, const Convex& self) {
2674 o.template hausdorffDistanceL1<ResultNumber>(self);
2675 })
2676 [[nodiscard]] constexpr auto hausdorffDistanceL1(const OtherShape& other) const {
2677 return other.template hausdorffDistanceL1<ResultNumber>(*this);
2678 }
2679
2681 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
2682 [[nodiscard]] constexpr auto hausdorffDistanceL1(const Shape<OtherPoint>& other) const {
2683 return other.template hausdorffDistanceL1<ResultNumber>(*this);
2684 }
2685
2687 template <class ResultNumber = NumberType, PointConcept OtherPoint>
2688 [[nodiscard]] constexpr auto hausdorffDistanceLInf(const OtherPoint& point) const;
2689
2691 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
2692 [[nodiscard]] constexpr auto hausdorffDistanceLInf(const OtherSegment& other) const;
2693
2695 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
2696 [[nodiscard]] constexpr auto hausdorffDistanceLInf(const OtherOrientedSegment& other) const;
2697
2699 template <class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
2700 [[nodiscard]] constexpr auto hausdorffDistanceLInf(const OtherRectangle& other) const;
2701
2703 template <class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
2704 [[nodiscard]] constexpr auto hausdorffDistanceLInf(const OtherTriangle& other) const;
2705
2707 template <class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
2708 [[nodiscard]] constexpr auto hausdorffDistanceLInf(const OtherConvex& other) const;
2709
2717 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
2718 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
2719 && requires(const OtherShape& o, const Convex& self) {
2720 o.template hausdorffDistanceLInf<ResultNumber>(self);
2721 })
2722 [[nodiscard]] constexpr auto hausdorffDistanceLInf(const OtherShape& other) const {
2723 return other.template hausdorffDistanceLInf<ResultNumber>(*this);
2724 }
2725
2727 template <class ResultNumber = division_result_t<NumberType>, PointConcept OtherPoint>
2728 [[nodiscard]] constexpr auto hausdorffDistanceLInf(const Shape<OtherPoint>& other) const {
2729 return other.template hausdorffDistanceLInf<ResultNumber>(*this);
2730 }
2731
2741 template <class ResultNumber = NumberType, PointConcept OtherPoint>
2742 [[nodiscard]] constexpr auto squaredHausdorffDistance(const OtherPoint& point) const;
2743
2745 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
2746 [[nodiscard]] constexpr auto squaredHausdorffDistance(const OtherSegment& other) const;
2747
2749 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
2750 [[nodiscard]] constexpr auto squaredHausdorffDistance(const OtherOrientedSegment& other) const;
2751
2753 template <class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
2754 [[nodiscard]] constexpr auto squaredHausdorffDistance(const OtherRectangle& other) const;
2755
2757 template <class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
2758 [[nodiscard]] constexpr auto squaredHausdorffDistance(const OtherTriangle& other) const;
2759
2761 template <class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
2762 [[nodiscard]] constexpr auto squaredHausdorffDistance(const OtherConvex& other) const;
2763
2771 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
2772 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
2773 && requires(const OtherShape& o, const Convex& self) {
2775 })
2776 [[nodiscard]] constexpr auto squaredHausdorffDistance(const OtherShape& other) const {
2777 return other.template squaredHausdorffDistance<ResultNumber>(*this);
2778 }
2779
2790 template <class ResultNumber = NumberType, PointConcept OtherPoint>
2791 [[nodiscard]] constexpr std::optional<Point<ResultNumber, typename PointType::LabelType>>
2792 intersection(const OtherPoint& other) const;
2793
2805 template <class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
2806 constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>>>
2807 intersection(const OtherSegment& other) const;
2808
2820 template <class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
2821 constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>>>
2822 intersection(const OtherOrientedSegment& other) const;
2823
2835 template <class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
2836 constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>>>
2837 intersection(const OtherLine& other) const;
2838
2850 template <class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
2851 constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>>>
2852 intersection(const OtherOrientedLine& other) const;
2853
2865 template <class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
2866 constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>>>
2867 intersection(const OtherRay& other) const;
2868
2881 template <class ResultNumber = division_result_t<NumberType>, HalfplaneConcept OtherHalfplane>
2882 constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>, Convex<Point<ResultNumber, typename PointType::LabelType>>>>
2883 intersection(const OtherHalfplane& other) const;
2884
2886 template <class ResultNumber = NumberType, HalfplaneIntersectionConcept OtherRegion>
2887 [[nodiscard]] constexpr auto intersection(const OtherRegion& other) const {
2888 return other.template intersection<ResultNumber>(*this);
2889 }
2890
2902 template <class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
2903 constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>, Convex<Point<ResultNumber, typename PointType::LabelType>>>>
2904 intersection(const OtherRectangle& other) const;
2905
2906
2918 template <class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
2919 constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>, Convex<Point<ResultNumber, typename PointType::LabelType>>>>
2920 intersection(const OtherTriangle& other) const;
2921
2933 template <class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
2934 constexpr std::optional<std::variant<Point<ResultNumber, typename PointType::LabelType>, Segment<Point<ResultNumber, typename PointType::LabelType>>, Convex<Point<ResultNumber, typename PointType::LabelType>>>>
2935 intersection(const OtherConvex& other) const;
2936
2938 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
2939 requires (!PointConcept<OtherShape>
2941 && (detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
2942 && requires(const OtherShape& o, const Convex& self) {
2943 o.template intersection<ResultNumber>(self);
2944 })
2945 [[nodiscard]] constexpr auto intersection(const OtherShape& other) const {
2946 return other.template intersection<ResultNumber>(*this);
2947 }
2948
2950 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
2951 requires (!PointConcept<OtherShape>
2952 && (detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
2953 && requires(const OtherShape& o, const Convex& self) {
2955 })
2956 [[nodiscard]] constexpr auto regularizedIntersection(const OtherShape& other) const {
2957 return other.template regularizedIntersection<ResultNumber>(*this);
2958 }
2959
2961 template <class ResultNumber = NumberType, class EmptyPoint>
2962 [[nodiscard]] constexpr EmptyShape<EmptyPoint> intersection(const EmptyShape<EmptyPoint>&) const {
2963 return {};
2964 }
2965
2972 [[nodiscard]] constexpr Convex rotated90(int k = 1) const;
2973
2979 constexpr void rotate90(int k = 1);
2980
2982 template <class OtherNumber>
2983 [[nodiscard]] constexpr Convex scaledUpX(const OtherNumber scalar) const;
2984
2986 template <class OtherNumber>
2987 constexpr void scaleUpX(const OtherNumber scalar);
2988
2990 template <class OtherNumber>
2991 [[nodiscard]] constexpr Convex scaledUpY(const OtherNumber scalar) const;
2992
2994 template <class OtherNumber>
2995 constexpr void scaleUpY(const OtherNumber scalar);
2996
2998 template <class OtherNumber>
2999 [[nodiscard]] constexpr Convex scaledDownX(const OtherNumber scalar) const;
3000
3002 template <class OtherNumber>
3003 constexpr void scaleDownX(const OtherNumber scalar);
3004
3006 template <class OtherNumber>
3007 [[nodiscard]] constexpr Convex scaledDownY(const OtherNumber scalar) const;
3008
3010 template <class OtherNumber>
3011 constexpr void scaleDownY(const OtherNumber scalar);
3012
3026 template <class OtherShape>
3028 [[nodiscard]] constexpr auto minkowskiSum(const OtherShape& other) const;
3029
3053 template <class OtherShape>
3055 [[nodiscard]] constexpr auto minkowskiErosion(const OtherShape& other) const;
3056
3079 template <class OtherShape>
3082 [[nodiscard]] constexpr auto minkowskiErosion(const OtherShape& other) const;
3083
3094 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
3096 && (detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
3097 && requires(const OtherShape& o, const Convex& self) {
3098 o.template minkowskiSum<ResultNumber>(self);
3099 })
3100 [[nodiscard]] auto minkowskiSum(const OtherShape& other) const {
3101 return other.template minkowskiSum<ResultNumber>(*this);
3102 }
3103
3119 template <class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
3121 regularizedUnion(const OtherConvex& other) const;
3122
3124 template <class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
3126 regularizedUnion(const OtherTriangle& other) const;
3127
3129 template <class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
3131 regularizedUnion(const OtherRectangle& other) const;
3132
3140 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
3141 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
3142 && requires(const OtherShape& o, const Convex& self) {
3143 o.template regularizedUnion<ResultNumber>(self);
3144 })
3145 [[nodiscard]] auto regularizedUnion(const OtherShape& other) const {
3146 return other.template regularizedUnion<ResultNumber>(*this);
3147 }
3148
3164 template <class ResultNumber = division_result_t<NumberType>, PolygonalRegionConcept OtherRegion>
3166 difference(const OtherRegion& other) const;
3167
3177 template <class ResultNumber = division_result_t<NumberType>, HalfplaneIntersectionConcept OtherIntersection>
3179 difference(const OtherIntersection& other) const;
3180
3187 template <class ResultNumber = division_result_t<NumberType>, HalfplaneConcept OtherHalfplane>
3189 difference(const OtherHalfplane& other) const;
3190
3203 template <class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
3205 symmetricDifference(const OtherConvex& other) const;
3206
3208 template <class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
3210 symmetricDifference(const OtherTriangle& other) const;
3211
3213 template <class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
3215 symmetricDifference(const OtherRectangle& other) const;
3216
3224 template <class ResultNumber = division_result_t<NumberType>, typename OtherShape>
3225 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Convex>)
3226 && requires(const OtherShape& o, const Convex& self) {
3227 o.template symmetricDifference<ResultNumber>(self);
3228 })
3229 [[nodiscard]] auto symmetricDifference(const OtherShape& other) const {
3230 return other.template symmetricDifference<ResultNumber>(*this);
3231 }
3232
3234 template<PointConcept OtherPoint>
3235 constexpr Convex& operator+=(const OtherPoint& translation);
3236
3246 template<PointConcept OtherPoint>
3247 constexpr Convex& operator-=(const OtherPoint& translation);
3248
3258 template <class Scalar>
3259 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
3260 constexpr Convex& operator*=(const Scalar& scalar);
3261
3271 template <class Scalar>
3272 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
3273 constexpr Convex& operator/=(const Scalar& scalar);
3274
3281 template <bool Oriented>
3283 public:
3284 using iterator_category = std::forward_iterator_tag;
3285 using iterator_concept = std::forward_iterator_tag;
3287 using difference_type = std::ptrdiff_t;
3289
3290 constexpr BoundaryIterator() = default;
3291
3292 constexpr value_type operator*() const {
3293 assert(convex != nullptr);
3294 return convex->template boundaryAt<Oriented>(index);
3295 }
3296
3298 ++index;
3299 return *this;
3300 }
3301
3303 BoundaryIterator copy(*this);
3304 ++(*this);
3305 return copy;
3306 }
3307
3308 constexpr bool operator==(const BoundaryIterator& other) const = default;
3309
3310 private:
3311 friend struct Convex;
3312
3313 constexpr BoundaryIterator(const Convex* convex_arg, std::size_t index_arg)
3314 : convex(convex_arg), index(index_arg) {}
3315
3316 const Convex* convex = nullptr;
3317 std::size_t index = 0;
3318 };
3319
3320 private:
3321 std::vector<PointType> points_{};
3322 [[no_unique_address]] mutable LabelType label_{};
3323 PointType translation_{};
3324 // Lazily computed caches, invalidated by resetCache() on every mutation.
3325 // maxIndex_ is -1 until first computed; bbox_ uses the empty rectangle as
3326 // its "not computed yet", which only a vertexless polygon can also mean,
3327 // and that case costs one size check to re-derive.
3328 mutable Rectangle<PointType> bbox_{};
3329 mutable std::ptrdiff_t maxIndex_ = -1;
3330
3331 // Memoized hash, computed lazily by std::hash<Convex>. hashUnset_ means "not
3332 // yet computed"; SIZE_MAX is chosen as the sentinel because it is a rare hash
3333 // output, and the one true hash that would collide with it is remapped to
3334 // hashUnset_ - 1 so the sentinel is never stored as a real value. Unlike the
3335 // bbox, the hash is not translation-invariant, so operator+=/-= reset it.
3336 static constexpr std::size_t hashUnset_ = pgl::detail::numeric_limits<std::size_t>::max();
3337 mutable std::size_t hash_ = hashUnset_;
3338 friend struct std::hash<Convex>;
3339
3340 // Drops every memoized value; call after any operation that mutates the
3341 // polygon's vertices. A pure translation does not need to drop bbox_/maxIndex_
3342 // (maxIndex_ stays valid and the bbox shifts in place, see operator+=), but it
3343 // must still reset hash_, which depends on the absolute vertex positions.
3344 constexpr void resetCache() const {
3345 bbox_ = {};
3346 maxIndex_ = -1;
3347 hash_ = hashUnset_;
3348 }
3349
3350 // Replaces the vertices by the convex hull of `points`, which are absolute
3351 // coordinates (the translation is already applied), so it is folded away.
3352 constexpr void rebuildHull(const std::vector<PointType>& points) {
3353 points_ = grahamScan(points);
3354 translation_ = {};
3355 resetCache();
3356 }
3357
3358 template <bool Oriented>
3359 constexpr BoundaryType<Oriented> boundaryAt(std::size_t index) const {
3360 const auto i = static_cast<std::ptrdiff_t>(index);
3361 return BoundaryType<Oriented>(get(i), get(i + 1));
3362 }
3363
3364 // Lexicographic less-than that promotes mixed numeric types to their
3365 // common type before comparing. Lets std::lower_bound / std::binary_search
3366 // search points_ with a key whose NumberType differs from PointType's.
3367 struct LexLessCrossType {
3368 template <class A, class B>
3369 constexpr bool operator()(const A& a, const B& b) const {
3370 using AX = std::remove_cvref_t<decltype(a.x())>;
3371 using BX = std::remove_cvref_t<decltype(b.x())>;
3372 using C = std::common_type_t<AX, BX>;
3373 const auto ax = static_cast<C>(a.x());
3374 const auto bx = static_cast<C>(b.x());
3375 if (ax < bx) return true;
3376 if (bx < ax) return false;
3377 return detail::asNumber<C>(a.y()) < detail::asNumber<C>(b.y());
3378 }
3379 };
3380 static constexpr LexLessCrossType lexLessCrossType{};
3381
3382 class Iterator {
3383 private:
3384 std::vector<PointType>::const_iterator it;
3385 PointType x;
3386
3387 public:
3388 using iterator_category = std::random_access_iterator_tag;
3389 using difference_type = std::ptrdiff_t;
3390 using value_type = PointType;
3391 using pointer = PointType*;
3392 using reference = PointType&;
3393
3394 Iterator() = default;
3395 Iterator(std::vector<PointType>::const_iterator it, PointType x) : it(it), x(x) {}
3396
3397 // Dereference returns value + x
3398 PointType operator*() const {
3399 return *it + x;
3400 }
3401
3402 // Pre-increment
3403 Iterator& operator++() {
3404 ++it;
3405 return *this;
3406 }
3407
3408 // Post-increment
3409 Iterator operator++(int) {
3410 Iterator tmp = *this;
3411 ++it;
3412 return tmp;
3413 }
3414
3415 // Pre-decrement
3416 Iterator& operator--() {
3417 --it;
3418 return *this;
3419 }
3420
3421 // Post-decrement
3422 Iterator operator--(int) {
3423 Iterator tmp = *this;
3424 --it;
3425 return tmp;
3426 }
3427
3428 // Equality comparison
3429 bool operator==(const Iterator& other) const {
3430 return it == other.it;
3431 }
3432
3433 // Other comparisons
3434 auto operator<=>(const Iterator& other) const {
3435 return it <=> other.it;
3436 }
3437
3438 // Addition
3439 Iterator operator+(difference_type n) const {
3440 return Iterator(it + n, x);
3441 }
3442
3443 // Subtraction
3444 Iterator operator-(difference_type n) const {
3445 return Iterator(it - n, x);
3446 }
3447
3448 // Difference
3449 difference_type operator-(const Iterator& other) const {
3450 return it - other.it;
3451 }
3452
3453 // Array subscript operator
3454 PointType operator[](difference_type n) const {
3455 return *(it + n) + x;
3456 }
3457 };
3458}; // class Convex
3459
3460template <class PointType, class LabelType, class TranslationNumber, class TranslationLabel>
3462 return convex + (-translation);
3463}
3464
3465template <class PointType, class LabelType, class Scalar>
3466 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
3467constexpr auto operator*(const Convex<PointType, LabelType>& convex, const Scalar& scalar) {
3468 using ResultPointType = Point<decltype(std::declval<PointType>().x() * scalar), typename PointType::LabelType>;
3470 result *= scalar;
3471 if constexpr (detail::has_label_v<LabelType>) {
3472 result.label() = LabelType{};
3473 }
3474 return result;
3475}
3476
3477template <class Scalar, class PointType, class LabelType>
3478 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
3479constexpr auto operator*(const Scalar& scalar, const Convex<PointType, LabelType>& convex) {
3480 return convex * scalar;
3481}
3482
3483template <class PointType, class LabelType, class Scalar>
3484 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
3485constexpr auto operator/(const Convex<PointType, LabelType>& convex, const Scalar& scalar) {
3486 using ResultPointType = Point<decltype(std::declval<PointType>().x() / scalar), typename PointType::LabelType>;
3488 result /= scalar;
3489 if constexpr (detail::has_label_v<LabelType>) {
3490 result.label() = LabelType{};
3491 }
3492 return result;
3493}
3494
3495template <class PointType, class LabelType>
3496std::ostream& operator<<(std::ostream& stream, const Convex<PointType, LabelType>& convex);
3497
3498} // namespace pgl
friend struct Convex
Definition convex.hpp:3311
std::forward_iterator_tag iterator_category
Definition convex.hpp:3284
constexpr bool operator==(const BoundaryIterator &other) const =default
value_type reference
Definition convex.hpp:3288
constexpr BoundaryIterator()=default
std::forward_iterator_tag iterator_concept
Definition convex.hpp:3285
std::ptrdiff_t difference_type
Definition convex.hpp:3287
constexpr BoundaryIterator operator++(int)
Definition convex.hpp:3302
constexpr value_type operator*() const
Definition convex.hpp:3292
constexpr BoundaryIterator & operator++()
Definition convex.hpp:3297
BoundaryType< Oriented > value_type
Definition convex.hpp:3286
Bounded polygonal primitives, convex or not.
Definition forward.hpp:373
Definition forward.hpp:319
Shape pairs whose Minkowski sum Pangolin can represent.
Definition forward.hpp:476
Definition forward.hpp:306
Definition forward.hpp:324
Declaration of pgl::Disk.
Definition arrangement.hpp:67
HalfplaneIntersection() -> HalfplaneIntersection< Point<>, NoLabel >
Definition halfplaneintersection.hpp:2308
@ y
Definition intervaltree.hpp:24
@ x
Definition intervaltree.hpp:24
@ vertex
Definition bitmatrix.hpp:37
Point() -> Point< int >
auto grahamScan(const Container &points_)
Computes the convex hull of a point container using Graham's scan.
Definition convexhull.hpp:177
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
MonotoneChain() -> MonotoneChain< Point<>, NoLabel >
Definition monotonechain.hpp:2439
Shape(const std::variant< T, Ts... > &) -> Shape< detail::shape_point_type_t< T > >
Convex() -> Convex< Point<>, NoLabel >
Definition convex.hpp:3311
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
Closed convex polygon stored by its vertices.
Definition convex.hpp:170
constexpr auto squaredHausdorffDistance(const OtherSegment &other) const
Returns the squared Hausdorff distance to the given shape.
Definition distance.hpp:1116
constexpr bool boundaryContains(const OtherRegion &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1750
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > symmetricDifference(const OtherTriangle &other) const
Returns the regularized symmetric difference of the two shapes (A △ B).
constexpr bool interiorsIntersect(const OtherConvex &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:932
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > symmetricDifference(const OtherRectangle &other) const
Returns the regularized symmetric difference of the two shapes (A △ B).
constexpr bool samePointSet(const OtherShape &other) const
Tests whether another shape defines exactly the same point set.
Definition samepointset.hpp:2001
bool separates(const OtherRegion &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:5723
constexpr void scaleUpY(const OtherNumber scalar)
Multiplies the convex polygon's y-coordinates by a factor in place.
Definition transformations.hpp:1666
constexpr auto squaredDistance(const OtherLine &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:999
constexpr bool contains(const OtherHalfplane &) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1194
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > symmetricDifference(const OtherConvex &other) const
Returns the regularized symmetric difference of the two shapes (A △ B).
constexpr const Rectangle< PointType > & bbox() const
Computes the bounding box of the convex polygon.
Definition bounding.hpp:374
constexpr auto hausdorffDistanceL1(const OtherPoint &point) const
Returns the Manhattan (L1) Hausdorff distance to the given shape.
Definition distancel1.hpp:1074
constexpr bool intersects(const OtherSegment &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:716
constexpr auto verticesView() const
Returns a lazy view over the vertices, translating each on the fly instead of allocating a vector.
Definition convex.hpp:563
constexpr bool intersects(const Shape< OtherPoint > &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:971
constexpr MonotoneChain< PointType > lowerHull() const
Returns the lower hull: the boundary chain running from the lexicographically smallest vertex to the ...
Definition convex.hpp:691
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Segment< Point< ResultNumber, typename PointType::LabelType > >, Convex< Point< ResultNumber, typename PointType::LabelType > > > > intersection(const OtherRectangle &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition intersection.hpp:1581
constexpr bool crosses(const OtherTriangle &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:603
constexpr bool crosses(const EmptyShape< EmptyPoint > &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition convex.hpp:2099
constexpr void scaleDownX(const OtherNumber scalar)
Divides the convex polygon's x-coordinates by a divisor in place.
Definition transformations.hpp:1685
constexpr auto minkowskiSum(const OtherShape &other) const
Returns the Minkowski sum of this shape and another (A ⊕ B).
Definition minkowski.hpp:803
constexpr auto twiceArea() const
Computes twice the area of the convex polygon.
Definition measures.hpp:516
constexpr bool crosses(const OtherShape &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition convex.hpp:2093
constexpr auto squaredDistance(const OtherRectangle &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:993
constexpr bool intersects(const OtherHalfplane &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:838
constexpr auto squaredDistance(const OtherHalfplane &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1098
constexpr Rectangle< Point< ResultNumber > > fbox() const
Computes the floating-point bounding box of the convex polygon.
Definition bounding.hpp:420
constexpr Point< ResultNumber > pointInside() const
Returns a point inside the convex polygon.
Definition measures.hpp:582
std::vector< Point< ResultNumber, typename PointType::LabelType > > latticePoints() const
Returns the integer points the convex polygon contains.
Definition lattice.hpp:649
constexpr bool separates(const OtherDisk &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1666
constexpr Convex< PointType > convexHull() const
Returns the convex hull of the polygon's vertices.
Definition convex.hpp:521
std::conditional_t< Oriented, OrientedSegment< PointType >, Segment< PointType > > BoundaryType
Definition convex.hpp:177
constexpr bool intersects(const OtherDisk &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:887
constexpr Point< ResultNumber > verticesCentroid() const
Computes the centroid of the vertex set.
Definition measures.hpp:566
constexpr auto cend() const
Returns a constant iterator to the end of vertices.
Definition convex.hpp:322
constexpr bool interiorsIntersect(const Shape< OtherPoint > &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:983
constexpr bool empty() const
Returns whether the convex polygon is the empty set of points.
Definition convex.hpp:390
constexpr bool contains(const OtherPolyline &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2459
constexpr auto squaredDistance(const OtherConvex &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:958
constexpr bool crosses(const OtherDisk &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:618
constexpr std::optional< PointType > getIfPoint() const
Returns the point the convex polygon collapses to, if it does.
Definition predicates.hpp:994
constexpr bool boundaryContains(const OtherHalfplane &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:782
constexpr bool interiorsIntersect(const OtherTriangle &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:926
constexpr 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 convex.hpp:289
constexpr bool interiorsIntersect(const OtherHalfplane &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:901
constexpr auto edgesView() const
Returns a lazy view over the edges, materializing each Segment on the fly instead of allocating a vec...
Definition convex.hpp:575
constexpr auto hausdorffDistanceLInf(const OtherPoint &point) const
Returns the Chebyshev (LInf) Hausdorff distance to the given shape.
Definition distancelinf.hpp:1062
BoundaryIterator< true > OrientedEdgeIterator
Definition convex.hpp:183
constexpr auto hausdorffDistanceLInf(const OtherSegment &other) const
Returns the Chebyshev (LInf) Hausdorff distance to the given shape.
Definition distancelinf.hpp:1068
auto minkowskiSum(const OtherShape &other) const
Returns the regularized Minkowski sum of the two shapes (A ⊕ B).
Definition convex.hpp:3100
constexpr bool intersects(const OtherShape &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition convex.hpp:1614
constexpr auto squaredHausdorffDistance(const OtherOrientedSegment &other) const
Returns the squared Hausdorff distance to the given shape.
Definition distance.hpp:1124
constexpr bool interiorsIntersect(const OtherRay &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:874
constexpr bool contains(const OtherSet &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition convex.hpp:1939
constexpr bool boundaryContains(const OtherOrientedSegment &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:758
constexpr bool boundaryContains(const OtherRectangle &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:788
auto regularizedUnion(const OtherShape &other) const
Returns the regularized union of the two shapes (A ∪ B).
Definition convex.hpp:3145
constexpr HalfplaneIntersection< PointType > asHalfplaneIntersection() const
Returns the convex polygon as a half-plane intersection.
Definition convex.hpp:672
constexpr auto squaredHausdorffDistance(const OtherShape &other) const
Returns the squared Hausdorff distance to the given shape.
Definition convex.hpp:2776
constexpr auto distanceL1(const OtherRay &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:815
constexpr auto intersection(const OtherShape &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition convex.hpp:2945
constexpr bool contains(const OtherSegment &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1164
constexpr Convex scaledDownX(const OtherNumber scalar) const
Returns the convex polygon with its x-coordinates divided by a divisor.
constexpr auto intersection(const OtherRegion &other) const
Adds this convex polygon's constraints to a half-plane intersection without deriving vertices.
Definition convex.hpp:2887
constexpr auto hausdorffDistanceL1(const OtherSegment &other) const
Returns the Manhattan (L1) Hausdorff distance to the given shape.
Definition distancel1.hpp:1080
constexpr EdgeIterator edgesBegin() const
Returns an iterator to the first unoriented edge.
Definition convex.hpp:591
constexpr bool boundaryContains(const OtherConvex &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:817
constexpr auto closestPoints(const OtherShape &other) const
Returns the pair of points realizing the distance, nothing when the shapes meet.
Definition closest.hpp:377
constexpr bool interiorsIntersect(const OtherRectangle &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:916
constexpr MonotoneChain< PointType > upperHull() const
Returns the upper hull: the boundary chain running from the lexicographically smallest vertex to the ...
Definition convex.hpp:718
constexpr auto hausdorffDistanceL1(const OtherConvex &other) const
Returns the Manhattan (L1) Hausdorff distance to the given shape.
Definition distancel1.hpp:1112
constexpr bool boundaryContains(const OtherSet &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition convex.hpp:1950
constexpr void scaleDownY(const OtherNumber scalar)
Divides the convex polygon's y-coordinates by a divisor in place.
Definition transformations.hpp:1704
constexpr bool interiorsIntersect(const OtherShape &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition convex.hpp:1732
constexpr auto squaredHausdorffDistance(const OtherPoint &point) const
Returns the squared Hausdorff distance to the given shape.
Definition distance.hpp:1110
constexpr bool crosses(const OtherSegment &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:557
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Segment< Point< ResultNumber, typename PointType::LabelType > >, Convex< Point< ResultNumber, typename PointType::LabelType > > > > intersection(const OtherHalfplane &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition intersection.hpp:1511
constexpr bool interiorsIntersect(const EmptyShape< EmptyPoint > &) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition convex.hpp:1738
constexpr auto squaredHausdorffDistance(const OtherConvex &other) const
Returns the squared Hausdorff distance to the given shape.
Definition distance.hpp:1148
detail::floating_result_t< ResultNumber > squaredDistance(const OtherDisk &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1183
constexpr bool boundaryContains(const Shape< OtherPoint > &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:841
constexpr bool contains(const Shape< OtherPoint > &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1685
constexpr auto distanceLInf(const OtherLine &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:781
constexpr bool boundaryContains(const OtherTriangle &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:805
constexpr bool interiorsIntersect(const OtherOrientedSegment &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:868
constexpr bool crosses(const Shape< OtherPoint > &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:624
constexpr EmptyShape< EmptyPoint > intersection(const EmptyShape< EmptyPoint > &) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition convex.hpp:2962
constexpr bool contains(const OtherDisk &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1274
constexpr auto distanceLInf(const OtherPoint &point) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:703
constexpr bool interiorContains(const OtherOrientedSegment &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:809
constexpr bool separates(const OtherPoint &) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1522
constexpr bool interiorContains(const OtherPoint &point) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:792
constexpr auto hausdorffDistanceLInf(const Shape< OtherPoint > &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition convex.hpp:2728
constexpr bool isDegenerate() const
Checks if the convex polygon is degenerate (has zero area).
Definition predicates.hpp:982
constexpr bool interiorContains(const OtherPolyline &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1766
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > regularizedUnion(const OtherTriangle &other) const
Returns the regularized union of the two shapes (A ∪ B).
constexpr EdgeIterator edgesEnd() const
Returns an iterator past the last unoriented edge.
Definition convex.hpp:599
constexpr auto distanceL1(const OtherOrientedSegment &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:749
constexpr bool interiorContains(const OtherRegion &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
constexpr auto squaredHausdorffDistance(const OtherTriangle &other) const
Returns the squared Hausdorff distance to the given shape.
Definition distance.hpp:1140
constexpr auto squaredDistance(const OtherPoint &point) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:791
constexpr void scaleUpX(const OtherNumber scalar)
Multiplies the convex polygon's x-coordinates by a factor in place.
Definition transformations.hpp:1647
auto symmetricDifference(const OtherShape &other) const
Returns the regularized symmetric difference of the two shapes (A △ B).
Definition convex.hpp:3229
constexpr bool interiorContains(const OtherRectangle &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:839
constexpr OrientedEdgeIterator orientedEdgesBegin() const
Returns an iterator to the first oriented edge.
Definition convex.hpp:607
constexpr auto hausdorffDistanceL1(const OtherShape &other) const
Returns the Manhattan (L1) Hausdorff distance to the given shape.
Definition convex.hpp:2676
constexpr auto distanceLInf(const Shape< OtherPoint > &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition convex.hpp:2636
constexpr bool separates(const OtherOrientedSegment &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1537
constexpr bool separates(const Shape< OtherPoint > &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1849
constexpr bool interiorsIntersect(const OtherPoint &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:804
constexpr bool contains(const OtherConvex &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1233
constexpr bool contains(const OtherChain &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2097
constexpr bool interiorsIntersect(const OtherDisk &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:964
constexpr auto distanceLInf(const OtherRay &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:803
constexpr auto distanceL1(const Shape< OtherPoint > &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition convex.hpp:2567
constexpr auto distanceLInf(const OtherRectangle &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:775
constexpr PolygonWithHoles< PointType > asPolygonWithHoles() const
Returns the convex polygon as a hole-free region.
Definition convex.hpp:646
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:1272
constexpr bool separates(const OtherLine &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1543
constexpr void insert(Range &&range)
Enlarges the convex polygon so that it contains every point in a range.
Definition convex.hpp:780
constexpr bool interiorsIntersect(const OtherOrientedLine &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:836
constexpr auto squaredDistance(const OtherSegment &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:892
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:1244
constexpr auto hausdorffDistanceLInf(const OtherConvex &other) const
Returns the Chebyshev (LInf) Hausdorff distance to the given shape.
Definition distancelinf.hpp:1100
constexpr auto distanceLInf(const OtherOrientedSegment &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:737
constexpr bool separates(const OtherChain &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:3207
constexpr bool interiorContains(const OtherLine &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:815
constexpr bool boundaryContains(const OtherPolygon &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:999
constexpr bool intersects(const OtherOrientedSegment &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:736
constexpr auto distanceL1(const OtherRectangle &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:787
constexpr bool interiorContains(const OtherRay &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:827
constexpr Convex & operator+=(const OtherPoint &translation)
Translates the convex polygon by the given point in place.
constexpr bool separates(const OtherSegment &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1528
constexpr Convex(std::initializer_list< NumberType > coords, bool trusted=false)
Creates a convex from a flat list of coordinates.
Definition convex.hpp:232
constexpr auto distanceL1(const OtherHalfplane &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:832
constexpr bool crosses(const OtherPoint &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:551
constexpr std::ptrdiff_t index(const PointType &point) const
constexpr auto distanceL1(const OtherLine &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:793
constexpr bool intersects(const OtherOrientedLine &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:756
constexpr Convex & operator-=(const OtherPoint &translation)
Translates the convex polygon by the negation of the given point.
constexpr auto distanceLInf(const OtherOrientedLine &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:797
auto difference(const Shape< OtherPoint > &other) const
Returns the regularized set difference of the two shapes (A ∖ B), re-dispatching through the wrapper'...
Definition convex.hpp:2538
constexpr auto squaredDistance(const OtherShape &other) const
Returns the squared Euclidean distance to the given shape.
Definition convex.hpp:2377
constexpr PolygonSet< PointType > asPolygonSet() const
Returns the convex polygon as a one-component set of regions.
Definition convex.hpp:659
PointType::NumberType NumberType
Definition convex.hpp:172
bool separates(const OtherSet &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:5978
constexpr bool contains(const OtherRay &) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1188
constexpr size_t maxIndex() const
Returns the index of the maximum vertex (rightmost and highest in case of ties).
Definition predicates.hpp:1022
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > difference(const OtherRegion &other) const
Returns the regularized set difference of the two shapes (A ∖ B).
constexpr bool contains(const OtherPolygon &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1793
constexpr bool intersects(const OtherPoint &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:829
constexpr bool boundaryContains(const OtherLine &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:764
constexpr Convex rotated90(int k=1) const
Returns the convex polygon rotated by 90k degrees around the origin.
Definition transformations.hpp:1618
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 convex.hpp:2496
constexpr auto area() const
Computes the area of the convex polygon.
Definition measures.hpp:531
constexpr bool interiorContains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition convex.hpp:1340
constexpr bool separates(const OtherPolygon &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:2034
constexpr Convex scaledUpX(const OtherNumber scalar) const
Returns the convex polygon with its x-coordinates multiplied by a factor.
constexpr A & label() const
Returns the convex-polygon label.
Definition convex.hpp:270
constexpr auto hausdorffDistanceL1(const OtherOrientedSegment &other) const
Returns the Manhattan (L1) Hausdorff distance to the given shape.
Definition distancel1.hpp:1088
constexpr Convex scaledUpY(const OtherNumber scalar) const
Returns the convex polygon with its y-coordinates multiplied by a factor.
constexpr void insert(const OtherPoint &point)
Enlarges the convex polygon so that it contains the given point.
Definition bounding.hpp:426
constexpr bool interiorsIntersect(const OtherLine &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:811
constexpr bool intersects(const OtherConvex &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:858
constexpr auto hausdorffDistanceL1(const Shape< OtherPoint > &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition convex.hpp:2682
constexpr bool boundaryContains(const OtherDisk &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:832
constexpr bool operator==(const Convex &other) const
Checks equality of two convex polygons.
Definition convex.hpp:348
auto regularizedIntersection(const Shape< OtherPoint > &other) const
Re-dispatches a regularized intersection through a runtime shape.
Definition convex.hpp:2502
constexpr bool boundaryContains(const OtherSegment &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:721
constexpr bool intersects(const EmptyShape< EmptyPoint > &) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition convex.hpp:1620
constexpr bool crosses(const OtherOrientedLine &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:575
constexpr bool interiorContains(const OtherHalfplane &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:833
constexpr bool verticesContain(const OtherPoint &point) const
Checks if the vertices list contains the given point.
Definition predicates.hpp:1051
constexpr bool boundaryContains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition convex.hpp:1335
constexpr ResultNumber squaredMinimumWidth() const
Returns the squared minimum width of the convex polygon.
Definition measures.hpp:1019
ApproximateNumber minimumWidth() const
Returns the minimum width of the convex polygon.
Definition measures.hpp:1032
constexpr auto closestSegments(const OtherShape &other) const
Returns the pair of elements realizing the distance, nothing when the shapes meet.
Definition closest.hpp:370
constexpr bool isSegment() const
Returns whether the convex polygon collapses to a non-degenerate segment.
Definition predicates.hpp:1002
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Segment< 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:1278
TLabel LabelType
Definition convex.hpp:173
constexpr bool separates(const OtherPolyline &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:4012
constexpr bool contains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition convex.hpp:1330
constexpr HalfplaneIntersection< PointType > smallestEnclosingSlab() const
Returns the narrowest slab containing the convex polygon.
Definition measures.hpp:993
constexpr bool contains(const OtherOrientedSegment &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1170
constexpr bool contains(const OtherLine &) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1176
constexpr auto squaredDistance(const OtherOrientedSegment &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:951
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Segment< 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:1488
constexpr bool crosses(const OtherOrientedSegment &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:563
constexpr bool separates(const EmptyShape< EmptyPoint > &) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition convex.hpp:1345
constexpr std::vector< Segment< PointType > > edges() const
Returns the edges of the convex polygon.
Definition convex.hpp:529
constexpr bool intersects(const OtherTriangle &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:807
constexpr std::optional< BoundaryType< false > > getIfSegment() const
Returns the segment the convex polygon collapses to, if it does.
Definition predicates.hpp:1008
constexpr auto squaredDistance(const OtherOrientedLine &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1041
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > difference(const OtherHalfplane &other) const
Returns the regularized set difference of the two shapes (A ∖ B).
constexpr auto distanceL1(const OtherSegment &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:732
constexpr bool crosses(const OtherRectangle &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:593
constexpr bool isPoint() const
Returns whether the convex polygon collapses to a single point.
Definition predicates.hpp:987
constexpr bool intersects(const OtherRay &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:762
constexpr bool isUndefined() const
Returns whether the convex polygon is degenerate without collapsing to a point or to a segment.
Definition predicates.hpp:1016
constexpr bool interiorContains(const OtherPolygon &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1202
constexpr Polygon< PointType > asPolygon() const
Returns the convex polygon as a simple polygon.
Definition convex.hpp:636
constexpr bool separates(const OtherHalfplane &) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1562
constexpr bool separates(const OtherOrientedLine &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1549
constexpr bool separates(const OtherRectangle &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1568
constexpr bool boundaryContains(const OtherPolyline &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1336
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:1253
constexpr auto end() const
Returns a constant iterator to the end of vertices.
Definition convex.hpp:314
constexpr OrientedEdgeIterator orientedEdgesEnd() const
Returns an iterator past the last oriented edge.
Definition convex.hpp:615
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:603
constexpr bool boundaryContains(const OtherOrientedLine &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:770
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Segment< Point< ResultNumber, typename PointType::LabelType > >, Convex< Point< ResultNumber, typename PointType::LabelType > > > > intersection(const OtherTriangle &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition intersection.hpp:1587
constexpr auto hausdorffDistanceLInf(const OtherOrientedSegment &other) const
Returns the Chebyshev (LInf) Hausdorff distance to the given shape.
Definition distancelinf.hpp:1076
constexpr auto operator<=>(const Convex &other) const
Compares two convex polygons.
Definition convex.hpp:331
constexpr bool interiorContains(const OtherChain &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1540
constexpr auto distanceL1(const OtherShape &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition convex.hpp:2476
constexpr bool contains(const OtherPoint &point) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1135
constexpr auto minkowskiErosion(const OtherShape &other) const
Returns the Minkowski erosion of this shape by a bounded polygonal one (A ⊖ B).
Disk< Point< NumberType > > smallestEnclosingDisk() const
Returns the smallest closed disk containing the convex polygon.
Definition mindisk.hpp:192
constexpr Convex()=default
Creates a convex with no vertex.
constexpr auto distanceL1(const OtherTriangle &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:781
constexpr bool crosses(const OtherRay &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:581
constexpr bool intersects(const OtherRectangle &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:780
constexpr bool interiorContains(const OtherRegion &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:2152
constexpr auto orientedEdgesView() const
Lazy view counterpart of orientedEdges(); see edgesView().
Definition convex.hpp:583
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Segment< 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:1482
constexpr bool interiorContains(const OtherOrientedLine &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:821
constexpr auto begin() const
Returns a constant iterator to the beginning of vertices.
Definition convex.hpp:298
constexpr bool separates(const OtherRegion &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:4667
constexpr auto squaredDistance(const OtherTriangle &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:987
constexpr bool separates(const OtherConvex &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1584
constexpr std::optional< std::array< Segment< PointType >, 2 > > edgesAtX(OtherNumberType x) const
Returns two edges of the convex polygon that intersect with the vertical line at x.
Definition atxy.hpp:289
constexpr std::optional< std::variant< Point< ResultNumber, typename PointType::LabelType >, Segment< Point< ResultNumber, typename PointType::LabelType > >, Convex< Point< ResultNumber, typename PointType::LabelType > > > > intersection(const OtherConvex &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition intersection.hpp:1593
constexpr bool intersects(const OtherLine &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:742
constexpr void rotate90(int k=1)
Rotates the convex polygon by 90k degrees around the origin in place.
Definition transformations.hpp:1628
constexpr bool separates(const OtherRay &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1555
constexpr bool boundaryContains(const OtherRay &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:776
constexpr bool crosses(const OtherLine &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:569
constexpr auto hausdorffDistanceLInf(const OtherTriangle &other) const
Returns the Chebyshev (LInf) Hausdorff distance to the given shape.
Definition distancelinf.hpp:1092
auto symmetricDifference(const Shape< OtherPoint > &other) const
Returns the regularized symmetric difference of the two shapes (A △ B), re-dispatching through the wr...
Definition convex.hpp:2555
constexpr bool crosses(const OtherHalfplane &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:587
constexpr auto regularizedIntersection(const OtherShape &other) const
Forwards a regularized intersection to the shape that owns it.
Definition convex.hpp:2956
constexpr void insert(const TShape &shape)
Enlarges the convex polygon so that it contains a finite shape.
constexpr bool contains(const OtherRectangle &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1200
constexpr std::vector< OrientedSegment< PointType > > orientedEdges() const
Returns the oriented edges of the convex polygon.
Definition convex.hpp:544
constexpr auto distanceLInf(const OtherConvex &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:744
constexpr Point< ResultNumber > centroid() const
Computes the centroid of the convex polygon.
Definition measures.hpp:538
constexpr Segment< PointType > diameter() const
Returns a segment realizing the diameter (the farthest vertex pair).
Definition measures.hpp:696
constexpr const std::vector< PointType > vertices() const
Returns the vertices of the convex polygon.
Definition convex.hpp:508
constexpr auto hausdorffDistanceLInf(const OtherShape &other) const
Returns the Chebyshev (LInf) Hausdorff distance to the given shape.
Definition convex.hpp:2722
constexpr std::vector< std::pair< std::size_t, std::size_t > > antipodalPairs() const
Returns every antipodal vertex-index pair, via rotating calipers.
Definition measures.hpp:615
constexpr bool boundaryContains(const OtherRegion &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
constexpr auto squaredHausdorffDistance(const OtherRectangle &other) const
Returns the squared Hausdorff distance to the given shape.
Definition distance.hpp:1132
constexpr Convex(Range &&points, bool trusted=false)
Creates a convex from a range of points.
Definition convex.hpp:200
constexpr auto minkowskiErosion(const OtherShape &other) const
Returns the Minkowski erosion of this shape by another (A ⊖ B).
Definition minkowskierosion.hpp:636
constexpr auto distanceLInf(const OtherSegment &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:720
constexpr bool contains(const OtherRegion &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Disk< Point< NumberType > > smallestEnclosingDisk(UniformRandomBitGenerator &&generator) const
Returns the smallest closed disk containing the convex polygon.
constexpr auto hausdorffDistanceL1(const OtherRectangle &other) const
Returns the Manhattan (L1) Hausdorff distance to the given shape.
Definition distancel1.hpp:1096
constexpr bool contains(const OtherTriangle &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1219
constexpr bool interiorContains(const OtherDisk &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:907
constexpr bool contains(const OtherRegion &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2854
constexpr bool boundaryContains(const OtherChain &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1226
constexpr auto hausdorffDistanceL1(const OtherTriangle &other) const
Returns the Manhattan (L1) Hausdorff distance to the given shape.
Definition distancel1.hpp:1104
constexpr auto distanceLInf(const OtherHalfplane &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:820
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > difference(const OtherIntersection &other) const
Returns the regularized set difference of the two shapes (A ∖ B).
constexpr bool interiorContains(const OtherSegment &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:803
constexpr auto distanceL1(const OtherOrientedLine &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:809
constexpr bool contains(const OtherOrientedLine &) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1182
BoundaryIterator< false > EdgeIterator
Definition convex.hpp:182
constexpr bool interiorContains(const OtherSet &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition convex.hpp:1961
constexpr bool separates(const OtherTriangle &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1578
constexpr bool crosses(const OtherConvex &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:609
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > regularizedUnion(const OtherConvex &other) const
Returns the regularized union of the two shapes (A ∪ B).
constexpr auto hausdorffDistanceLInf(const OtherRectangle &other) const
Returns the Chebyshev (LInf) Hausdorff distance to the given shape.
Definition distancelinf.hpp:1084
auto regularizedUnion(const Shape< OtherPoint > &other) const
Returns the regularized union of the two shapes (A ∪ B), re-dispatching through the wrapper's own reg...
Definition convex.hpp:2519
constexpr auto distanceL1(const OtherPoint &point) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:715
constexpr bool interiorContains(const OtherConvex &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:872
size_t size() const
Returns the number of vertices in the convex polygon.
Definition convex.hpp:840
constexpr bool interiorsIntersect(const OtherSegment &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:842
constexpr auto cbegin() const
Returns a constant iterator to the beginning of vertices.
Definition convex.hpp:306
constexpr auto distanceL1(const OtherConvex &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:756
constexpr bool interiorContains(const Shape< OtherPoint > &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:918
constexpr bool interiorContains(const OtherTriangle &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:858
constexpr Convex(const Convex< OtherPointType, OtherLabelType > &other)
Converts a convex with compatible vertex type.
Definition convex.hpp:257
constexpr const PointType operator[](std::size_t index) const
Accesses a vertex by index.
Definition convex.hpp:279
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > regularizedUnion(const OtherRectangle &other) const
Returns the regularized union of the two shapes (A ∪ B).
constexpr auto squaredDistance(const OtherRay &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1047
constexpr bool boundaryContains(const OtherPoint &point) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:652
constexpr HalfplaneIntersection< PointType > smallestEnclosingRectangle() const
Returns the smallest-area rectangle containing the convex polygon.
Definition measures.hpp:725
constexpr auto distanceLInf(const OtherTriangle &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:769
PointType PointType
Definition convex.hpp:171
constexpr auto distanceLInf(const OtherShape &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition convex.hpp:2630
constexpr Convex scaledDownY(const OtherNumber scalar) const
Returns the convex polygon with its y-coordinates divided by a divisor.
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
Weakly x-monotone polyline stored by lexicographically sorted vertices.
Definition monotonechain.hpp:146
Sentinel type used when a point carries no extra label.
Definition point.hpp:31
Two-dimensional point with optional label payload.
Definition point.hpp:129
Set of closed regions with pairwise disjoint interiors.
Definition polygonset.hpp:165
Closed region bounded by one outer simple polygon minus disjoint polygonal holes.
Definition polygonwithholes.hpp:89
Closed simple polygon stored by its vertices.
Definition polygon.hpp:59
Axis-aligned rectangle stored by minimum and maximum corners.
Definition rectangle.hpp:75
Unoriented closed segment between two endpoints plus optional segment label.
Definition segment.hpp:58
Runtime variant wrapper over the supported primitive shapes.
Definition shape.hpp:160