IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 6cd70b66 authored by Maximilian Reininghaus's avatar Maximilian Reininghaus :vulcan:
Browse files

const-correctness of Path

parent 03502fe8
No related branches found
No related tags found
1 merge request!464Fix radio test
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
#pragma once #pragma once
#include <deque> #include <deque>
#include <corsika/framework/geometry/Point.hpp> #include <corsika/framework/geometry/Point.hpp>
#include <corsika/framework/core/PhysicalUnits.hpp>
namespace corsika { namespace corsika {
...@@ -37,30 +39,36 @@ namespace corsika { ...@@ -37,30 +39,36 @@ namespace corsika {
} }
inline void Path::removeFromEnd() { inline void Path::removeFromEnd() {
auto lastpoint_ = points_.back(); int const dequesize = points_.size();
points_.pop_back(); if (dequesize == 0) {
int dequesize_ = points_.size();
if (dequesize_ == 0 || dequesize_ == 1) {
length_ = LengthType::zero(); length_ = LengthType::zero();
} else if (dequesize_ == 2) { return;
length_ = (points_.back() - points_.front()).getNorm();
} else {
length_ -= (lastpoint_ - points_.back()).getNorm();
} }
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 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; } inline int Path::getNSegments() const { return points_.size() - 1; }
} // namespace corsika } // namespace corsika
\ No newline at end of file
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#pragma once #pragma once
#include <deque> #include <deque>
#include <corsika/framework/core/PhysicalUnits.hpp>
#include <corsika/framework/geometry/Point.hpp> #include <corsika/framework/geometry/Point.hpp>
namespace corsika { namespace corsika {
...@@ -20,6 +22,10 @@ namespace corsika { ...@@ -20,6 +22,10 @@ namespace corsika {
class Path { class Path {
std::deque<Point> points_; ///< The points that make up this path. std::deque<Point> points_; ///< The points that make up this path.
LengthType length_ = LengthType::zero(); ///< The length of the 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: public:
/** /**
* Create a Path with a given starting Point. * Create a Path with a given starting Point.
...@@ -49,27 +55,29 @@ namespace corsika { ...@@ -49,27 +55,29 @@ namespace corsika {
/** /**
* Get the starting point of the path. * Get the starting point of the path.
*/ */
inline Point getStart() const; inline Point const& getStart() const;
/** /**
* Get the end point of the path. * Get the end point of the path.
*/ */
inline Point getEnd() const; inline Point const& getEnd() const;
/** /**
* Get a specific point of the path. * 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. * 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. * 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. * Get the number of steps in the path.
...@@ -82,4 +90,4 @@ namespace corsika { ...@@ -82,4 +90,4 @@ namespace corsika {
} // namespace corsika } // namespace corsika
#include <corsika/detail/framework/geometry/Path.inl> #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