8 #include <steering_functions/utilities/utilities.hpp>
55 return std::accumulate(this->
begin(), this->
end(), 0.0,
63 std::vector<PathState>::const_iterator
Path::cend()
const {
71 std::vector<PathState>::const_iterator
Path::end()
const {
79 std::vector<PathState>::iterator
Path::end() {
100 for (
auto&& new_state :
path) {
101 this->
states_.emplace_back(new_state);
111 return std::min_element(this->
begin(), this->
end(),
118 return std::min_element(this->
begin(), this->
end(),
125 return std::max_element(this->
begin(), this->
end(),
132 return std::max_element(this->
begin(), this->
end(),
139 for (
auto&& s : this->
states_) {
140 s.point = s.point + p;
145 for (
auto&& s : this->
states_) {
147 s.angle = s.point.
mod_2pi(s.angle + ang);
152 for (
auto&& s : this->
states_) {
153 s.point.setX(-s.point.getX());
154 s.angle = s.point.mod_2pi(M_PI - s.angle);
158 for (
auto&& s : this->
states_) {
159 s.point.setY(-s.point.getY());
160 s.angle = s.point.mod_2pi(-s.angle);
165 for (
size_t i = 0; i < this->
size(); ++i) {
175 for (
size_t i = 0; i < this->
size(); ++i) {
185 for (
size_t i = 0; i < this->
size(); ++i) {
195 for (
size_t i = 0; i < this->
size(); ++i) {
207 [](
double d,
const PathState& s) {return d + fabs(s.len);});
211 for (
size_t i = 0; i < swath.
numPoints() - 1; ++i) {
216 s.
angle = p_ang.getAngleFromPoint();
226 double total_length = this->
length();
227 if (len > total_length) {
228 return this->
at(total_length);
229 }
else if (len < 0.0) {
230 return this->
at(0.0);
234 for (
size_t i = 0; i < this->
size(); ++i) {
235 double len_state = fabs(
states_[i].len);
236 if (len_state < len) {
243 len *=
static_cast<double>(
states_[i].dir);
245 p.
getY() + len * sin(ang));
260 template<
typename CharT>
274 std::string
to_string(
double d,
const int precision = 6) {
275 std::stringstream ss;
276 ss.precision(precision);
284 std::locale::global(std::locale::classic());
285 std::string res =
"";
287 for (
size_t i = 0; i <
size(); ++i) {
307 for (
auto&& s : this->
states_) {
309 double n_steps = max(1.0, std::round(fabs(s.len / step_size)));
310 Point start2end = s.atEnd() - s.point;
311 for (
double j = 0.0; j < n_steps; j += 1.0) {
313 state.
point = s.point + start2end * (j / n_steps);
314 state.
len /= n_steps;
325 std::ofstream out(file);
331 std::ifstream in(file);
332 double x, y, z, ang, vel, len, dir, d_type;
333 while (in >> x >> y >> z >> ang >> vel >> len >> dir >> d_type) {
347 if (this->
size() < 3) {
return *
this;}
349 std::vector<double> x, y, ang_prov, old_vel, len;
350 std::vector<PathDirection> old_dir;
351 std::vector<PathSectionType> old_type;
352 for (
int i = 0; i < this->
size(); ++i) {
353 if (this->
states_[i].len != 0.0) {
354 x.emplace_back(this->
states_[i].point.getX());
355 y.emplace_back(this->
states_[i].point.getY());
356 ang_prov.emplace_back(this->
states_[i].angle);
357 len.emplace_back(this->
states_[i].len);
358 old_vel.emplace_back(this->
states_[i].velocity);
359 old_dir.emplace_back(this->
states_[i].dir);
360 old_type.emplace_back(this->
states_[i].type);
363 x.emplace_back(this->
states_.back().atEnd().getX());
364 y.emplace_back(this->
states_.back().atEnd().getY());
365 ang_prov.emplace_back(this->
states_.back().angle);
366 len.emplace_back(0.0);
367 old_vel.emplace_back(this->
states_.back().velocity);
368 old_dir.emplace_back(this->
states_.back().dir);
369 old_type.emplace_back(this->
states_.back().type);
372 std::vector<double> t(len.size());
373 std::partial_sum(len.begin(), len.end() - 1, t.begin() + 1);
381 double step = t.back() /
static_cast<double>(number_points);
383 for (
size_t i = 0; i < number_points; ++i) {
388 int it = std::lower_bound(t.begin(), t.end(), d + 1e-10) - t.begin() - 1;
390 state.
dir = old_dir[it];
391 state.
type = old_type[it];
398 size_t N = this->
size();
400 for (
size_t i = 0; i < N;) {
401 double new_len {this->
states_[i].len};
406 this->
states_[i].point.distance(
407 this->states_[j].point) < min_dist_equal) {
408 new_len += this->
states_[j].len;
418 new_path.
states_.emplace_back(state);
427 for (
auto&& s : this->
states_) {
435 if (this->
size() > 1) {
436 int n =
static_cast<int>((10.0 / step_size) * this->
length());