Point.h
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 // Author: Gonzalo Mier
4 // BSD-3 License
5 //=============================================================================
6 
7 #pragma once
8 #ifndef FIELDS2COVER_TYPES_POINT_H_
9 #define FIELDS2COVER_TYPES_POINT_H_
10 
11 #include <gdal/ogr_geometry.h>
12 #include <iostream>
13 #include <functional>
14 #include <memory>
15 #include <utility>
16 #include <vector>
18 
19 namespace f2c::types {
20 
21 struct Point : public Geometry<OGRPoint, wkbPoint> {
22  public:
24  Point();
25  Point(double x, double y, double z = 0);
26  Point(const Point&);
27  Point(Point&&);
28  ~Point();
29  Point& operator=(const Point&);
30  Point& operator=(Point&&);
31 
32  public:
33  bool operator==(const Point& b) const;
34 
35  bool operator!=(const Point& b) const;
36 
37  bool operator<(const Point& b) const;
38 
39  Point operator+(const Point& b) const;
40 
41  Point operator-(const Point& b) const;
42 
43  Point& operator*=(double b);
44 
45  Point operator*(double b) const;
46  double operator*(const Point& b) const;
47 
48  Point operator/(double b) const;
49 
50  static double det(const Point& u, const Point& v);
51 
52 
53  public:
54  Point clone() const;
55  double X() const;
56  double Y() const;
57  double Z() const;
58 
59  double getX() const;
60  double getY() const;
61  double getZ() const;
62  void setX(double x);
63  void setY(double y);
64  void setZ(double z);
65 
66  void setPoint(double x, double y, double z = 0);
67  void setPoint(const OGRPoint& p);
68  void setPoint(const Point& p);
69 
70  double getAngleFromPoints(const Point& end) const;
71  double getAngleFromPoint() const;
73  static double getAngleFromPoints(
74  const Point& p1, const Point& p2, const Point& p3);
75  Point getPointFromAngle(double angle, double dist) const;
76 
77  Point rotateFromPoint(double angle, const Point& p_r) const;
78 
79  double signedDistance2Segment(const Point& start, const Point& end) const;
81  const Point& l1_s, const Point& l1_e,
82  const Point& l2_s, const Point& l2_e);
83 
84  Point closestPointInSegment(const Point& seg_s, const Point& seg_e) const;
85 
86  template <class T>
87  std::vector<T> rotateFromPoint(double angle, const std::vector<T>& t) const;
88 
89  template <class T>
90  T rotateFromPoint(double angle, const T& t) const;
91 };
92 
93 std::ostream& operator<<(std::ostream& os, const Point& p);
94 
95 template <class T>
96 std::vector<T> Point::rotateFromPoint(
97  double angle, const std::vector<T>& t) const {
98  std::vector<T> res;
99  for (auto&& p : t) {
100  res.emplace_back(this->rotateFromPoint(angle, p));
101  }
102  return res;
103 }
104 
105 template <class T>
106 T Point::rotateFromPoint(double angle, const T& t) const {
107  T res;
108  for (auto&& p : t) {
109  res.addGeometry(this->rotateFromPoint(angle, p));
110  }
111  return res;
112 }
113 
114 
115 inline OGRPoint operator+(const OGRPoint& a, const f2c::types::Point& b) {
116  return {a.getX() + b.getX(), a.getY() + b.getY(), a.getZ() + b.getZ()};
117 }
118 
119 inline OGRPoint operator-(const OGRPoint& a, const f2c::types::Point& b) {
120  return {a.getX() - b.getX(), a.getY() - b.getY(), a.getZ() - b.getZ()};
121 }
122 
123 template <class T>
124 inline std::vector<T> operator+(
125  const std::vector<T>& t, const f2c::types::Point& dir) {
126  std::vector<T> res;
127  for (auto&& p : t) {
128  res.emplace_back(p + dir);
129  }
130  return res;
131 }
132 
133 template <class T>
134 inline std::vector<T> operator-(
135  const f2c::types::Point& dir, const std::vector<T>& t) {
136  std::vector<T> res;
137  for (auto&& p : t) {
138  res.emplace_back(dir - p);
139  }
140  return res;
141 }
142 
143 template <class T>
144 inline std::vector<T> operator-(
145  const std::vector<T>& t, const f2c::types::Point& dir) {
146  std::vector<T> res;
147  for (auto&& p : t) {
148  res.emplace_back(p - dir);
149  }
150  return res;
151 }
152 
153 template <class T>
154 inline T operator+(const T& t, const f2c::types::Point& dir) {
155  T res;
156  for (auto&& p : t) {
157  res.addGeometry(p + dir);
158  }
159  return res;
160 }
161 
162 template <class T>
163 inline T operator-(const f2c::types::Point& dir, const T& t) {
164  T res;
165  for (auto&& p : t) {
166  res.addGeometry(dir - p);
167  }
168  return res;
169 }
170 
171 template <class T>
172 inline T operator-(const T& t, const f2c::types::Point& dir) {
173  T res;
174  for (auto&& p : t) {
175  res.addGeometry(p - dir);
176  }
177  return res;
178 }
179 
180 } // namespace f2c::types
181 
182 namespace std {
183 template<>
184 struct hash<f2c::types::Point> {
185  inline size_t operator()(const f2c::types::Point& p) const {
186  return size_t(p.getX() + p.getY() * 1e10 + p.getZ() * 1e20);
187  }
188 };
189 }
190 
191 #endif // FIELDS2COVER_TYPES_POINT_H_
f2c::types::Point::setZ
void setZ(double z)
Definition: Point.cpp:101
f2c::types::operator<<
std::ostream & operator<<(std::ostream &os, const Point &p)
Definition: Point.cpp:37
f2c::types::Point::getZ
double getZ() const
Definition: Point.cpp:97
1_basic_types.p1
p1
Definition: 1_basic_types.py:11
f2c::types
Types used by fields2cover library.
Definition: Cell.h:20
f2c::types::Geometry
Definition: Geometry.h:26
f2c::types::Point::operator-
Point operator-(const Point &b) const
Definition: Point.cpp:61
1_basic_types.p3
p3
Definition: 1_basic_types.py:22
f2c::types::Point::operator+
Point operator+(const Point &b) const
Definition: Point.cpp:57
f2c::types::Point::operator<
bool operator<(const Point &b) const
Definition: Point.cpp:52
Geometry.h
1_basic_types.end
end
Definition: 1_basic_types.py:76
f2c::types::Point::intersectionOfLines
static Point intersectionOfLines(const Point &l1_s, const Point &l1_e, const Point &l2_s, const Point &l2_e)
Definition: Point.cpp:157
f2c::types::Point::closestPointInSegment
Point closestPointInSegment(const Point &seg_s, const Point &seg_e) const
Definition: Point.cpp:169
f2c::types::Point::Z
double Z() const
Definition: Point.cpp:94
std::hash< f2c::types::Point >::operator()
size_t operator()(const f2c::types::Point &p) const
Definition: Point.h:185
f2c::types::Point::operator==
bool operator==(const Point &b) const
Definition: Point.cpp:42
f2c::types::Point::Y
double Y() const
Definition: Point.cpp:93
f2c::types::Point::setX
void setX(double x)
Definition: Point.cpp:99
f2c::types::Point::operator*
Point operator*(double b) const
Definition: Point.cpp:72
f2c::types::Point::rotateFromPoint
Point rotateFromPoint(double angle, const Point &p_r) const
Definition: Point.cpp:121
1_basic_types.p2
p2
Definition: 1_basic_types.py:15
f2c::types::Point::Point
Point()
Definition: Point.cpp:11
f2c::types::Point::X
double X() const
Definition: Point.cpp:92
f2c::types::operator+
OGRPoint operator+(const OGRPoint &a, const f2c::types::Point &b)
Definition: Point.h:115
f2c::types::Point::operator*=
Point & operator*=(double b)
Definition: Point.cpp:65
f2c::types::Point::clone
Point clone() const
Definition: Point.cpp:88
f2c::types::Point::setPoint
void setPoint(double x, double y, double z=0)
Definition: Point.cpp:103
f2c::types::Point::operator!=
bool operator!=(const Point &b) const
Definition: Point.cpp:48
f2c::types::Point::getAngleFromPoints
double getAngleFromPoints(const Point &end) const
Definition: Point.cpp:132
f2c::types::Point::operator/
Point operator/(double b) const
Definition: Point.cpp:80
f2c::types::Point::signedDistance2Segment
double signedDistance2Segment(const Point &start, const Point &end) const
Definition: Point.cpp:149
f2c::types::Point
Definition: Point.h:21
f2c::types::Point::setY
void setY(double y)
Definition: Point.cpp:100
f2c::types::Point::operator=
Point & operator=(const Point &)
Definition: Point.cpp:30
std
Definition: Point.h:182
f2c
Main namespace of the fields2cover library.
Definition: boustrophedon_decomp.h:14
f2c::types::Point::getAngleFromPoint
double getAngleFromPoint() const
Definition: Point.cpp:136
f2c::types::operator-
OGRPoint operator-(const OGRPoint &a, const f2c::types::Point &b)
Definition: Point.h:119
f2c::types::Point::getY
double getY() const
Definition: Point.cpp:96
f2c::types::Point::getX
double getX() const
Definition: Point.cpp:95
f2c::types::Point::~Point
~Point()
f2c::types::Point::det
static double det(const Point &u, const Point &v)
Definition: Point.cpp:84
f2c::types::Point::getPointFromAngle
Point getPointFromAngle(double angle, double dist) const
Definition: Point.cpp:145


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31