IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 949fabf4 authored by Nikos Karastathis's avatar Nikos Karastathis :ocean:
Browse files

Path class header and inline file in correct format

parent 04d9d4c5
No related branches found
No related tags found
1 merge request!313Resolve "Geometry and environment feature updates - merge to refactored version"
///* /*
// * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
// * *
// * This software is distributed under the terms of the GNU General Public * This software is distributed under the terms of the GNU General Public
// * Licence version 3 (GPL Version 3). See file LICENSE for a full version of * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
// * the license. * the license.
// */ */
//
//#pragma once #pragma once
//
//#include <deque> #include <deque>
//#include <corsika/framework/geometry/Point.hpp> #include <corsika/framework/geometry/Point.hpp>
//
//namespace corsika { namespace corsika {
//
// inline void AddToEnd(Point const& point) { Path::Path(Point const& point) {
// length_ += (point - points_.back()).getNorm(); points_.push_front(point);
// points_.push_back(point); }
// }
// Path::Path(std::deque<Point> const& points)
// : points_(points) {
// inline void RemoveFromEnd() { int dequesize_ = points.size();
// auto lastpoint_ = points_.back(); if (dequesize_ == 0 || dequesize_ == 1) {
// points_.pop_back(); length_ = LengthType::zero();
// int dequesize_ = points_.size(); }
// if (dequesize_ == 0 || dequesize_ == 1) { else if (dequesize_ == 2) {
// length_ = LengthType::zero(); length_ = (points.back() - points.front()).getNorm();
// } }
// else if (dequesize_ == 2) { else {
// length_ = (points_.back() - points_.front()).getNorm(); for (auto point = points.begin(); point != points.end() - 1; ++point) {
// } auto point_next = *(point+1);
// else { length_ -= (lastpoint_ - points_.back()).getNorm(); } auto point_now = *(point);
// } length_ += (point_next - point_now).getNorm();
// }
// }
// inline LengthType GetLength() const { }
// return length_;
// } inline void Path::AddToEnd(Point const& point) {
// length_ += (point - points_.back()).getNorm();
// points_.push_back(point);
// inline Point GetStart() const { }
// return points_.front();
// } inline void Path::RemoveFromEnd() {
// auto lastpoint_ = points_.back();
// points_.pop_back();
// inline Point GetEnd() const { int dequesize_ = points_.size();
// return points_.back(); if (dequesize_ == 0 || dequesize_ == 1) {
// } length_ = LengthType::zero();
// }
// else if (dequesize_ == 2) {
// inline Point GetPoint(std::size_t const index) const { length_ = (points_.back() - points_.front()).getNorm();
// return points_.at(index); }
// } else { length_ -= (lastpoint_ - points_.back()).getNorm(); }
// }
//
// inline LengthType Path::GetLength() const {
// inline int GetNSegments() const { return points_.size() - 1; } return length_;
// }
//} // namespace corsika
\ No newline at end of file inline Point Path::GetStart() const {
return points_.front();
}
inline Point Path::GetEnd() const {
return points_.back();
}
inline Point Path::GetPoint(std::size_t const index) const {
return points_.at(index);
}
inline auto Path::begin() { return points_.begin(); }
inline auto Path::end() { return points_.end(); }
inline int Path::GetNSegments() const { return points_.size() - 1; }
} // namespace corsika
\ No newline at end of file
...@@ -24,101 +24,62 @@ namespace corsika { ...@@ -24,101 +24,62 @@ namespace corsika {
/** /**
* Create a Path with a given starting Point. * Create a Path with a given starting Point.
*/ */
Path(Point const& point) { Path(Point const& point);
points_.push_front(point);
}
/** /**
* Initialize a Path from an existing collection of Points. * Initialize a Path from an existing collection of Points.
*/ */
Path(std::deque<Point> const& points) Path(std::deque<Point> const& points);
: points_(points) {
int dequesize_ = points.size();
if (dequesize_ == 0 || dequesize_ == 1) {
length_ = LengthType::zero();
}
else if (dequesize_ == 2) {
length_ = (points.back() - points.front()).getNorm();
}
else {
for (auto point = points.begin(); point != points.end() - 1; ++point) {
auto point_next = *(point+1);
auto point_now = *(point);
length_ += (point_next - point_now).getNorm();
}
}
}
/** /**
* Add a new Point to the end of the path. * Add a new Point to the end of the path.
*/ */
void AddToEnd(Point const& point) { inline void AddToEnd(Point const& point);
length_ += (point - points_.back()).getNorm();
points_.push_back(point);
}
/** /**
* Remove a point from the end of the path. * Remove a point from the end of the path.
*/ */
void RemoveFromEnd() { inline void RemoveFromEnd();
auto lastpoint_ = points_.back();
points_.pop_back();
int dequesize_ = points_.size();
if (dequesize_ == 0 || dequesize_ == 1) {
length_ = LengthType::zero();
}
else if (dequesize_ == 2) {
length_ = (points_.back() - points_.front()).getNorm();
}
else { length_ -= (lastpoint_ - points_.back()).getNorm(); }
}
/** /**
* Get the total length of the path. * Get the total length of the path.
*/ */
LengthType GetLength() const { inline LengthType GetLength() const;
return length_;
}
/** /**
* Get the starting point of the path. * Get the starting point of the path.
*/ */
Point GetStart() const { inline Point GetStart() const;
return points_.front();
}
/** /**
* Get the end point of the path. * Get the end point of the path.
*/ */
Point GetEnd() const { inline Point GetEnd() const;
return points_.back();
}
/** /**
* Get a specific point of the path. * Get a specific point of the path.
*/ */
Point GetPoint(std::size_t const index) const { inline Point GetPoint(std::size_t const index) const;
return points_.at(index);
}
/** /**
* Return an iterator to the start of the Path. * Return an iterator to the start of the Path.
*/ */
auto begin() { return points_.begin(); } inline auto begin();
/** /**
* Return an iterator to the end of the Path. * Return an iterator to the end of the Path.
*/ */
auto end() { return points_.end(); } inline auto end();
/** /**
* Get the number of steps in the path. * Get the number of steps in the path.
*
* This is one less than the number of points that * This is one less than the number of points that
* defines the path. * defines the path.
*/ */
int GetNSegments() const { return points_.size() - 1; } inline int GetNSegments() const;
}; // class Path }; // class Path
} // namespace corsika } // namespace corsika
\ No newline at end of file
#include <corsika/detail/framework/geometry/Path.inl>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment