From 13fb9c6a44ea5225aacf405d7a89af107edc5729 Mon Sep 17 00:00:00 2001 From: Nikos Karastathis <n.karastathis@kit.edu> Date: Mon, 30 Jan 2023 09:58:12 +0100 Subject: [PATCH] Members of Path class are protected & some corrections --- corsika/detail/framework/geometry/Path.inl | 26 +++++++++++----------- corsika/framework/geometry/Path.hpp | 16 ++++++++++--- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/corsika/detail/framework/geometry/Path.inl b/corsika/detail/framework/geometry/Path.inl index b0078840b..4ba3d1ba8 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 03bc6a15f..b10a17b27 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 -- GitLab