24template <
class Po
intType = Po
int<>,
class Label>
29template <std::ranges::input_range Range>
30requires detail::is_point_v<std::ranges::range_value_t<Range>>
33template <
class Number>
34requires (!detail::is_point_v<Number>)
37template <
class Number>
38requires (!detail::is_point_v<Number>)
58template <
class Po
intType_,
class TLabel>
63 static_assert(detail::is_point_v<PointType>,
"Polygon requires pgl::Point vertices");
65 template <
bool Oriented>
68 template <
bool Oriented>
69 class BoundaryIterator;
90 template<std::ranges::input_range Range = std::initializer_list<Po
intType>>
91 requires std::ranges::common_range<Range> &&
92 std::convertible_to<std::ranges::range_value_t<Range>,
PointType>
93 constexpr explicit Polygon(Range&& points,
bool trusted =
false) {
94 for (
const auto& p : points) {
113 constexpr explicit Polygon(std::initializer_list<NumberType> coords,
bool trusted =
false) {
114 assert(coords.size() % 2 == 0);
115 points_.reserve(coords.size() / 2);
116 for (
auto it = coords.begin(); it != coords.end(); ) {
119 points_.emplace_back(
x,
y);
135 template<Po
intConcept OtherPo
intType,
class OtherLabelType>
136 requires(std::constructible_from<PointType, const OtherPointType&>)
138 : points_(other.
begin(), other.
end()), label_(detail::copyLabel<LabelType>(other)) {}
148 template <
class A = LabelType>
149 requires(detail::has_label_v<A>)
161 return points_[
index] + translation_;
170 const std::ptrdiff_t n =
static_cast<std::ptrdiff_t
>(
size());
171 return (*
this)[
static_cast<std::size_t
>(((
index % n) + n) % n)];
185 for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(
size()); ++i) {
186 if ((*
this)[
static_cast<std::size_t
>(i)] == point) {
197 return Iterator(points_.begin(), translation_);
204 return Iterator(points_.cbegin(), translation_);
210 constexpr auto end()
const {
211 return Iterator(points_.end(), translation_);
218 return Iterator(points_.cend(), translation_);
225 if (
auto cmp = points_.size() <=> other.points_.size(); cmp != 0) {
228 for (std::size_t i = 0; i < points_.size(); ++i) {
229 if (
auto cmp = points_[i] + translation_ <=> other.points_[i] + other.translation_; cmp != 0) {
233 return std::strong_ordering::equal;
241 if (points_.size() != other.points_.size()) {
244 for (std::size_t i = 0; i < points_.size(); ++i) {
245 if (points_[i] + translation_ != other.points_[i] + other.translation_) {
253 template<AnyShapeConcept OtherShape>
254 [[nodiscard]]
constexpr bool samePointSet(
const OtherShape& other)
const;
259 constexpr std::size_t
size()
const {
260 return points_.size();
272 template <
class ResultNumber = NumberType>
274 if (points_.size() < 3) {
275 return ResultNumber(0);
277 return pgl::detail::abs(signedTwiceArea<ResultNumber>());
284 template <
class ResultNumber = division_result_t<NumberType>>
286 ResultNumber result =
static_cast<ResultNumber
>(
twiceArea());
287 return result / ResultNumber(2);
302 [[nodiscard]]
constexpr bool empty()
const {
303 return points_.empty();
330 [[nodiscard]]
constexpr bool isPoint()
const {
331 return detail::allPointsEqual(points_);
341 [[nodiscard]]
constexpr std::optional<PointType>
getIfPoint()
const {
345 return points_.front() + translation_;
359 return detail::pointsSpanSegment(points_);
369 [[nodiscard]]
constexpr std::optional<BoundaryType<false>>
getIfSegment()
const {
373 return detail::spannedSegment<BoundaryType<false>>(points_) + translation_;
407 template <
class Rational = pgl::Rational<pgl::BigInt>>
424 const std::ptrdiff_t n =
static_cast<std::ptrdiff_t
>(
size());
428 bool sawPositive =
false;
429 bool sawNegative =
false;
430 for (std::ptrdiff_t i = 0; i < n; ++i) {
434 }
else if (turn < 0) {
437 if (sawPositive && sawNegative) {
465 const std::ptrdiff_t n =
static_cast<std::ptrdiff_t
>(
size());
472 std::size_t breaks = 0;
473 bool previous =
get(n - 1) <
get(0);
474 for (std::ptrdiff_t i = 0; i < n; ++i) {
475 const bool ascends =
get(i) <
get(i + 1);
476 if (ascends != previous) {
571 template <
class ResultNumber = gr
id_number_t<
typename Po
intType_::NumberType>>
572 requires(detail::extended_integral<ResultNumber> || std::same_as<ResultNumber, BigInt>)
581 template <std::
floating_po
int ResultNumber =
double>
587 constexpr std::vector<PointType>
vertices()
const {
589 for (
auto&
vertex : ret) {
598 constexpr std::vector<Segment<PointType>>
edges()
const {
599 std::vector<Segment<PointType>> result;
600 const auto translatedVertices =
vertices();
601 for (std::size_t i = 0; i < translatedVertices.size(); ++i) {
602 const auto& p1 = translatedVertices[i];
603 const auto& p2 = translatedVertices[(i + 1) % translatedVertices.size()];
604 result.emplace_back(p1, p2);
613 std::vector<OrientedSegment<PointType>> result;
614 const auto translatedVertices =
vertices();
615 for (std::size_t i = 0; i < translatedVertices.size(); ++i) {
616 const auto& p1 = translatedVertices[i];
617 const auto& p2 = translatedVertices[(i + 1) % translatedVertices.size()];
618 result.emplace_back(p1, p2);
758 template <
class ResultNumber = division_result_t<NumberType>>
771 return std::ranges::subrange(
begin(),
end());
856 template <
class ResultNumber = division_result_t<NumberType>>
858 if (points_.size() < 3) {
868 ResultNumber areaTwice = 0;
869 const std::size_t n = points_.size();
870 for (std::size_t i = 0; i < n; ++i) {
871 const auto& p1 = points_[i];
872 const auto& p2 = points_[(i + 1) % n];
873 const ResultNumber cross = detail::asNumber<ResultNumber>(p1.x()) * detail::asNumber<ResultNumber>(p2.y())
874 - detail::asNumber<ResultNumber>(p2.x()) * detail::asNumber<ResultNumber>(p1.y());
876 cx += (detail::asNumber<ResultNumber>(p1.x()) + detail::asNumber<ResultNumber>(p2.x())) * cross;
877 cy += (detail::asNumber<ResultNumber>(p1.y()) + detail::asNumber<ResultNumber>(p2.y())) * cross;
879 if (areaTwice == ResultNumber(0)) {
882 const ResultNumber denom = ResultNumber(3) * areaTwice;
891 template <
class ResultNumber = division_result_t<NumberType>>
893 if (points_.empty()) {
898 for (
const auto&
vertex : points_) {
899 cx += detail::asNumber<ResultNumber>(
vertex.x());
900 cy += detail::asNumber<ResultNumber>(
vertex.y());
903 cy /
static_cast<ResultNumber
>(points_.size()))
926 template <
class ResultNumber = division_result_t<NumberType>>
937 template <
class OtherShape>
961 template <
class SegmentRange>
1026 template <
class ResultNumber = gr
id_number_t<
typename Po
intType_::NumberType>>
1027 requires(std::signed_integral<ResultNumber>)
1042 template <
class Po
intRange,
class SegmentRange>
1043 auto triangulation(
const PointRange& points,
const SegmentRange& segments)
const;
1075 template <
class ResultNumber = division_result_t<NumberType>, PolygonConcept OtherPolygon>
1080 template <
class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
1085 template <
class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
1090 template <
class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
1095 template <
class ResultNumber = division_result_t<NumberType>, PolygonWithHolesConcept OtherRegion>
1108 template <
class ResultNumber = division_result_t<NumberType>, PolygonSetConcept OtherSet>
1121 template <
class ResultNumber = division_result_t<NumberType>, HalfplaneIntersectionConcept OtherIntersection>
1131 template <
class ResultNumber = division_result_t<NumberType>, HalfplaneConcept OtherHalfplane>
1160 template <
class ResultNumber = division_result_t<NumberType>, PolygonConcept OtherPolygon>
1165 template <
class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
1170 template <
class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
1175 template <
class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
1180 template <
class ResultNumber = division_result_t<NumberType>, PolygonWithHolesConcept OtherRegion>
1195 template <
class ResultNumber = division_result_t<NumberType>, PolygonSetConcept OtherSet>
1218 template <
class ResultNumber = division_result_t<NumberType>, PolygonConcept OtherPolygon>
1223 template <
class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
1228 template <
class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
1233 template <
class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
1238 template <
class ResultNumber = division_result_t<NumberType>, PolygonWithHolesConcept OtherRegion>
1252 template <
class ResultNumber = division_result_t<NumberType>, PolygonSetConcept OtherSet>
1295 template <
class ResultNumber = division_result_t<NumberType>, PolygonConcept OtherPolygon>
1300 template <
class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
1305 template <
class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
1310 template <
class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
1315 template <
class ResultNumber = division_result_t<NumberType>, PolygonWithHolesConcept OtherRegion>
1328 template <
class ResultNumber = division_result_t<NumberType>, PolylineConcept OtherPolyline>
1342 template <
class ResultNumber = division_result_t<NumberType>, MonotoneChainConcept OtherChain>
1363 template <
class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
1373 template <
class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherSegment>
1387 template <
class ResultNumber = division_result_t<NumberType>, PolygonSetConcept OtherSet>
1399 template<Po
intConcept OtherPo
int>
1400 constexpr bool contains(
const OtherPoint& point)
const;
1411 template<SegmentConcept OtherSegment>
1412 constexpr bool contains(
const OtherSegment& other)
const;
1419 template<OrientedSegmentConcept OtherOrientedSegment>
1420 constexpr bool contains(
const OtherOrientedSegment& other)
const;
1425 template<LineConcept OtherLine>
1431 template<OrientedLineConcept OtherOrientedLine>
1432 constexpr bool contains(
const OtherOrientedLine& other)
const;
1437 template<RayConcept OtherRay>
1443 template<HalfplaneConcept OtherHalfplane>
1444 constexpr bool contains(
const OtherHalfplane& other)
const;
1451 template<RectangleConcept OtherRectangle>
1452 constexpr bool contains(
const OtherRectangle& other)
const;
1459 template<TriangleConcept OtherTriangle>
1460 constexpr bool contains(
const OtherTriangle& other)
const;
1467 template<ConvexConcept OtherConvex>
1468 constexpr bool contains(
const OtherConvex& other)
const;
1478 template<PolygonConcept OtherPolygon>
1479 constexpr bool contains(
const OtherPolygon& other)
const;
1502 template<PolygonConcept OtherPolygon>
1514 template<DiskConcept OtherDisk>
1526 template <
class EmptyPo
int>
1531 template <
class EmptyPo
int>
1536 template <
class EmptyPo
int>
1549 template<Po
intConcept OtherPo
int>
1560 template<SegmentConcept OtherSegment>
1572 template<SegmentConcept OtherSegment>
1580 template<OrientedSegmentConcept OtherOrientedSegment>
1586 template<LineConcept OtherLine>
1592 template<OrientedLineConcept OtherOrientedLine>
1598 template<RayConcept OtherRay>
1604 template<HalfplaneConcept OtherHalfplane>
1612 template<RectangleConcept OtherRectangle>
1620 template<TriangleConcept OtherTriangle>
1628 template<ConvexConcept OtherConvex>
1639 template<PolygonConcept OtherPolygon>
1647 template<Po
intConcept OtherPo
int>
1658 template<SegmentConcept OtherSegment>
1662 template<OrientedSegmentConcept OtherOrientedSegment>
1666 template<LineConcept OtherLine>
1670 template<OrientedLineConcept OtherOrientedLine>
1674 template<RayConcept OtherRay>
1678 template<HalfplaneConcept OtherHalfplane>
1686 template<RectangleConcept OtherRectangle>
1694 template<TriangleConcept OtherTriangle>
1700 template<ConvexConcept OtherConvex>
1706 template<PolygonConcept OtherPolygon>
1712 template<DiskConcept OtherDisk>
1718 template<Po
intConcept OtherPo
int>
1723 template<DiskConcept OtherDisk>
1727 template<Po
intConcept OtherPo
int>
1728 [[nodiscard]]
constexpr bool separates(
const OtherPoint& other)
const;
1731 template<HalfplaneConcept OtherHalfplane>
1732 [[nodiscard]]
constexpr bool separates(
const OtherHalfplane& other)
const;
1735 template<RectangleConcept OtherRectangle>
1736 [[nodiscard]]
constexpr bool separates(
const OtherRectangle& other)
const;
1739 template<TriangleConcept OtherTriangle>
1740 [[nodiscard]]
constexpr bool separates(
const OtherTriangle& other)
const;
1743 template<DiskConcept OtherDisk>
1744 [[nodiscard]]
constexpr bool separates(
const OtherDisk& other)
const;
1747 template<ConvexConcept OtherConvex>
1748 [[nodiscard]]
constexpr bool separates(
const OtherConvex& other)
const;
1751 template<PolygonConcept OtherPolygon>
1752 [[nodiscard]]
constexpr bool separates(
const OtherPolygon& other)
const;
1755 template<MonotoneChainConcept OtherChain>
1756 [[nodiscard]]
constexpr bool contains(
const OtherChain& other)
const;
1759 template<MonotoneChainConcept OtherChain>
1763 template<MonotoneChainConcept OtherChain>
1767 template<MonotoneChainConcept OtherChain>
1768 [[nodiscard]]
constexpr bool intersects(
const OtherChain& other)
const;
1771 template<MonotoneChainConcept OtherChain>
1783 template<MonotoneChainConcept OtherChain>
1784 [[nodiscard]]
constexpr bool separates(
const OtherChain& other)
const;
1787 template<MonotoneChainConcept OtherChain>
1788 [[nodiscard]]
constexpr bool crosses(
const OtherChain& other)
const;
1791 template <
class ResultNumber = division_result_t<NumberType>, MonotoneChainConcept OtherChain>
1795 template <
class ResultNumber = division_result_t<NumberType>, MonotoneChainConcept OtherChain>
1796 [[nodiscard]]
constexpr auto distanceL1(
const OtherChain& other)
const;
1799 template <
class ResultNumber = division_result_t<NumberType>, MonotoneChainConcept OtherChain>
1803 template<PolylineConcept OtherPolyline>
1804 [[nodiscard]]
constexpr bool contains(
const OtherPolyline& other)
const;
1807 template<PolylineConcept OtherPolyline>
1811 template<PolylineConcept OtherPolyline>
1815 template<PolylineConcept OtherPolyline>
1816 [[nodiscard]]
constexpr bool intersects(
const OtherPolyline& other)
const;
1819 template<PolylineConcept OtherPolyline>
1829 template<PolylineConcept OtherPolyline>
1830 [[nodiscard]]
constexpr bool separates(
const OtherPolyline& other)
const;
1833 template<HalfplaneIntersectionConcept OtherRegion>
1834 [[nodiscard]]
constexpr bool contains(
const OtherRegion& other)
const;
1837 template<HalfplaneIntersectionConcept OtherRegion>
1841 template<HalfplaneIntersectionConcept OtherRegion>
1845 template<HalfplaneIntersectionConcept OtherRegion>
1846 [[nodiscard]]
constexpr bool separates(
const OtherRegion& other)
const;
1855 template<PolygonWithHolesConcept OtherRegion>
1856 [[nodiscard]]
constexpr bool contains(
const OtherRegion& other)
const;
1864 template<PolygonWithHolesConcept OtherRegion>
1868 template<PolygonWithHolesConcept OtherRegion>
1878 template<PolygonWithHolesConcept OtherRegion>
1879 [[nodiscard]]
bool separates(
const OtherRegion& other)
const;
1890 template<PolygonSetConcept OtherSet>
1891 [[nodiscard]]
constexpr bool contains(
const OtherSet& other)
const {
1892 for (
const auto& component : other) {
1901 template<PolygonSetConcept OtherSet>
1903 for (
const auto& component : other) {
1912 template<PolygonSetConcept OtherSet>
1914 for (
const auto& component : other) {
1930 template<PolygonSetConcept OtherSet>
1934 template<PolylineConcept OtherPolyline>
1935 [[nodiscard]]
constexpr bool crosses(
const OtherPolyline& other)
const;
1938 template <
class ResultNumber = division_result_t<NumberType>, PolylineConcept OtherPolyline>
1942 template <
class ResultNumber = division_result_t<NumberType>, PolylineConcept OtherPolyline>
1943 [[nodiscard]]
constexpr auto distanceL1(
const OtherPolyline& other)
const;
1946 template <
class ResultNumber = division_result_t<NumberType>, PolylineConcept OtherPolyline>
1947 [[nodiscard]]
constexpr auto distanceLInf(
const OtherPolyline& other)
const;
1955 template<Po
intConcept OtherPo
int>
1963 template<SegmentConcept OtherSegment>
1971 template<OrientedSegmentConcept OtherOrientedSegment>
1972 constexpr bool intersects(
const OtherOrientedSegment& other)
const;
1979 template<LineConcept OtherLine>
1987 template<OrientedLineConcept OtherOrientedLine>
1995 template<RayConcept OtherRay>
2003 template<HalfplaneConcept OtherHalfplane>
2011 template<RectangleConcept OtherRectangle>
2019 template<TriangleConcept OtherTriangle>
2027 template<ConvexConcept OtherConvex>
2037 template<PolygonConcept OtherPolygon>
2055 template<PolygonConcept OtherPolygon>
2063 template<PolygonConcept OtherPolygon>
2068 template<DiskConcept OtherDisk>
2076 template<Po
intConcept OtherPo
int>
2084 template<LineConcept OtherLine>
2092 template<OrientedLineConcept OtherOrientedLine>
2100 template<SegmentConcept OtherSegment>
2108 template<OrientedSegmentConcept OtherOrientedSegment>
2116 template<RayConcept OtherRay>
2124 template<HalfplaneConcept OtherHalfplane>
2132 template<RectangleConcept OtherRectangle>
2140 template<TriangleConcept OtherTriangle>
2148 template<ConvexConcept OtherConvex>
2156 template<PolygonConcept OtherPolygon>
2160 template<DiskConcept OtherDisk>
2172 template<SegmentConcept OtherSegment>
2176 template<OrientedSegmentConcept OtherOrientedSegment>
2177 constexpr bool separates(
const OtherOrientedSegment& other)
const;
2188 template<RayConcept OtherRay>
2194 template<LineConcept OtherLine>
2198 template<OrientedLineConcept OtherOrientedLine>
2199 constexpr bool separates(
const OtherOrientedLine& other)
const;
2202 template<Po
intConcept OtherPo
int>
2203 [[nodiscard]]
constexpr bool crosses(
const OtherPoint&)
const;
2206 template<SegmentConcept OtherSegment>
2207 [[nodiscard]]
constexpr bool crosses(
const OtherSegment& other)
const;
2210 template<OrientedSegmentConcept OtherOrientedSegment>
2211 [[nodiscard]]
constexpr bool crosses(
const OtherOrientedSegment& other)
const;
2214 template<RayConcept OtherRay>
2215 [[nodiscard]]
constexpr bool crosses(
const OtherRay& other)
const;
2218 template<LineConcept OtherLine>
2219 [[nodiscard]]
constexpr bool crosses(
const OtherLine& other)
const;
2222 template<OrientedLineConcept OtherOrientedLine>
2223 [[nodiscard]]
constexpr bool crosses(
const OtherOrientedLine& other)
const;
2226 template<HalfplaneConcept OtherHalfplane>
2227 [[nodiscard]]
constexpr bool crosses(
const OtherHalfplane&)
const;
2230 template<RectangleConcept OtherRectangle>
2231 [[nodiscard]]
constexpr bool crosses(
const OtherRectangle&)
const;
2234 template<TriangleConcept OtherTriangle>
2235 [[nodiscard]]
constexpr bool crosses(
const OtherTriangle&)
const;
2238 template<ConvexConcept OtherConvex>
2239 [[nodiscard]]
constexpr bool crosses(
const OtherConvex&)
const;
2242 template<DiskConcept OtherDisk>
2243 [[nodiscard]]
constexpr bool crosses(
const OtherDisk&)
const;
2246 template<PolygonConcept OtherPolygon>
2247 [[nodiscard]]
constexpr bool crosses(
const OtherPolygon&)
const;
2250 template<Po
intConcept OtherPo
int>
2254 template<Po
intConcept OtherPo
int>
2258 template<Po
intConcept OtherPo
int>
2262 template<
typename OtherShape>
2264 [[nodiscard]]
constexpr bool crosses(
const OtherShape& other)
const {
2265 return other.crosses(*
this);
2274 template<
typename OtherShape>
2276 [[nodiscard]]
constexpr bool intersects(
const OtherShape& other)
const {
2277 return other.intersects(*
this);
2286 template<
typename OtherShape>
2289 return other.interiorsIntersect(*
this);
2293 template <
class EmptyPo
int>
2299 template <
class EmptyPo
int>
2305 template <
class EmptyPo
int>
2329 template <
class ResultNumber = division_result_t<NumberType>, Po
intConcept OtherPo
int>
2333 template <
class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
2337 template <
class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
2341 template <
class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
2345 template <
class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
2349 template <
class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
2353 template <
class ResultNumber = division_result_t<NumberType>, HalfplaneConcept OtherHalfplane>
2357 template <
class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
2361 template <
class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
2365 template <
class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
2369 template <
class ResultNumber = division_result_t<NumberType>, PolygonConcept OtherPolygon>
2378 template <
class ResultNumber = division_result_t<NumberType>,
typename OtherShape>
2379 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Polygon>)
2380 &&
requires(
const OtherShape& o,
const Polygon& self) {
2395 template <
class ResultNumber =
double,
class DiskPo
intType,
class DiskLabel>
2411 template <
class ResultNumber = NumberType, BoundedPolygonalConcept OtherShape>
2412 requires detail::ClosestPairConcept<Polygon<PointType_, TLabel>, OtherShape>
2431 template <
class ResultNumber = division_result_t<NumberType>,
class OtherShape>
2432 requires detail::ClosestPointsPairConcept<Polygon<PointType_, TLabel>, OtherShape>
2436 template <
class ResultNumber = division_result_t<NumberType>, Po
intConcept OtherPo
int>
2437 [[nodiscard]]
constexpr auto distanceL1(
const OtherPoint& point)
const;
2440 template <
class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
2441 [[nodiscard]]
constexpr auto distanceL1(
const OtherSegment& other)
const;
2444 template <
class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
2445 [[nodiscard]]
constexpr auto distanceL1(
const OtherOrientedSegment& other)
const;
2448 template <
class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
2449 [[nodiscard]]
constexpr auto distanceL1(
const OtherLine& other)
const;
2452 template <
class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
2453 [[nodiscard]]
constexpr auto distanceL1(
const OtherOrientedLine& other)
const;
2456 template <
class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
2457 [[nodiscard]]
constexpr auto distanceL1(
const OtherRay& other)
const;
2460 template <
class ResultNumber = division_result_t<NumberType>, HalfplaneConcept OtherHalfplane>
2461 [[nodiscard]]
constexpr auto distanceL1(
const OtherHalfplane& other)
const;
2464 template <
class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
2465 [[nodiscard]]
constexpr auto distanceL1(
const OtherRectangle& other)
const;
2468 template <
class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
2469 [[nodiscard]]
constexpr auto distanceL1(
const OtherTriangle& other)
const;
2472 template <
class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
2473 [[nodiscard]]
constexpr auto distanceL1(
const OtherConvex& other)
const;
2476 template <
class ResultNumber = division_result_t<NumberType>, PolygonConcept OtherPolygon>
2477 [[nodiscard]]
constexpr auto distanceL1(
const OtherPolygon& other)
const;
2485 template <
class ResultNumber = division_result_t<NumberType>,
typename OtherShape>
2486 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Polygon>)
2487 &&
requires(
const OtherShape& o,
const Polygon& self) {
2490 [[nodiscard]]
constexpr auto distanceL1(
const OtherShape& other)
const {
2509 template <
class ResultNumber = division_result_t<NumberType>, Po
intConcept OtherPo
int>
2515 template <
class ResultNumber = division_result_t<NumberType>, Po
intConcept OtherPo
int>
2532 template <
class ResultNumber = division_result_t<NumberType>, Po
intConcept OtherPo
int>
2551 template <
class ResultNumber = division_result_t<NumberType>, Po
intConcept OtherPo
int>
2569 template <
class ResultNumber = division_result_t<NumberType>, Po
intConcept OtherPo
int>
2581 template <
class ResultNumber =
double, Po
intConcept OtherPo
int>
2587 template <
class ResultNumber = division_result_t<NumberType>, Po
intConcept OtherPo
int>
2591 template <
class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
2592 [[nodiscard]]
constexpr auto distanceLInf(
const OtherSegment& other)
const;
2595 template <
class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
2596 [[nodiscard]]
constexpr auto distanceLInf(
const OtherOrientedSegment& other)
const;
2599 template <
class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
2603 template <
class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
2604 [[nodiscard]]
constexpr auto distanceLInf(
const OtherOrientedLine& other)
const;
2607 template <
class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
2611 template <
class ResultNumber = division_result_t<NumberType>, HalfplaneConcept OtherHalfplane>
2612 [[nodiscard]]
constexpr auto distanceLInf(
const OtherHalfplane& other)
const;
2615 template <
class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
2616 [[nodiscard]]
constexpr auto distanceLInf(
const OtherRectangle& other)
const;
2619 template <
class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
2620 [[nodiscard]]
constexpr auto distanceLInf(
const OtherTriangle& other)
const;
2623 template <
class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
2627 template <
class ResultNumber = division_result_t<NumberType>, PolygonConcept OtherPolygon>
2628 [[nodiscard]]
constexpr auto distanceLInf(
const OtherPolygon& other)
const;
2636 template <
class ResultNumber = division_result_t<NumberType>,
typename OtherShape>
2637 requires ((detail::shapeRank<OtherShape> > detail::shapeRank<Polygon>)
2638 &&
requires(
const OtherShape& o,
const Polygon& self) {
2646 template <
class ResultNumber =
double, Po
intConcept OtherPo
int>
2659 template <
class ResultNumber = NumberType, Po
intConcept OtherPo
int>
2660 [[nodiscard]]
constexpr std::optional<Point<ResultNumber, typename PointType::LabelType>>
2686 template <
class ResultNumber = division_result_t<NumberType>, SegmentConcept OtherSegment>
2698 template <
class ResultNumber = division_result_t<NumberType>, OrientedSegmentConcept OtherOrientedSegment>
2722 template <
class ResultNumber = division_result_t<NumberType>, LineConcept OtherLine>
2734 template <
class ResultNumber = division_result_t<NumberType>, OrientedLineConcept OtherOrientedLine>
2758 template <
class ResultNumber = division_result_t<NumberType>, RayConcept OtherRay>
2783 template <
class ResultNumber = division_result_t<NumberType>, PolygonConcept OtherPolygon>
2798 template <
class ResultNumber = division_result_t<NumberType>, ConvexConcept OtherConvex>
2813 template <
class ResultNumber = division_result_t<NumberType>, TriangleConcept OtherTriangle>
2828 template <
class ResultNumber = division_result_t<NumberType>, RectangleConcept OtherRectangle>
2841 template <
class ResultNumber = division_result_t<NumberType>,
typename OtherShape>
2843 && (detail::shapeRank<OtherShape> > detail::shapeRank<Polygon>)
2844 &&
requires(
const OtherShape& o,
const Polygon& self) {
2852 template <
class ResultNumber = division_result_t<NumberType>,
typename OtherShape>
2854 && (detail::shapeRank<OtherShape> > detail::shapeRank<Polygon>)
2855 &&
requires(
const OtherShape& o,
const Polygon& self) {
2863 template <
class ResultNumber = NumberType,
class EmptyPo
int>
2890 template <
class ResultNumber = division_result_t<NumberType>, HalfplaneConcept OtherHalfplane>
2910 template <
class ResultNumber = division_result_t<NumberType>, PolylineConcept OtherPolyline>
2911 [[nodiscard]]
constexpr auto intersection(
const OtherPolyline& other)
const;
2928 template <
class ResultNumber = division_result_t<NumberType>, MonotoneChainConcept OtherChain>
2984 template <
class OtherNumber>
2988 template <
class OtherNumber>
2992 template <
class OtherNumber>
2996 template <
class OtherNumber>
3000 template <
class OtherNumber>
3004 template <
class OtherNumber>
3008 template <
class OtherNumber>
3012 template <
class OtherNumber>
3028 template <
class OtherShape>
3055 template <
class OtherShape>
3090 template <
class ResultNumber = division_result_t<NumberType>,
class OtherShape>
3101 template<Po
intConcept OtherPo
int>
3103 translation_ += translation;
3107 if (!bbox_.empty()) {
3108 bbox_ += translation;
3119 template<Po
intConcept OtherPo
int>
3121 translation_ -= translation;
3122 if (!bbox_.empty()) {
3123 bbox_ -= translation;
3135 template <
class Scalar>
3137 constexpr Polygon&
operator*=(
const Scalar& scalar) {
3138 for (
auto&
vertex : points_) {
3141 translation_ *= scalar;
3152 template <
class Scalar>
3154 constexpr Polygon&
operator/=(
const Scalar& scalar) {
3155 for (
auto&
vertex : points_) {
3158 translation_ /= scalar;
3170 template <
bool Oriented>
3182 assert(polygon !=
nullptr);
3183 return polygon->template boundaryAt<Oriented>(index);
3203 : polygon(polygon_arg), index(index_arg) {}
3205 const Polygon* polygon =
nullptr;
3206 std::size_t
index = 0;
3210 std::vector<PointType> points_{};
3211 [[no_unique_address]]
mutable LabelType label_{};
3217 mutable Rectangle<PointType> bbox_{};
3224 static constexpr std::size_t hashUnset_ = pgl::detail::numeric_limits<std::size_t>::max();
3225 mutable std::size_t hash_ = hashUnset_;
3226 friend struct std::hash<
Polygon>;
3232 constexpr void resetCache()
const {
3240 void untangleRuntime();
3242 template <
bool Oriented>
3244 const auto i =
static_cast<std::ptrdiff_t
>(
index);
3255 template <
class ResultNumber,
class OtherShape>
3256 constexpr ResultNumber edgeMinSquaredDistance(
const OtherShape& other)
const;
3259 template <
class ResultNumber,
class OtherShape>
3260 constexpr ResultNumber edgeMinDistanceL1(
const OtherShape& other)
const;
3263 template <
class ResultNumber,
class OtherShape>
3264 constexpr ResultNumber edgeMinDistanceLInf(
const OtherShape& other)
const;
3277 template <
class ResultNumber = NumberType>
3278 constexpr ResultNumber signedTwiceArea()
const {
3279 ResultNumber sum = 0;
3280 const std::size_t n = points_.size();
3281 for (std::size_t i = 0; i < n; ++i) {
3282 const auto& p1 = points_[i];
3283 const auto& p2 = points_[(i + 1) % n];
3284 sum += detail::asNumber<ResultNumber>(p1.x()) * detail::asNumber<ResultNumber>(p2.y())
3285 - detail::asNumber<ResultNumber>(p2.x()) * detail::asNumber<ResultNumber>(p1.y());
3297 constexpr bool hasNoArea()
const {
3298 using Exact = detail::promoted_number_t<NumberType>;
3299 return signedTwiceArea<Exact>() == Exact(0);
3312 constexpr bool windsClockwise(std::size_t pivot)
const {
3313 const std::size_t n = points_.size();
3315 std::size_t before = (pivot + n - 1) % n;
3316 while (before != pivot && points_[before] ==
vertex) {
3317 before = (before + n - 1) % n;
3319 std::size_t after = (pivot + 1) % n;
3320 while (after != pivot && points_[after] ==
vertex) {
3321 after = (after + 1) % n;
3337 constexpr void normalize() {
3338 if (points_.empty()) {
3341 auto minIt = std::min_element(points_.begin(), points_.end());
3342 if (points_.size() >= 3 &&
3343 windsClockwise(
static_cast<std::size_t
>(minIt - points_.begin()))) {
3346 std::reverse(points_.begin(), points_.end());
3347 minIt = std::min_element(points_.begin(), points_.end());
3349 std::rotate(points_.begin(), minIt, points_.end());
3378 template <
class Poly>
3379 class BoundaryChains {
3381 using PT =
typename Poly::PointType;
3384 explicit BoundaryChains(
const Poly& poly) : verts_(poly.
vertices()) {
3386 buffer_.reserve(2 * n_);
3389 const auto ascends = [&](std::size_t i) {
return verts_[i] < verts_[(i + 1) % n_]; };
3394 std::size_t start = 0;
3396 for (std::size_t j = 0; j < n_; ++j) {
3397 if (ascends((j + n_ - 1) % n_) != ascends(j)) {
3410 std::size_t i = start;
3412 const bool up = ascends(i);
3413 runs_.push_back({i, up});
3415 while (ascends(k) == up) {
3419 }
while (i != start);
3422 bool exhausted()
const {
return produced_ == runs_.size(); }
3423 const std::vector<ChainView>& produced()
const {
return chains_; }
3426 const ChainView& produceNext() {
3427 const auto [
begin, up] = runs_[produced_];
3428 const std::size_t
end = runs_[(produced_ + 1) % runs_.size()].first;
3429 const std::size_t bufStart = buffer_.size();
3430 std::size_t idx =
begin;
3431 buffer_.push_back(verts_[idx]);
3432 while (idx !=
end) {
3433 idx = (idx + 1) % n_;
3434 buffer_.push_back(verts_[idx]);
3436 const std::size_t len = buffer_.size() - bufStart;
3438 std::reverse(buffer_.begin() +
static_cast<std::ptrdiff_t
>(bufStart), buffer_.end());
3440 chains_.emplace_back(std::span<const PT>(buffer_.data() + bufStart, len),
true);
3442 return chains_.back();
3446 std::vector<PT> verts_;
3447 std::vector<PT> buffer_;
3448 std::vector<std::pair<std::size_t, bool>> runs_;
3449 std::vector<ChainView> chains_;
3451 std::size_t produced_ = 0;
3456 std::vector<PointType>::const_iterator it;
3460 using iterator_category = std::random_access_iterator_tag;
3461 using difference_type = std::ptrdiff_t;
3466 Iterator() =
default;
3467 Iterator(std::vector<PointType>::const_iterator it,
PointType x) : it(it), x(x) {}
3475 Iterator& operator++() {
3481 Iterator operator++(
int) {
3482 Iterator tmp = *
this;
3488 Iterator& operator--() {
3494 Iterator operator--(
int) {
3495 Iterator tmp = *
this;
3501 bool operator==(
const Iterator& other)
const {
3502 return it == other.it;
3506 auto operator<=>(
const Iterator& other)
const {
3507 return it <=> other.it;
3511 Iterator operator+(difference_type n)
const {
3512 return Iterator(it + n, x);
3516 Iterator operator-(difference_type n)
const {
3517 return Iterator(it - n, x);
3521 difference_type operator-(
const Iterator& other)
const {
3522 return it - other.it;
3526 PointType operator[](difference_type n)
const {
3527 return *(it + n) + x;
3532template <
class Po
intType,
class LabelType,
class TranslationNumber,
class TranslationLabel>
3534 return polygon + (-translation);
3537template <
class Po
intType,
class LabelType,
class Scalar>
3538 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
3543 if constexpr (detail::has_label_v<LabelType>) {
3544 result.
label() = LabelType{};
3549template <
class Scalar,
class Po
intType,
class LabelType>
3550 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
3552 return polygon * scalar;
3555template <
class Po
intType,
class LabelType,
class Scalar>
3556 requires(!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
3561 if constexpr (detail::has_label_v<LabelType>) {
3562 result.
label() = LabelType{};
3567template <
class Po
intType,
class LabelType>
Undirected simple graph stored as adjacency sets.
Definition graph.hpp:38
std::ptrdiff_t difference_type
Definition polygon.hpp:3176
constexpr value_type operator*() const
Definition polygon.hpp:3181
constexpr bool operator==(const BoundaryIterator &other) const =default
friend struct Polygon
Definition polygon.hpp:3200
BoundaryType< Oriented > value_type
Definition polygon.hpp:3175
constexpr BoundaryIterator operator++(int)
Definition polygon.hpp:3191
constexpr BoundaryIterator()=default
constexpr BoundaryIterator & operator++()
Definition polygon.hpp:3186
std::forward_iterator_tag iterator_category
Definition polygon.hpp:3173
value_type reference
Definition polygon.hpp:3177
std::forward_iterator_tag iterator_concept
Definition polygon.hpp:3174
Bounded polygonal primitives, convex or not.
Definition forward.hpp:373
Shape pairs whose Minkowski sum Pangolin can represent.
Definition forward.hpp:476
Definition forward.hpp:306
Definition arrangement.hpp:67
@ y
Definition intervaltree.hpp:24
@ x
Definition intervaltree.hpp:24
@ vertex
Definition bitmatrix.hpp:37
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< PointType, Label, std::span< const PointType > > MonotoneChainView
A non-owning MonotoneChain that views an external, already canonical (sorted, duplicate-free) contigu...
Definition monotonechain.hpp:2670
constexpr std::partial_ordering orientationSign(const Point< ANumber, ALabel > &a, const Point< BNumber, BLabel > &b, const Point< CNumber, CLabel > &c)
Classifies the orientation of three points.
Definition orientation.hpp:544
Shape(const std::variant< T, Ts... > &) -> Shape< detail::shape_point_type_t< T > >
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
Polygon() -> Polygon< Point<>, NoLabel >
Definition polygon.hpp:3200
Closed convex polygon stored by its vertices.
Definition convex.hpp:170
constexpr Segment< PointType > diameter() const
Returns a segment realizing the diameter (the farthest vertex pair).
Definition measures.hpp:696
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
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
ERational NumberType
Definition point.hpp:131
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
constexpr auto squaredDistance(const OtherChain &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1445
constexpr auto distanceL1(const OtherPoint &point) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:858
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > minkowskiSum(const OtherSet &other) const
Returns the regularized Minkowski sum of the two shapes (A ⊕ B), as a set of regions.
constexpr Point< ResultNumber > pointInside() const
Returns a point strictly inside the (simple) polygon.
Definition measures.hpp:1050
constexpr auto squaredDistance(const OtherPoint &point) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1335
PolygonWithHoles< Point< ResultNumber, typename PointType::LabelType > > minkowskiSum(const OtherTriangle &other) const
Returns the regularized Minkowski sum of the two shapes (A ⊕ B).
constexpr bool boundaryContains(const OtherOrientedSegment &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:891
PolygonWithHoles< Point< ResultNumber, typename PointType::LabelType > > minkowskiSum(const OtherRegion &other) const
Returns the regularized Minkowski sum of the two shapes (A ⊕ B).
constexpr bool crosses(const Shape< OtherPoint > &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:710
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > regularizedUnion(const OtherConvex &other) const
Returns the regularized union of the two shapes (A ∪ B).
auto regularizedIntersection(const Shape< OtherPoint > &other) const
Re-dispatches a regularized intersection through a runtime shape.
Definition polygon.hpp:2516
constexpr bool interiorsIntersect(const EmptyShape< EmptyPoint > &) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition polygon.hpp:2306
constexpr std::vector< std::variant< Point< ResultNumber, typename PointType::LabelType >, Polyline< Point< ResultNumber, typename PointType::LabelType > >, Polygon< 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:2203
constexpr bool boundaryContains(const OtherPoint &point) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:855
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:1094
constexpr bool interiorContains(const OtherChain &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1556
constexpr bool intersects(const OtherRectangle &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:1075
constexpr std::optional< PointType > getIfPoint() const
Returns the point the polygon collapses to, if it does.
Definition polygon.hpp:341
constexpr bool crosses(const OtherConvex &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:692
constexpr auto cbegin() const
Returns a constant iterator to the first vertex.
Definition polygon.hpp:203
constexpr bool crosses(const OtherOrientedSegment &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:646
PointType::NumberType NumberType
Definition polygon.hpp:61
constexpr bool interiorsIntersect(const OtherRectangle &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:1175
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > difference(const OtherTriangle &other) const
Returns the regularized set difference of the two shapes (A ∖ B).
constexpr bool contains(const OtherPolyline &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2490
constexpr bool crosses(const OtherOrientedLine &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:664
constexpr Convex< PointType > convexHull() const
Returns the convex hull of the polygon's vertices.
Definition polygon.hpp:537
constexpr bool intersects(const OtherChain &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:1596
constexpr auto distanceL1(const OtherOrientedSegment &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:876
constexpr auto distanceL1(const OtherRectangle &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:921
constexpr auto distanceLInf(const OtherPolyline &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:1372
constexpr auto distanceL1(const OtherTriangle &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:930
constexpr bool separates(const OtherLine &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1969
constexpr bool crosses(const OtherSegment &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:640
constexpr const Rectangle< PointType > & bbox() const
Computes the bounding box of the polygon.
Definition bounding.hpp:449
constexpr auto distanceLInf(const OtherPoint &point) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:846
constexpr bool boundaryContains(const OtherTriangle &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:938
constexpr auto operator<=>(const Polygon &other) const
Compares two polygons by their canonical vertex sequences.
Definition polygon.hpp:224
constexpr bool intersects(const OtherOrientedLine &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:1037
Graph< PointType > visibilityGraph() const
Returns the visibility graph of the polygon vertices.
Definition visibilitygraph.hpp:838
constexpr auto distanceLInf(const OtherPolygon &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:936
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > difference(const OtherPolygon &other) const
Returns the regularized set difference of the two shapes (A ∖ B).
constexpr bool interiorContains(const OtherOrientedSegment &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:986
constexpr bool crosses(const OtherTriangle &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:686
constexpr bool boundaryContains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition polygon.hpp:1532
constexpr bool interiorContains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition polygon.hpp:1537
constexpr bool interiorContains(const OtherRegion &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
constexpr std::size_t chainCount() const
Counts the maximal lexicographically monotone chains the boundary decomposes into,...
Definition polygon.hpp:464
constexpr bool crosses(const OtherChain &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:940
constexpr bool crosses(const EmptyShape< EmptyPoint > &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition polygon.hpp:2294
constexpr bool contains(const OtherRay &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1458
constexpr auto squaredDistance(const OtherLine &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1362
constexpr Polygon(std::initializer_list< NumberType > coords, bool trusted=false)
Creates a polygon from a flat list of coordinates.
Definition polygon.hpp:113
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > regularizedUnion(const OtherPolygon &other) const
Returns the regularized union of the two shapes (A ∪ B).
constexpr auto distanceL1(const Shape< OtherPoint > &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition polygon.hpp:2582
Graph< PointType > clearVisibilityGraph() const
Returns the clear visibility graph of the polygon vertices.
Definition visibilitygraph.hpp:862
constexpr Segment< PointType > diameter() const
Returns a segment realizing the diameter (the farthest vertex pair).
Definition polygon.hpp:530
constexpr Polygon scaledUpY(const OtherNumber scalar) const
Returns the polygon with its y-coordinates multiplied by a factor.
constexpr bool boundaryContains(const OtherLine &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:897
constexpr bool samePointSet(const OtherShape &other) const
Tests whether another shape defines exactly the same point set.
Definition samepointset.hpp:2019
constexpr Polygon(Range &&points, bool trusted=false)
Creates a polygon from a range of points.
Definition polygon.hpp:93
std::vector< PointType > clearlyVisibleVertices(const PointType &query) const
The polygon vertices clearly visible from query.
Definition visibilitygraph.hpp:896
constexpr bool contains(const OtherPoint &point) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1296
constexpr bool crosses(const OtherShape &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition polygon.hpp:2264
constexpr bool intersects(const OtherOrientedSegment &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:1007
constexpr bool interiorContains(const OtherDisk &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1347
constexpr std::optional< HalfplaneIntersection< PointType > > getStarShapedKernel() const
Returns the kernel: the set of points that see the whole polygon.
Definition halfplaneintersection.hpp:2649
constexpr std::ptrdiff_t index(const PointType &point) const
Definition polygon.hpp:184
constexpr bool contains(const OtherRegion &other) const
Tests whether this shape contains the other shape (A ⊇ B).
constexpr bool intersects(const OtherDisk &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:1328
constexpr bool interiorContains(const OtherRay &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1004
constexpr auto intersection(const OtherPolyline &other) const
Returns the intersection with an open polyline (A ∩ B), a sequence of points and segments.
Definition intersection.hpp:3030
constexpr bool crosses(const OtherDisk &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:698
constexpr bool separates(const OtherPolygon &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:2673
constexpr bool isUndefined() const
Checks whether the polygon is degenerate without covering a point or a segment.
Definition polygon.hpp:388
constexpr bool boundaryContains(const OtherRegion &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
constexpr bool boundaryContains(const OtherRectangle &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:921
PolygonWithHoles< Point< ResultNumber, typename PointType::LabelType > > minkowskiSum(const OtherRectangle &other) const
Returns the regularized Minkowski sum of the two shapes (A ⊕ B).
constexpr auto edgesView() const
Returns a lazy view over the edges, materializing each Segment on the fly instead of allocating a vec...
Definition polygon.hpp:782
PolygonSet< Point< ResultNumber, typename PointType_::LabelType > > minkowskiErosion(const OtherShape &other) const
Returns the regularized Minkowski erosion of this shape by a bounded polygonal one (A ⊖ B),...
Definition minkowskierosion.hpp:721
constexpr bool separates(const OtherRegion &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:4708
constexpr std::optional< BoundaryType< false > > getIfSegment() const
Returns the segment the polygon collapses to, if it does.
Definition polygon.hpp:369
constexpr bool isConvex() const
Tests whether the polygon is convex.
Definition polygon.hpp:423
auto symmetricDifference(const Shape< OtherPoint > &other) const
Returns the regularized symmetric difference of the two shapes (A △ B), re-dispatching through the wr...
Definition polygon.hpp:2570
auto triangulation() const
Builds the constrained Delaunay triangulation of this polygon.
Definition triangulation.hpp:6860
constexpr auto distanceL1(const OtherChain &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:1121
constexpr std::vector< std::variant< Point< ResultNumber, typename PointType::LabelType >, Polyline< Point< ResultNumber, typename PointType::LabelType > >, Polygon< 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:2196
auto asBitMatrix() const
Rasterizes this polygon into a BitMatrix, one bit per covered cell.
Definition bitmatrix.hpp:2698
constexpr bool interiorContains(const OtherRectangle &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1018
constexpr bool interiorsIntersect(const OtherOrientedLine &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:1026
constexpr bool contains(const OtherOrientedLine &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1452
constexpr auto squaredDistance(const OtherRay &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1380
constexpr auto orientedEdgesView() const
Lazy view counterpart of orientedEdges(); see edgesView().
Definition polygon.hpp:790
constexpr std::vector< 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:1982
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 polygon.hpp:2533
bool isSimple() const
Tests whether the polygon is simple (its boundary does not touch or cross itself).
Definition xysweep.hpp:246
constexpr auto distanceL1(const OtherHalfplane &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:912
constexpr Rectangle< Point< ResultNumber > > fbox() const
Computes the floating-point bounding box of the polygon.
Definition bounding.hpp:461
constexpr std::vector< 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:1975
constexpr auto distanceLInf(const OtherOrientedLine &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:882
constexpr auto squaredDistance(const OtherOrientedSegment &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1353
constexpr bool contains(const OtherTriangle &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1488
constexpr bool interiorsIntersect(const OtherLine &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:1004
constexpr auto distanceLInf(const OtherShape &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition polygon.hpp:2641
constexpr bool crosses(const OtherRectangle &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:676
constexpr bool isPoint() const
Checks whether the polygon covers exactly one point.
Definition polygon.hpp:330
constexpr PolygonSet< PointType > asPolygonSet() const
Returns the polygon as a one-component set of regions.
Definition polygon.hpp:847
constexpr bool interiorsIntersect(const Shape< OtherPoint > &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:1383
constexpr bool interiorsIntersect(const OtherOrientedSegment &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:1077
constexpr Point< ResultNumber > centroid() const
Computes the area-weighted centroid of the polygon.
Definition polygon.hpp:857
constexpr auto distanceL1(const OtherPolyline &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:1384
constexpr bool boundaryContains(const OtherSegment &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:874
constexpr bool intersects(const OtherTriangle &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:1102
constexpr bool boundaryContains(const OtherRay &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:909
bool separates(const OtherSet &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:5984
std::conditional_t< Oriented, OrientedSegment< PointType >, Segment< PointType > > BoundaryType
Definition polygon.hpp:66
constexpr bool interiorsIntersect(const OtherSegment &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:1032
constexpr bool interiorsIntersect(const OtherConvex &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:1191
constexpr bool separates(const OtherConvex &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:2667
constexpr bool separates(const OtherHalfplane &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1990
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > regularizedUnion(const OtherRegion &other) const
Returns the regularized union of the two shapes (A ∪ B).
auto regularizedIntersection(const OtherShape &other) const
Forwards a regularized intersection to the shape that owns it.
Definition polygon.hpp:2858
PolygonWithHoles< Point< ResultNumber, typename PointType::LabelType > > minkowskiSum(const OtherPolyline &other) const
Returns the regularized Minkowski sum of the two shapes (A ⊕ B).
constexpr std::vector< 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:1967
auto triangulation(const SegmentRange &segments) const
Builds the constrained Delaunay triangulation of this polygon with the given interior constraint segm...
Definition triangulation.hpp:6866
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > difference(const OtherSet &other) const
Returns the regularized set difference of the two shapes (A ∖ B).
constexpr auto distanceL1(const OtherPolygon &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:948
constexpr auto distanceLInf(const OtherRay &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:891
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > difference(const OtherRectangle &other) const
Returns the regularized set difference of the two shapes (A ∖ B).
constexpr bool intersects(const OtherHalfplane &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:1057
constexpr bool containsChainBased(const OtherPolygon &other) const
Same contract as contains(const OtherPolygon&) const, by the chain-pair strategy alone.
Definition contains.hpp:1587
constexpr bool interiorContains(const OtherTriangle &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1034
constexpr auto squaredDistance(const OtherHalfplane &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1389
constexpr auto minkowskiSum(const OtherShape &other) const
Returns the Minkowski sum of this shape and another (A ⊕ B).
Definition minkowski.hpp:804
constexpr void scaleUpX(const OtherNumber scalar)
Multiplies the polygon's x-coordinates by a factor in place.
Definition transformations.hpp:1816
constexpr Polygon scaledDownY(const OtherNumber scalar) const
Returns the polygon with its y-coordinates divided by a divisor.
constexpr Polygon()=default
Creates a polygon with no vertex.
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:1942
constexpr auto intersection(const OtherChain &other) const
Returns the intersection with a monotone chain (A ∩ B), a sequence of points and segments.
Definition intersection.hpp:3036
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > regularizedUnion(const OtherTriangle &other) const
Returns the regularized union of the two shapes (A ∪ B).
constexpr bool isSegment() const
Checks whether the polygon covers exactly one segment of positive length.
Definition polygon.hpp:358
constexpr bool intersects(const Shape< OtherPoint > &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:1172
constexpr std::vector< 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:1960
constexpr bool crosses(const OtherPoint &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:634
bool separates(const OtherRegion &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:5729
constexpr auto squaredDistance(const OtherSegment &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1344
PolygonWithHoles< Point< ResultNumber, typename PointType::LabelType > > minkowskiSum(const OtherConvex &other) const
Returns the regularized Minkowski sum of the two shapes (A ⊕ B).
constexpr void scaleDownY(const OtherNumber scalar)
Divides the polygon's y-coordinates by a divisor in place.
Definition transformations.hpp:1873
constexpr auto distanceL1(const OtherShape &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition polygon.hpp:2490
constexpr auto squaredDistance(const OtherOrientedLine &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1371
constexpr auto squaredDistance(const OtherConvex &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1416
constexpr bool intersects(const OtherPolyline &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:1787
constexpr bool operator==(const Polygon &other) const
Checks equality of two polygons.
Definition polygon.hpp:240
constexpr bool contains(const OtherOrientedSegment &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1440
constexpr bool boundaryContains(const OtherPolyline &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1355
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > symmetricDifference(const OtherRectangle &other) const
Returns the regularized symmetric difference of the two shapes (A △ B).
constexpr bool intersects(const EmptyShape< EmptyPoint > &) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition polygon.hpp:2300
constexpr bool contains(const OtherSegment &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1348
constexpr bool interiorContains(const OtherRegion &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:2194
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 polygon.hpp:2510
constexpr bool interiorsIntersect(const OtherDisk &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:1621
constexpr bool contains(const OtherHalfplane &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1464
constexpr auto distanceLInf(const OtherConvex &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:927
constexpr Polygon(const Polygon< OtherPointType, OtherLabelType > &other)
Converts a polygon with compatible vertex type.
Definition polygon.hpp:137
constexpr bool intersects(const OtherLine &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:1013
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > symmetricDifference(const OtherPolygon &other) const
Returns the regularized symmetric difference of the two shapes (A △ B).
constexpr bool interiorContains(const OtherHalfplane &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1010
constexpr auto distanceLInf(const Shape< OtherPoint > &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition polygon.hpp:2647
constexpr EmptyShape< EmptyPoint > intersection(const EmptyShape< EmptyPoint > &) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition polygon.hpp:2864
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > symmetricDifference(const OtherConvex &other) const
Returns the regularized symmetric difference of the two shapes (A △ B).
constexpr EdgeIterator edgesEnd() const
Returns an iterator past the last unoriented edge.
Definition polygon.hpp:806
constexpr bool boundariesIntersect(const OtherPolygon &other) const
Tests whether the two polygon boundaries share at least one point (∂A ∩ ∂B ≠ ∅).
Definition interiorsintersect.hpp:1197
constexpr bool interiorsIntersect(const OtherPolygon &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:1278
constexpr auto squaredDistance(const OtherPolygon &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1425
constexpr auto begin() const
Returns a constant iterator to the first vertex.
Definition polygon.hpp:196
constexpr auto distanceLInf(const OtherOrientedSegment &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:864
constexpr auto squaredDistance(const OtherShape &other) const
Returns the squared Euclidean distance to the given shape.
Definition polygon.hpp:2383
constexpr bool separates(const OtherChain &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:3213
constexpr bool contains(const OtherRectangle &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1472
constexpr const PointType operator[](std::size_t index) const
Accesses a vertex by index.
Definition polygon.hpp:159
constexpr bool boundaryContains(const OtherOrientedLine &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:903
constexpr std::size_t size() const
Returns the number of vertices in the polygon.
Definition polygon.hpp:259
Polygon< Point< ResultNumber > > regularizedVisiblePolygon(const PointType &query) const
The part of the polygon visible from query, regularized.
Definition visibilitygraph.hpp:906
constexpr auto distanceLInf(const OtherSegment &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:855
constexpr bool crosses(const OtherRay &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:652
constexpr auto closestPoints(const OtherShape &other) const
Returns the pair of points realizing the distance, nothing when the shapes meet.
Definition closest.hpp:419
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > difference(const OtherIntersection &other) const
Returns the regularized set difference of the two shapes (A ∖ B).
constexpr bool contains(const Shape< PointType > &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1675
constexpr bool boundaryContains(const OtherDisk &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:980
constexpr auto distanceLInf(const OtherRectangle &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:909
constexpr bool boundariesStrongCross(const OtherPolygon &other) const
Tests whether the two polygon boundaries have mononotone chains that strong cross.
Definition interiorsintersect.hpp:1241
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > symmetricDifference(const OtherRegion &other) const
Returns the regularized symmetric difference of the two shapes (A △ B).
constexpr Polygon & operator-=(const OtherPoint &translation)
Translates the polygon by the negation of the given point.
Definition polygon.hpp:3120
constexpr bool crosses(const OtherLine &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:658
constexpr bool interiorsIntersect(const OtherTriangle &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:1185
constexpr ResultNumber twiceArea() const
Computes twice the (unsigned) area of the polygon via the shoelace formula.
Definition polygon.hpp:273
constexpr A & label() const
Returns the polygon label.
Definition polygon.hpp:150
constexpr bool separates(const OtherOrientedLine &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1984
constexpr OrientedEdgeIterator orientedEdgesBegin() const
Returns an iterator to the first oriented edge.
Definition polygon.hpp:814
constexpr auto minkowskiErosion(const OtherShape &other) const
Returns the Minkowski erosion of this shape by another (A ⊖ B).
Definition minkowskierosion.hpp:637
constexpr bool interiorsIntersect(const OtherRay &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:1083
constexpr bool crosses(const OtherHalfplane &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:670
std::vector< Point< ResultNumber, typename PointType::LabelType > > latticePoints() const
Returns the integer points the polygon contains.
Definition lattice.hpp:661
constexpr EdgeIterator edgesBegin() const
Returns an iterator to the first unoriented edge.
Definition polygon.hpp:798
constexpr bool boundaryContains(const OtherRegion &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1786
constexpr bool crosses(const OtherPolygon &) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:704
constexpr bool interiorContains(const OtherSet &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition polygon.hpp:1913
constexpr bool separates(const OtherOrientedSegment &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1978
constexpr bool boundaryContains(const OtherHalfplane &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:915
constexpr bool interiorContains(const OtherPoint &point) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:931
std::vector< PointType > visibleVertices(const PointType &query) const
The polygon vertices visible from query.
Definition visibilitygraph.hpp:887
BoundaryIterator< false > EdgeIterator
Definition polygon.hpp:71
constexpr auto closestSegments(const OtherShape &other) const
Returns the pair of elements realizing the distance, nothing when the shapes meet.
Definition closest.hpp:412
BoundaryIterator< true > OrientedEdgeIterator
Definition polygon.hpp:72
constexpr bool interiorContains(const OtherConvex &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1050
constexpr bool interiorContains(const OtherPolygon &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1084
constexpr bool intersects(const OtherConvex &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:1125
constexpr std::vector< OrientedSegment< PointType > > orientedEdges() const
Returns the oriented edges of the polygon.
Definition polygon.hpp:612
constexpr bool interiorContainsInterior(const OtherSegment &other) const
Tests whether this shape's interior contains the segment's interior.
Definition interiorcontains.hpp:960
constexpr Polygon & operator+=(const OtherPoint &translation)
Translates the polygon by the given point.
Definition polygon.hpp:3102
constexpr OrientedEdgeIterator orientedEdgesEnd() const
Returns an iterator past the last oriented edge.
Definition polygon.hpp:822
constexpr bool intersects(const OtherPolygon &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:1148
constexpr bool contains(const OtherPolygon &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1566
constexpr void untangle()
Makes the polygon simple in place by uncrossing its boundary.
Definition transformations.hpp:1731
EPoint PointType
Definition polygon.hpp:60
constexpr auto distanceL1(const OtherRay &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:903
constexpr bool contains(const OtherConvex &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1503
constexpr void rotate90(int k=1)
Rotates the polygon by 90k degrees around the origin in place.
Definition transformations.hpp:1724
constexpr bool interiorsIntersect(const OtherChain &other) const
Tests whether the interiors of the shapes intersect (A° ∩ B° ≠ ∅).
Definition interiorsintersect.hpp:1833
constexpr void scaleUpY(const OtherNumber scalar)
Multiplies the polygon's y-coordinates by a factor in place.
Definition transformations.hpp:1835
constexpr auto distanceLInf(const OtherHalfplane &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:900
constexpr auto distanceLInf(const OtherLine &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:873
constexpr bool interiorContains(const OtherPolyline &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:1795
constexpr bool separates(const OtherTriangle &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:2466
constexpr std::vector< 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:1952
constexpr auto distanceLInf(const OtherTriangle &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:918
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > difference(const OtherConvex &other) const
Returns the regularized set difference of the two shapes (A ∖ B).
constexpr std::vector< PointType > vertices() const
Returns the vertices of the polygon (translation applied).
Definition polygon.hpp:587
PolygonWithHoles< Point< ResultNumber, typename PointType::LabelType > > minkowskiSum(const OtherSegment &other) const
Returns the regularized Minkowski sum of the two shapes (A ⊕ B).
constexpr auto squaredDistance(const OtherPolyline &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1729
constexpr bool separates(const OtherRectangle &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:2456
constexpr bool contains(const OtherDisk &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1657
constexpr bool interiorsIntersect(const OtherShape &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition polygon.hpp:2288
constexpr std::vector< std::variant< Point< ResultNumber, typename PointType::LabelType >, Polyline< Point< ResultNumber, typename PointType::LabelType > >, Polygon< 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:2189
TLabel LabelType
Definition polygon.hpp:62
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > difference(const OtherRegion &other) const
Returns the regularized set difference of the two shapes (A ∖ B).
auto triangulation(const PointRange &points, const SegmentRange &segments) const
Builds the constrained Delaunay triangulation of this polygon with the given interior vertices and co...
Definition triangulation.hpp:6872
constexpr auto area() const
Computes the area of the polygon.
Definition polygon.hpp:285
constexpr std::vector< std::variant< Point< ResultNumber, typename PointType::LabelType >, Segment< Point< ResultNumber, typename PointType::LabelType > >, Polygon< 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:2210
std::vector< Convex< PointType > > convexPartition() const
Cuts this polygon into convex pieces with disjoint interiors.
Definition triangulation.hpp:6878
constexpr auto squaredDistance(const OtherTriangle &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1407
constexpr bool interiorContains(const OtherOrientedLine &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:998
constexpr auto squaredDistance(const OtherRectangle &other) const
Returns the squared Euclidean distance to the given shape.
Definition distance.hpp:1398
constexpr bool boundaryContains(const OtherChain &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:1245
constexpr std::vector< Segment< PointType > > edges() const
Returns the edges of the polygon.
Definition polygon.hpp:598
constexpr auto distanceL1(const OtherOrientedLine &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:894
constexpr bool separates(const OtherSegment &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1870
constexpr bool boundaryContains(const OtherSet &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition polygon.hpp:1902
Graph< PointType > reducedVisibilityGraph() const
Returns the reduced visibility graph of the polygon vertices.
Definition visibilitygraph.hpp:875
constexpr auto distanceL1(const OtherLine &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:885
auto intersection(const OtherShape &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition polygon.hpp:2847
constexpr bool contains(const OtherSet &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition polygon.hpp:1891
constexpr bool boundaryContains(const OtherPolygon &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:965
PolygonWithHoles< Point< ResultNumber, typename PointType::LabelType > > minkowskiSum(const OtherChain &other) const
Returns the regularized Minkowski sum of the two shapes (A ⊕ B).
constexpr bool contains(const OtherRegion &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2916
constexpr bool intersects(const OtherPoint &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:985
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > difference(const OtherHalfplane &other) const
Returns the regularized set difference of the two shapes (A ∖ B).
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > regularizedUnion(const OtherRectangle &other) const
Returns the regularized union of the two shapes (A ∪ B).
constexpr auto distanceL1(const OtherConvex &other) const
Returns the Manhattan (L1) distance to the given shape.
Definition distancel1.hpp:939
constexpr bool isStarShaped() const
Tests whether the polygon is star-shaped.
Definition polygon.hpp:515
constexpr bool intersects(const OtherSegment &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:991
constexpr bool separates(const OtherRay &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1936
constexpr PolygonWithHoles< PointType > asPolygonWithHoles() const
Returns the polygon as a hole-free region.
Definition polygon.hpp:835
constexpr auto distanceLInf(const OtherChain &other) const
Returns the Chebyshev (LInf) distance to the given shape.
Definition distancelinf.hpp:1109
constexpr bool boundaryContains(const Shape< OtherPoint > &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:989
constexpr bool interiorContains(const OtherSegment &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:940
constexpr Polygon scaledUpX(const OtherNumber scalar) const
Returns the polygon with its x-coordinates multiplied by a factor.
constexpr Polygon rotated90(int k=1) const
Returns the polygon rotated by 90k degrees around the origin.
Definition transformations.hpp:1714
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 polygon.hpp:169
PolygonSet< Point< ResultNumber, typename PointType::LabelType > > symmetricDifference(const OtherTriangle &other) const
Returns the regularized symmetric difference of the two shapes (A △ B).
constexpr bool contains(const OtherChain &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:2109
constexpr auto verticesView() const
Returns a lazy view over the vertices, translating each on the fly instead of allocating a vector.
Definition polygon.hpp:770
constexpr bool crosses(const OtherPolyline &other) const
Tests whether the two shapes mutually separate each other (each disconnects the other).
Definition crosses.hpp:1038
constexpr bool interiorsIntersect(const OtherHalfplane &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:1120
constexpr bool intersects(const OtherShape &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition polygon.hpp:2276
constexpr Polygon scaledDownX(const OtherNumber scalar) const
Returns the polygon with its x-coordinates divided by a divisor.
constexpr bool interiorsIntersect(const OtherPoint &other) const
Tests whether the interiors of the two shapes intersect ((A∖∂A) ∩ (B∖∂B) ≠ ∅).
Definition interiorsintersect.hpp:997
constexpr bool contains(const EmptyShape< EmptyPoint > &) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition polygon.hpp:1527
constexpr bool isDegenerate() const
Checks if the polygon is degenerate (has zero area).
Definition polygon.hpp:319
constexpr bool separates(const OtherPolyline &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:4032
detail::floating_result_t< ResultNumber > squaredDistance(const Disk< DiskPointType, DiskLabel > &disk) const
Returns the squared Euclidean distance to a disk.
Definition distance.hpp:1434
constexpr bool empty() const
Returns whether the polygon is the empty set of points.
Definition polygon.hpp:302
constexpr std::vector< std::variant< Point< ResultNumber, typename PointType::LabelType >, Polyline< Point< ResultNumber, typename PointType::LabelType > >, Polygon< Point< ResultNumber, typename PointType::LabelType > > > > intersection(const OtherPolygon &other) const
Returns the intersection of the two shapes (A ∩ B), empty when they are disjoint.
Definition intersection.hpp:1990
constexpr bool separates(const OtherPoint &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:1864
constexpr auto cend() const
Returns a constant iterator past the last vertex.
Definition polygon.hpp:217
constexpr bool boundaryContains(const OtherConvex &other) const
Tests whether this shape's boundary contains the other shape (∂A ⊇ B).
Definition boundarycontains.hpp:950
constexpr auto end() const
Returns a constant iterator past the last vertex.
Definition polygon.hpp:210
std::vector< Convex< PointType > > convexCovering() const
Covers this polygon with convex hulls derived from triangle cliques.
Definition triangulation.hpp:6883
constexpr bool separates(const OtherDisk &other) const
Tests whether removing this shape disconnects the other shape (B∖A is disconnected).
Definition separates.hpp:2472
constexpr Point< ResultNumber > verticesCentroid() const
Computes the centroid of the vertex set (the average of the vertices).
Definition polygon.hpp:892
constexpr bool interiorsIntersect(const OtherPolyline &other) const
Tests whether the interiors of the shapes intersect (A° ∩ B° ≠ ∅).
Definition interiorsintersect.hpp:2096
auto symmetricDifference(const OtherSet &other) const
Returns the regularized symmetric difference of the two shapes (A △ B).
Definition polygon.hpp:1253
auto difference(const Shape< OtherPoint > &other) const
Returns the regularized set difference of the two shapes (A ∖ B), re-dispatching through the wrapper'...
Definition polygon.hpp:2552
constexpr bool contains(const OtherLine &other) const
Tests whether this shape contains the other shape (A ⊇ B).
Definition contains.hpp:1446
auto regularizedUnion(const OtherSet &other) const
Returns the regularized union of the two shapes (A ∪ B).
Definition polygon.hpp:1196
constexpr bool interiorContains(const OtherLine &other) const
Tests whether this shape's interior contains the other shape (A∖∂A ⊇ B).
Definition interiorcontains.hpp:992
constexpr void scaleDownX(const OtherNumber scalar)
Divides the polygon's x-coordinates by a divisor in place.
Definition transformations.hpp:1854
constexpr bool intersects(const OtherRay &other) const
Tests whether this shape and the other shape intersect (A ∩ B ≠ ∅).
Definition intersects.hpp:1043
PolygonWithHoles< Point< ResultNumber, typename PointType::LabelType > > minkowskiSum(const OtherPolygon &other) const
Returns the regularized Minkowski sum 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:867
Open polygonal chain stored in traversal order; may self-intersect.
Definition polyline.hpp:69
Axis-aligned rectangle stored by minimum and maximum corners.
Definition rectangle.hpp:75
Unoriented closed segment between two endpoints plus optional segment label.
Definition segment.hpp:58
Runtime variant wrapper over the supported primitive shapes.
Definition shape.hpp:160