diff --git a/corsika/detail/framework/geometry/Path.inl b/corsika/detail/framework/geometry/Path.inl index b0078840bc8f41ed9ea3db6c0cf30ded22db8e9a..4ba3d1ba823273128e47aed7fcdb443bf26b4919 100644 --- a/corsika/detail/framework/geometry/Path.inl +++ b/corsika/detail/framework/geometry/Path.inl @@ -39,18 +39,16 @@ namespace corsika { } inline void Path::removeFromEnd() { - int const dequesize = points_.size(); - if (dequesize == 0) { - length_ = LengthType::zero(); - return; - } - if (dequesize == 1) { + auto lastpoint_ = points_.back(); + points_.pop_back(); + int dequesize_ = points_.size(); + if (dequesize_ == 0 || dequesize_ == 1) { length_ = LengthType::zero(); - return; + } else if (dequesize_ == 2) { + length_ = (points_.back() - points_.front()).getNorm(); + } else { + length_ -= (lastpoint_ - points_.back()).getNorm(); } - - length_ -= distance(points_.back(), points_[dequesize - 2]); - points_.pop_back(); } inline LengthType Path::getLength() const { return length_; } @@ -63,12 +61,14 @@ namespace corsika { return points_.at(index); } - inline Path::iterator Path::begin() { return points_.begin(); } inline Path::const_iterator Path::begin() const { return points_.cbegin(); } - inline Path::iterator Path::end() { return points_.end(); } inline Path::const_iterator Path::end() const { return points_.cend(); } + inline Path::iterator Path::begin() { return points_.begin(); } + + inline Path::iterator Path::end() { return points_.end(); } + inline int Path::getNSegments() const { return points_.size() - 1; } -} // namespace corsika +} // namespace corsika \ No newline at end of file diff --git a/corsika/framework/geometry/Path.hpp b/corsika/framework/geometry/Path.hpp index 03bc6a15f3fa20e6ea78f5543d3ea1cc86276f98..b10a17b27ce8d22296eeb5cd94e613b80fcb325f 100644 --- a/corsika/framework/geometry/Path.hpp +++ b/corsika/framework/geometry/Path.hpp @@ -20,6 +20,8 @@ namespace corsika { * points using N >= 1 straight-line segments. */ class Path { + + protected: std::deque<Point> points_; ///< The points that make up this path. LengthType length_ = LengthType::zero(); ///< The length of the path. @@ -65,18 +67,26 @@ namespace corsika { /** * Get a specific point of the path. */ - inline Point const& getPoint(std::size_t index) const; + inline Point const& getPoint(std::size_t const index) const; /** * Return an iterator to the start of the Path. */ inline const_iterator begin() const; - inline iterator begin(); /** * Return an iterator to the end of the Path. */ inline const_iterator end() const; + + /** + * Return an iterator to the start of the Path. + */ + inline iterator begin(); + + /** + * Return an iterator to the end of the Path. + */ inline iterator end(); /** @@ -90,4 +100,4 @@ namespace corsika { } // namespace corsika -#include <corsika/detail/framework/geometry/Path.inl> +#include <corsika/detail/framework/geometry/Path.inl> \ No newline at end of file