Fishnet 2.0.1
Framework for Graph-Based Analysis of GIS Vector Data
Loading...
Searching...
No Matches
IPoint.hpp
Go to the documentation of this file.
1#pragma once
3#include <fishnet/Radians.hpp>
4#include "GeometryBase.hpp"
5
6namespace fishnet::geometry::__impl{
7
8template<typename T>
9class PointStub{
10private:
11 T x;
12 T y;
13public:
14 using numeric_type = T;
15 constexpr static GeometryType type = GeometryType::POINT;
16 constexpr PointStub(T x, T y) : x(x), y(y) {}
17 T getX() const noexcept{
18 return x;
19 }
20 T getY() const noexcept{
21 return y;
22 }
23 PointStub operator-() const noexcept{
24 return PointStub(-x, -y);
25 }
26 PointStub operator+(const PointStub & other) const noexcept{
27 return PointStub(x + other.x, y + other.y);
28 }
29 PointStub operator-(const PointStub & other) const noexcept{
30 return PointStub(x - other.x, y - other.y);
31 }
32 PointStub operator*(T scalar) const noexcept{
33 return PointStub(x * scalar, y * scalar);
34 }
35 PointStub operator/(T scalar) const noexcept{
36 return PointStub(x / scalar, y / scalar);
37 }
38 bool operator==(const PointStub & other) const noexcept{
39 return x == other.x && y == other.y;
40 }
41 double dot(const PointStub & other) const noexcept{
42 return 0.0;
43 }
44 double cross(const PointStub & other) const noexcept{
45 return 0.0;
46 }
47 bool isParallel(const PointStub & other) const noexcept{
48 return false;
49 }
50 bool isOrthogonal(const PointStub & other) const noexcept{
51 return false;
52 }
53 double length() const noexcept{
54 return 0.0;
55 }
56 double distance(const PointStub & other) const noexcept{
57 return 0.0;
58 }
59 PointStub orthogonal() const noexcept{
60 return PointStub(0,0);
61 }
62 PointStub normalize() const noexcept{
63 return PointStub(0,0);
64 }
65 fishnet::math::Radians angle(const PointStub & other) const noexcept{
67 }
68 fishnet::math::Radians angle(const PointStub & other, fishnet::math::Radians angleRotate) const noexcept{
70 }
71 size_t hash() const noexcept {
72 return 0;
73 }
74 std::string toString() const noexcept {
75 return {};
76 }
77};
78template<fishnet::math::Number T>
79constexpr auto operator*(T scalar, const PointStub<T> & point) noexcept{
80 return point * scalar;
81}
82} // namespace fishnet::geometry::__impl
83
84namespace fishnet::geometry{
85
91template<typename P>
92concept IPoint = GeometryBase<P> && requires(
93 const typename std::remove_cvref_t<P> & constPoint,
94 const __impl::PointStub<typename std::remove_cvref_t<P>::numeric_type> & otherPoint,
95 typename std::remove_cvref_t<P>::numeric_type number
96){
97 {constPoint.getX()} -> std::convertible_to<typename std::remove_cvref_t<P>::numeric_type>;
98 {constPoint.getY()} -> std::convertible_to<typename std::remove_cvref_t<P>::numeric_type>;
99 {std::remove_cvref_t<P>(number, number)} -> std::same_as<std::remove_cvref_t<P>>;
100 {-constPoint} -> std::same_as<std::remove_cvref_t<P>>;
101 {constPoint + otherPoint} -> std::same_as<std::remove_cvref_t<P>>;
102 {constPoint - otherPoint} -> std::same_as<std::remove_cvref_t<P>>;
103 {constPoint * number} -> std::same_as<std::remove_cvref_t<P>>;
104 {constPoint / number} -> std::convertible_to<std::remove_cvref_t<P>>;
105 {constPoint.dot(otherPoint)} -> std::convertible_to<typename std::remove_cvref_t<P>::numeric_type>;
106 {constPoint.cross(otherPoint)} -> std::convertible_to<typename std::remove_cvref_t<P>::numeric_type>;
107 {constPoint.isParallel(otherPoint)} -> std::same_as<bool>;
108 {constPoint.isOrthogonal(otherPoint)} -> std::same_as<bool>;
109 {constPoint.length()} -> std::convertible_to<double>;
110 {constPoint.distance(otherPoint)} -> std::convertible_to<double>;
111 {constPoint.orthogonal()} -> std::same_as<std::remove_cvref_t<P>>;
112 {constPoint.normalize()} -> std::convertible_to<std::remove_cvref_t<P>>;
113 {constPoint.angle(otherPoint)} -> std::same_as<fishnet::math::Radians>;
114 {constPoint.angle(otherPoint, fishnet::math::Radians(0.0))} -> std::same_as<fishnet::math::Radians>;
115};
116
126template<fishnet::math::Number T, fishnet::math::Number U>
127constexpr auto operator*(U scalar,const IPoint auto & vector) noexcept{
128 return vector * scalar;
129}
130
131static_assert(IPoint<__impl::PointStub<double>>, "PointStub<double> does not satisfy IPoint concept");
132static_assert(IPoint<__impl::PointStub<int>>, "PointStub<int> does not satisfy IPoint concept");
133
134template<typename P>
136
137template<typename R>
138concept PointRange = std::ranges::range<R> && IPoint<std::ranges::range_value_t<R>>;
139static_assert(PointRange<std::vector<__impl::PointStub<double>>>, "std::vector<__impl::PointStub<double>> does not satisfy PointRange concept");
140} // namespace fishnet::geometry
IPolygon implementation backed by an OGRPolygon.
Definition OGRPolygonAdapter.hpp:22
Radians implementation of Angle.
Definition Radians.hpp:11
static const Radians PI
Definition Radians.hpp:20
Definition GeometryBase.hpp:11
Definition IPoint.hpp:135
Interface for a point.
Definition IPoint.hpp:92
Definition IPoint.hpp:138
Definition BoundingBoxWrapper.hpp:5
constexpr auto operator*(U scalar, const IPoint auto &vector) noexcept
Reversed multiplication operator, allowing commutative behavior: e.g.: Vec2D(1,1) * 2 == 2 * Vec2D(1,...
Definition IPoint.hpp:127