Fishnet 2.0.1
Framework for Graph-Based Analysis of GIS Vector Data
Loading...
Searching...
No Matches
SimplePolygon.hpp
Go to the documentation of this file.
1#pragma once
3#include "Ring.hpp"
4#include "Rectangle.hpp"
5
6namespace fishnet::geometry {
12template<fishnet::math::Number T>
13class SimplePolygon : public Ring<T>{
14public:
15 using numeric_type = T;
16 constexpr static GeometryType type = GeometryType::POLYGON;
17
18 using Ring<T>::contains;
19 using Ring<T>::crosses;
20 using Ring<T>::touches;
21 using Ring<T>::distance;
22
23 SimplePolygon(const Ring<T> & boundary):Ring<T>(boundary){}
24
25 SimplePolygon(std::initializer_list<Vec2D<T>> && points):Ring<T>(std::move(points)){}
26
27 SimplePolygon(util::random_access_range_of<Vec2D<T>> auto const & points):Ring<T>(points) {}
28
29 SimplePolygon(util::random_access_range_of<Segment<T>> auto const & segments):Ring<T>(segments) {}
30
31 constexpr util::view_of<Segment<T>> auto getSegments() = delete;
32
34
35 constexpr const Ring<T> & getBoundary() const noexcept {
36 return static_cast<const Ring<T> &>(*this);
37 }
38
39 constexpr util::view_of<Ring<T>> auto getHoles() const noexcept {
40 return std::ranges::empty_view<Ring<T>>();
41 }
42
43 constexpr Rectangle<T> aaBB() const noexcept {
44 return this->getBoundary().aaBB();
45 }
46
47 template<fishnet::math::Number U>
48 constexpr bool inline operator==(const SimplePolygon<U> & other) const noexcept {
49 return this->getBoundary() == other.getBoundary();
50 }
51
52 constexpr bool isSimple() const noexcept {
53 return true;
54 }
55
56 constexpr bool inline containsInHole(IPoint auto const & point) const noexcept {
57 return false;
58 }
59
60 constexpr bool inline containsInHole(IPolygon auto const & other) const noexcept {
61 return false;
62 }
63
64 constexpr bool contains(IPolygon auto const & other) const noexcept {
65 return this->getBoundary().contains(other.getBoundary());
66 }
67
68 constexpr bool crosses(IPolygon auto const & other) const noexcept {
69 return this->getBoundary().crosses(other.getBoundary());
70 }
71
72 constexpr bool touches(IPolygon auto const & other) const noexcept {
73 return this->getBoundary().touches(other.getBoundary());
74 }
75
81 constexpr fishnet::math::DEFAULT_FLOATING_POINT distance(IPolygon auto const & other) const noexcept {
82 if(this->contains(other)) return 0;
83 if(this->touches(other)) return 0;
84 return this->getBoundary().distance(other.getBoundary());
85 }
86
87};
88
89//Deduction guides
90template<math::Number T>
92
93template<typename T>
94SimplePolygon(std::initializer_list<Vec2D<T>> && points)->SimplePolygon<T>;
95
96template<std::ranges::random_access_range R>
97SimplePolygon(const R & )->SimplePolygon<typename std::ranges::range_value_t<R>::numeric_type>;
98
99static_assert(Shape<SimplePolygon<double>>);
100static_assert(IPolygon<SimplePolygon<double>>);
101// Explicit template instantiation
103} // namespace fishnet::geometry
Implementation of a rectangle Stores top,right,bottom and left point of the rectangle.
Definition Rectangle.hpp:15
Implementation of a ring.
Definition Ring.hpp:31
Implementation of a segment.
Definition Segment.hpp:14
Simple polygon implementation with no holes.
Definition SimplePolygon.hpp:13
constexpr bool crosses(IPolygon auto const &other) const noexcept
Definition SimplePolygon.hpp:68
constexpr fishnet::math::DEFAULT_FLOATING_POINT distance(IPolygon auto const &other) const noexcept
Distance between the two polygons.
Definition SimplePolygon.hpp:81
constexpr bool containsInHole(IPolygon auto const &other) const noexcept
Definition SimplePolygon.hpp:60
T numeric_type
Definition SimplePolygon.hpp:15
constexpr util::view_of< Ring< T > > auto getHoles() const noexcept
Definition SimplePolygon.hpp:39
constexpr bool containsInHole(IPoint auto const &point) const noexcept
Definition SimplePolygon.hpp:56
constexpr bool contains(IPolygon auto const &other) const noexcept
Definition SimplePolygon.hpp:64
constexpr util::random_access_range_of< Vec2D< T > > auto getPoints()=delete
SimplePolygon(util::random_access_range_of< Segment< T > > auto const &segments)
Definition SimplePolygon.hpp:29
constexpr bool touches(IPolygon auto const &other) const noexcept
Definition SimplePolygon.hpp:72
SimplePolygon(const Ring< T > &boundary)
Definition SimplePolygon.hpp:23
static constexpr GeometryType type
Definition SimplePolygon.hpp:16
constexpr Rectangle< T > aaBB() const noexcept
Definition SimplePolygon.hpp:43
constexpr const Ring< T > & getBoundary() const noexcept
Definition SimplePolygon.hpp:35
constexpr util::view_of< Segment< T > > auto getSegments()=delete
constexpr bool isSimple() const noexcept
Definition SimplePolygon.hpp:52
SimplePolygon(util::random_access_range_of< Vec2D< T > > auto const &points)
Definition SimplePolygon.hpp:27
constexpr bool operator==(const SimplePolygon< U > &other) const noexcept
Definition SimplePolygon.hpp:48
SimplePolygon(std::initializer_list< Vec2D< T > > &&points)
Definition SimplePolygon.hpp:25
Implementation of a two-dimensional vector.
Definition Vec2D.hpp:16
Interface for a point.
Definition IPoint.hpp:92
Interface for a polygon A polygon is a two-dimensional shape defined by a boundary and zero or more h...
Definition IPolygon.hpp:98
A geometry enclosing an area: a ring, a polygon or a multi-polygon.
Definition IGeometry.hpp:23
Definition CollectionConcepts.hpp:39
Definition CollectionConcepts.hpp:45
Definition BoundingBoxWrapper.hpp:5
GeometryType
Definition GeometryBase.hpp:6
double DEFAULT_FLOATING_POINT
Definition NumericConcepts.hpp:12
STL namespace.