diff --git a/corsika/detail/framework/geometry/Path.inl b/corsika/detail/framework/geometry/Path.inl index 3676d13577cd22d59d8c4299bf2129d4fb926cee..c8c05921fc9e9442ea3cb847d9dd67561bfa3f12 100644 --- a/corsika/detail/framework/geometry/Path.inl +++ b/corsika/detail/framework/geometry/Path.inl @@ -1,78 +1,59 @@ -/* - * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu - * - * 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 - * the license. - */ - -#pragma once - -#include <deque> -#include <corsika/framework/geometry/Point.hpp> - -namespace corsika { - - Path::Path(Point const& point) { - points_.push_front(point); - } - - Path::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(); - } - } - } - - inline void Path::AddToEnd(Point const& point) { - length_ += (point - points_.back()).getNorm(); - points_.push_back(point); - } - - inline void Path::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(); } - } - - inline LengthType Path::GetLength() const { - return length_; - } - - 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 +///* +// * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu +// * +// * 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 +// * the license. +// */ +// +//#pragma once +// +//#include <deque> +//#include <corsika/framework/geometry/Point.hpp> +// +//namespace corsika { +// +// inline void AddToEnd(Point const& point) { +// length_ += (point - points_.back()).getNorm(); +// points_.push_back(point); +// } +// +// +// 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(); } +// } +// +// +// inline LengthType GetLength() const { +// return length_; +// } +// +// +// inline Point GetStart() const { +// return points_.front(); +// } +// +// +// inline Point GetEnd() const { +// return points_.back(); +// } +// +// +// inline Point GetPoint(std::size_t const index) const { +// return points_.at(index); +// } +// +// +// +// inline int GetNSegments() const { return points_.size() - 1; } +// +//} // namespace corsika \ No newline at end of file diff --git a/corsika/framework/geometry/Path.hpp b/corsika/framework/geometry/Path.hpp index cb8d38a44397e572a9544b0b72db39fcbd7d153a..77b6966e535b8ba58661e8bd7e8973fd294540a1 100644 --- a/corsika/framework/geometry/Path.hpp +++ b/corsika/framework/geometry/Path.hpp @@ -24,62 +24,101 @@ namespace corsika { /** * 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. */ - 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. */ - inline void AddToEnd(Point const& point); + void AddToEnd(Point const& point) { + length_ += (point - points_.back()).getNorm(); + points_.push_back(point); + } /** * Remove a point from the end of the path. */ - inline void RemoveFromEnd(); + 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. */ - inline LengthType GetLength() const; + LengthType GetLength() const { + return length_; + } /** * Get the starting point of the path. */ - inline Point GetStart() const; + Point GetStart() const { + return points_.front(); + } /** * Get the end point of the path. */ - inline Point GetEnd() const; + Point GetEnd() const { + return points_.back(); + } /** * Get a specific point of the path. */ - inline Point GetPoint(std::size_t const index) const; + Point GetPoint(std::size_t const index) const { + return points_.at(index); + } /** * Return an iterator to the start of the Path. */ - inline auto begin(); + auto begin() { return points_.begin(); } /** * Return an iterator to the end of the Path. */ - inline auto end(); + auto end() { return points_.end(); } /** * Get the number of steps in the path. + * * This is one less than the number of points that * defines the path. */ - inline int GetNSegments() const; + int GetNSegments() const { return points_.size() - 1; } }; // class Path -} // namespace corsika - -#include <corsika/detail/framework/geometry/Path.inl> \ No newline at end of file +} // namespace corsika \ No newline at end of file