Swath.cpp
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 
8 
9 namespace f2c::types {
10 
11 Swath::Swath() = default;
12 Swath::Swath(const LineString& _path) : path_(_path) {}
13 
14 Swath::Swath(double _width) {
15  this->setWidth(_width);
16 }
17 
18 Swath::Swath(const LineString& _path, double _width, int _id, SwathType _type) :
19  id_(_id), path_(_path), type_(_type) {
20  this->setWidth(_width);
21 }
22 
23 Swath::Swath(const Swath&) = default;
24 Swath::~Swath() = default;
25 Swath& Swath::operator=(Swath&&) = default;
26 Swath& Swath::operator=(const Swath&) = default;
27 
28 bool Swath::operator!=(const Swath& s) const {
29  if (s.getWidth() != this->getWidth()) {
30  return true;
31  }
32  Point this_p {this->startPoint()};
33  Point s_p = (this->hasSameDir(s) ? s.startPoint() : s.endPoint());
34  return (this_p.getX() != s_p.getX() || this_p.getY() != s_p.getY()) ||
35  s.length() != this->length();
36 }
37 
38 bool Swath::operator==(const Swath& s) const {
39  return !(s != *this);
40 }
41 
42 bool Swath::operator<(const Swath& s) const {
43  return this->getId() < s.getId();
44 }
45 
46 bool Swath::operator>(const Swath& s) const {
47  return this->getId() > s.getId();
48 }
49 
50 bool Swath::operator>=(const Swath& s) const {
51  return (this->getId() > s.getId() ||
52  (this->getId() == s.getId() && *this == s));
53 }
54 
55 bool Swath::operator<=(const Swath& s) const {
56  return (this->getId() < s.getId() ||
57  (this->getId() == s.getId() && *this == s));
58 }
59 
60 double Swath::length() const {
61  return this->path_.length();
62 }
63 
64 double Swath::area() const {
65  return this->areaCovered().area();
66 }
67 
68 double Swath::area(const Cells& polys) const {
69  return this->areaCovered(polys).area();
70 }
71 
73  this->path_.reversePoints();
74  this->creation_dir_ = !this->creation_dir_;
75 }
76 
77 double Swath::getInAngle() const {
78  if (this->path_.isEmpty()) {
79  return -1.0;
80  }
81  return (path_.getGeometry(1) - path_.getGeometry(0)).getAngleFromPoint();
82 }
83 
84 double Swath::getOutAngle() const {
85  if (this->path_.isEmpty()) {
86  return -1.0;
87  }
88  auto n = this->numPoints() - 1;
89  return (path_.getGeometry(n) - path_.getGeometry(n-1)).getAngleFromPoint();
90 }
91 
93  if (this->path_.isEmpty()) {
94  return {};
95  }
96  return this->path_.startPoint();
97 }
98 
100  if (this->path_.isEmpty()) {
101  return {};
102  }
103  return this->path_.endPoint();
104 }
105 
107  if (this->path_.isEmpty()) {
108  return Cells();
109  }
110  return Cells::buffer(this->path_, 0.5 * this->width_);
111 }
112 
113 Cells Swath::areaCovered(const Cells& polys) const {
114  return polys.getCellsInside(this->areaCovered());
115 }
116 
118  Swath new_s {this->path_.clone(), this->width_, this->id_};
119  new_s.setCreationDir(this->getCreationDir());
120  return new_s;
121 }
122 
123 bool Swath::hasSameDir(const Swath& s) const {
124  return s.getCreationDir() == this->getCreationDir();
125 }
126 
128  if (!this->hasSameDir(s)) {
129  this->reverse();
130  }
131 }
132 
134  if (this->hasSameDir(s)) {
135  this->reverse();
136  }
137 }
138 
139 size_t Swath::numPoints() const {
140  return this->path_->getNumPoints();
141 }
142 
144  return this->path_.getGeometry(i);
145 }
146 
147 const Point Swath::getPoint(int i) const {
148  return this->path_.getGeometry(i);
149 }
150 
151 int Swath::getId() const {
152  return this->id_;
153 }
154 
155 void Swath::setId(int _id) {
156  this->id_ = _id;
157 }
158 
160  return this->path_;
161 }
162 
163 void Swath::setPath(const LineString& _path) {
164  this->path_ = _path;
165 }
166 
167 double Swath::getWidth() const {
168  return this->width_;
169 }
170 
171 void Swath::setWidth(double _width) {
172  if (0 >= _width) {
173  throw std::invalid_argument("Width needs to be positive");
174  }
175  this->width_ = _width;
176 }
177 
178 bool Swath::getCreationDir() const {
179  return this->creation_dir_;
180 }
181 
182 void Swath::setCreationDir(bool _creation_dir) {
183  this->creation_dir_ = _creation_dir;
184 }
185 
187  return this->type_;
188 }
189 
191  this->type_ = _type;
192 }
193 
194 void Swath::moveTo(const Point& ref_pt) {
195  for (auto&& s : this->path_) {
196  s = s + ref_pt;
197  }
198 }
199 
200 } // namespace f2c::types
201 
f2c::types::Swath::hasSameDir
bool hasSameDir(const Swath &s) const
Check if the difference between swaths angles is less than pi.
Definition: Swath.cpp:123
f2c::types::Swath::getId
int getId() const
Definition: Swath.cpp:151
f2c::types::Geometries::area
double area() const
Compute area of the geometry.
Definition: Geometries_impl.hpp:14
f2c::types::Swath::clone
Swath clone() const
Definition: Swath.cpp:117
f2c::types::Swath::numPoints
size_t numPoints() const
Definition: Swath.cpp:139
f2c::types::Swath::creation_dir_
bool creation_dir_
Definition: Swath.h:101
f2c::types::Swath::operator=
virtual Swath & operator=(Swath &&)
f2c::types
Types used by fields2cover library.
Definition: Cell.h:20
f2c::types::Swath::path_
LineString path_
Definition: Swath.h:99
f2c::types::Swath::getInAngle
double getInAngle() const
Definition: Swath.cpp:77
f2c::types::LineString::getGeometry
void getGeometry(size_t i, Point &point)
Definition: LineString.cpp:54
f2c::types::Swath::operator<
bool operator<(const Swath &s) const
Definition: Swath.cpp:42
f2c::types::Swath::getWidth
double getWidth() const
Definition: Swath.cpp:167
f2c::types::Geometries::clone
SAMETYPE clone() const
Definition: Geometries_impl.hpp:19
f2c::types::Swath::~Swath
virtual ~Swath()
f2c::types::Swath
Definition: Swath.h:23
f2c::types::Swath::setPath
void setPath(const LineString &path)
Definition: Swath.cpp:163
f2c::types::Swath::targetOppositeDirAs
void targetOppositeDirAs(const Swath &s)
Definition: Swath.cpp:133
f2c::types::Swath::areaCovered
Cells areaCovered() const
Definition: Swath.cpp:106
f2c::types::Swath::reverse
void reverse()
Definition: Swath.cpp:72
f2c::types::Swath::setType
void setType(SwathType type)
Definition: Swath.cpp:190
f2c::types::Swath::getPath
LineString getPath() const
Definition: Swath.cpp:159
Swath.h
f2c::types::Swath::id_
int id_
Definition: Swath.h:98
f2c::types::Swath::setId
void setId(int id)
Definition: Swath.cpp:155
f2c::types::Swath::operator>
bool operator>(const Swath &s) const
Definition: Swath.cpp:46
f2c::types::Swath::moveTo
void moveTo(const Point &ref_pt)
Moves swath data by a reference point.
Definition: Swath.cpp:194
f2c::types::Swath::length
double length() const
Definition: Swath.cpp:60
f2c::types::Geometry::isEmpty
bool isEmpty() const
Definition: Geometry_impl.hpp:222
f2c::types::Swath::Swath
Swath()
f2c::types::Swath::targetSameDirAs
void targetSameDirAs(const Swath &s)
Definition: Swath.cpp:127
f2c::types::Swath::endPoint
Point endPoint() const
Definition: Swath.cpp:99
f2c::types::Swath::operator==
bool operator==(const Swath &s) const
Definition: Swath.cpp:38
f2c::types::LineString::startPoint
const Point startPoint() const
Definition: LineString.cpp:114
f2c::types::LineString
Definition: LineString.h:19
f2c::types::Swath::setWidth
void setWidth(double width)
Definition: Swath.cpp:171
f2c::types::Swath::getPoint
Point getPoint(int i)
Definition: Swath.cpp:143
f2c::types::Swath::startPoint
Point startPoint() const
Definition: Swath.cpp:92
f2c::types::Cells
Definition: Cells.h:21
f2c::types::Swath::getCreationDir
bool getCreationDir() const
Definition: Swath.cpp:178
f2c::types::Cells::getCellsInside
Cells getCellsInside(const Cells &cell) const
Definition: Cells.cpp:216
f2c::types::Point
Definition: Point.h:21
f2c::types::Swath::operator!=
bool operator!=(const Swath &s) const
Definition: Swath.cpp:28
f2c::types::Swath::width_
double width_
Definition: Swath.h:100
f2c::types::Swath::getType
SwathType getType() const
Definition: Swath.cpp:186
f2c::types::LineString::endPoint
const Point endPoint() const
Definition: LineString.cpp:118
f2c::types::Swath::setCreationDir
void setCreationDir(bool creation_dir)
Definition: Swath.cpp:182
f2c::types::SwathType
SwathType
Definition: Swath.h:21
f2c::types::Swath::area
double area() const
Definition: Swath.cpp:64
f2c::types::Swath::operator>=
bool operator>=(const Swath &s) const
Definition: Swath.cpp:50
f2c::types::Point::getY
double getY() const
Definition: Point.cpp:96
f2c::types::LineString::reversePoints
void reversePoints()
Definition: LineString.cpp:48
f2c::types::Swath::getOutAngle
double getOutAngle() const
Definition: Swath.cpp:84
f2c::types::Cells::buffer
static Cells buffer(const Geometry< T, R > &geom, double width, int side=0)
Definition: Cells.h:99
f2c::types::Point::getX
double getX() const
Definition: Point.cpp:95
f2c::types::Swath::operator<=
bool operator<=(const Swath &s) const
Definition: Swath.cpp:55
f2c::types::LineString::length
double length() const
Definition: LineString.cpp:47
f2c::types::Swath::type_
SwathType type_
Definition: Swath.h:102


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