Swaths.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 #include <algorithm>
9 
10 namespace f2c::types {
11 
12 Swaths::Swaths() = default;
13 Swaths::Swaths(int i) : data_(i) {}
14 
15 Swaths::Swaths(const std::initializer_list<Swath>& v_s) {
16  for (auto&& s : v_s) {
17  emplace_back(s);
18  }
19 }
20 
21 Swaths::Swaths(const std::vector<Swath>& v_s) {
22  for (auto&& s : v_s) {
23  emplace_back(s);
24  }
25 }
26 
27 Swaths::~Swaths() = default;
28 
29 void Swaths::emplace_back(const Swath& s) {
30  this->data_.emplace_back(s);
31 }
32 
34  const LineString& l, double w, int id, SwathType type) {
35  this->data_.emplace_back(l, w, id, type);
36 }
37 
38 void Swaths::push_back(const Swath& s) {
39  this->data_.push_back(s);
40 }
41 
42 std::vector<Swath>::iterator Swaths::begin() {
43  return this->data_.begin();
44 }
45 
46 std::vector<Swath>::iterator Swaths::end() {
47  return this->data_.end();
48 }
49 
50 std::vector<Swath>::const_iterator Swaths::begin() const {
51  return this->data_.begin();
52 }
53 
54 std::vector<Swath>::const_iterator Swaths::end() const {
55  return this->data_.end();
56 }
57 
59  std::reverse(this->data_.begin(), this->data_.end());
60 }
61 
63  return this->data_.back();
64 }
65 
66 const Swath& Swaths::back() const {
67  return this->data_.back();
68 }
69 
70 Swath& Swaths::at(size_t i) {
71  return this->data_.at(i);
72 }
73 
74 const Swath& Swaths::at(size_t i) const {
75  return this->data_.at(i);
76 }
77 
78 size_t Swaths::size() const {
79  return this->data_.size();
80 }
81 
83  return this->data_[i];
84 }
85 
86 const Swath& Swaths::operator[] (int i) const {
87  return this->data_[i];
88 }
89 
90 void Swaths::append(const LineString& line, double width, SwathType type) {
91  this->emplace_back(line, width, this->size(), type);
92 }
93 
95  const MultiLineString& lines, double width, SwathType type) {
96  for (auto&& line : lines) {
97  this->append(line.clone(), width, type);
98  }
99 }
100 
101 void Swaths::append(const LineString& line, const Cell& poly, double width,
102  SwathType type) {
103  this->append(poly.getLinesInside(line), width, type);
104 }
105 
106 void Swaths::append(const LineString& line, const Cells& polys,
107  double width, SwathType type) {
108  this->append(polys.getLinesInside(line), width, type);
109 }
110 
111 void Swaths::append(const MultiLineString& lines, const Cell& poly,
112  double width, SwathType type) {
113  this->append(poly.getLinesInside(lines), width, type);
114 }
115 
116 void Swaths::append(const MultiLineString& lines, const Cells& polys,
117  double width, SwathType type) {
118  this->append(polys.getLinesInside(lines), width, type);
119 }
120 
122  for (auto&& s : swaths) {
123  this->emplace_back(s);
124  }
125 }
126 
127 void Swaths::sort() {
128  for (auto&& s : this->data_) {
129  if (s.endPoint() < s.startPoint()) {
130  s.reverse();
131  }
132  }
133  std::sort(this->data_.begin(), this->data_.end());
134 }
135 
137  for (size_t i = 1; i < this->size(); ++i) {
138  this->data_[i].targetOppositeDirAs(this->data_[i - 1]);
139  }
140 }
141 
143  Swaths new_s;
144  for (auto&& s : this->data_) {
145  new_s.emplace_back(s.clone());
146  }
147  return new_s;
148 }
149 
150 void Swaths::moveTo(const Point& ref_pt) {
151  for (auto&& s : this->data_) {
152  s.moveTo(ref_pt);
153  }
154 }
155 
156 
157 } // namespace f2c::types
158 
f2c::types::Swaths::size
size_t size() const
Definition: Swaths.cpp:78
f2c::types::Swaths::emplace_back
void emplace_back(const Swath &s)
Definition: Swaths.cpp:29
f2c::types::Swaths::end
std::vector< Swath >::iterator end()
Definition: Swaths.cpp:46
5_route_planning.swaths
swaths
Definition: 5_route_planning.py:58
f2c::types::Swaths::reverse
void reverse()
Definition: Swaths.cpp:58
f2c::types
Types used by fields2cover library.
Definition: Cell.h:20
f2c::types::Swaths::~Swaths
~Swaths()
f2c::types::Swaths::reverseDirOddSwaths
void reverseDirOddSwaths()
Definition: Swaths.cpp:136
Swaths.h
f2c::types::Swaths::at
Swath & at(size_t i)
Definition: Swaths.cpp:70
f2c::types::Swath
Definition: Swath.h:23
f2c::types::Swaths::operator[]
Swath & operator[](int i)
Definition: Swaths.cpp:82
f2c::types::Cell::getLinesInside
MultiLineString getLinesInside(const LineString &line) const
Compute the sections of a LineString that is inside this cell.
Definition: Cell.cpp:176
f2c::types::MultiLineString
Definition: MultiLineString.h:18
f2c::types::Cell
Definition: Cell.h:32
f2c::types::Swaths::moveTo
void moveTo(const Point &ref_pt)
Definition: Swaths.cpp:150
f2c::types::Swaths::Swaths
Swaths()
2_objective_functions.width
float width
Definition: 2_objective_functions.py:29
f2c::types::LineString
Definition: LineString.h:19
f2c::types::Swaths::append
void append(const LineString &line, double width=0, SwathType type=SwathType::MAINLAND)
Definition: Swaths.cpp:90
f2c::types::Cells
Definition: Cells.h:21
f2c::types::Swaths::back
Swath & back()
Definition: Swaths.cpp:62
f2c::types::Point
Definition: Point.h:21
f2c::types::Swaths::clone
Swaths clone() const
Definition: Swaths.cpp:142
f2c::types::Swaths::sort
void sort()
Definition: Swaths.cpp:127
f2c::types::Cells::getLinesInside
MultiLineString getLinesInside(const LineString &line) const
Definition: Cells.cpp:208
f2c::types::SwathType
SwathType
Definition: Swath.h:21
f2c::types::Swaths::begin
std::vector< Swath >::iterator begin()
Definition: Swaths.cpp:42
f2c::types::Swaths::data_
std::vector< Swath > data_
Definition: Swaths.h:73
1_basic_types.lines
lines
Definition: 1_basic_types.py:73
f2c::types::Swaths
Definition: Swaths.h:20
f2c::types::Swaths::push_back
void push_back(const Swath &s)
Definition: Swaths.cpp:38


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