diff --git a/corsika/detail/framework/geometry/Path.inl b/corsika/detail/framework/geometry/Path.inl index c367531883c0bce37a488fb2901c6cc13c0bad09..b0078840bc8f41ed9ea3db6c0cf30ded22db8e9a 100644 --- a/corsika/detail/framework/geometry/Path.inl +++ b/corsika/detail/framework/geometry/Path.inl @@ -9,7 +9,9 @@ #pragma once #include <deque> + #include <corsika/framework/geometry/Point.hpp> +#include <corsika/framework/core/PhysicalUnits.hpp> namespace corsika { @@ -37,30 +39,36 @@ namespace corsika { } inline void Path::removeFromEnd() { - auto lastpoint_ = points_.back(); - points_.pop_back(); - int dequesize_ = points_.size(); - if (dequesize_ == 0 || dequesize_ == 1) { + int const dequesize = points_.size(); + if (dequesize == 0) { length_ = LengthType::zero(); - } else if (dequesize_ == 2) { - length_ = (points_.back() - points_.front()).getNorm(); - } else { - length_ -= (lastpoint_ - points_.back()).getNorm(); + return; } + if (dequesize == 1) { + length_ = LengthType::zero(); + return; + } + + length_ -= distance(points_.back(), points_[dequesize - 2]); + points_.pop_back(); } inline LengthType Path::getLength() const { return length_; } - inline Point Path::getStart() const { return points_.front(); } + inline Point const& Path::getStart() const { return points_.front(); } - inline Point Path::getEnd() const { return points_.back(); } + inline Point const& Path::getEnd() const { return points_.back(); } - inline Point Path::getPoint(std::size_t const index) const { return points_.at(index); } + inline Point const& Path::getPoint(std::size_t const index) const { + return points_.at(index); + } - inline auto Path::begin() { return points_.begin(); } + inline Path::iterator Path::begin() { return points_.begin(); } + inline Path::const_iterator Path::begin() const { return points_.cbegin(); } - inline auto Path::end() { return points_.end(); } + inline Path::iterator Path::end() { return points_.end(); } + inline Path::const_iterator Path::end() const { return points_.cend(); } inline int Path::getNSegments() const { return points_.size() - 1; } -} // namespace corsika \ No newline at end of file +} // namespace corsika diff --git a/corsika/framework/geometry/Path.hpp b/corsika/framework/geometry/Path.hpp index 620cbeeab2210141e8a51f423e9422688313e4d2..03bc6a15f3fa20e6ea78f5543d3ea1cc86276f98 100644 --- a/corsika/framework/geometry/Path.hpp +++ b/corsika/framework/geometry/Path.hpp @@ -9,6 +9,8 @@ #pragma once #include <deque> + +#include <corsika/framework/core/PhysicalUnits.hpp> #include <corsika/framework/geometry/Point.hpp> namespace corsika { @@ -20,6 +22,10 @@ namespace corsika { class Path { std::deque<Point> points_; ///< The points that make up this path. LengthType length_ = LengthType::zero(); ///< The length of the path. + + using iterator = std::deque<Point>::iterator; + using const_iterator = std::deque<Point>::const_iterator; + public: /** * Create a Path with a given starting Point. @@ -49,27 +55,29 @@ namespace corsika { /** * Get the starting point of the path. */ - inline Point getStart() const; + inline Point const& getStart() const; /** * Get the end point of the path. */ - inline Point getEnd() const; + inline Point const& getEnd() const; /** * Get a specific point of the path. */ - inline Point getPoint(std::size_t const index) const; + inline Point const& getPoint(std::size_t index) const; /** * Return an iterator to the start of the Path. */ - inline auto begin(); + inline const_iterator begin() const; + inline iterator begin(); /** * Return an iterator to the end of the Path. */ - inline auto end(); + inline const_iterator end() const; + inline iterator end(); /** * Get the number of steps in the path. @@ -82,4 +90,4 @@ namespace corsika { } // namespace corsika -#include <corsika/detail/framework/geometry/Path.inl> \ No newline at end of file +#include <corsika/detail/framework/geometry/Path.inl>