From 949fabf4605ae69cbec402cb9388807de493dcf3 Mon Sep 17 00:00:00 2001 From: Nikos Karastathis <n.karastathis@kit.edu> Date: Mon, 25 Jan 2021 17:35:37 +0100 Subject: [PATCH] Path class header and inline file in correct format --- corsika/detail/framework/geometry/Path.inl | 137 ++++++++++++--------- corsika/framework/geometry/Path.hpp | 67 +++------- 2 files changed, 92 insertions(+), 112 deletions(-) diff --git a/corsika/detail/framework/geometry/Path.inl b/corsika/detail/framework/geometry/Path.inl index c8c05921f..3676d1357 100644 --- a/corsika/detail/framework/geometry/Path.inl +++ b/corsika/detail/framework/geometry/Path.inl @@ -1,59 +1,78 @@ -///* -// * (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 +/* + * (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 diff --git a/corsika/framework/geometry/Path.hpp b/corsika/framework/geometry/Path.hpp index 77b6966e5..cb8d38a44 100644 --- a/corsika/framework/geometry/Path.hpp +++ b/corsika/framework/geometry/Path.hpp @@ -24,101 +24,62 @@ namespace corsika { /** * Create a Path with a given starting Point. */ - Path(Point const& point) { - points_.push_front(point); - } + Path(Point const& point); /** * Initialize a Path from an existing collection of 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(); - } - } - } + Path(std::deque<Point> const& points); /** * Add a new Point to the end of the path. */ - void AddToEnd(Point const& point) { - length_ += (point - points_.back()).getNorm(); - points_.push_back(point); - } + inline void AddToEnd(Point const& point); /** * Remove a point from the end of the path. */ - 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 void RemoveFromEnd(); /** * Get the total length of the path. */ - LengthType GetLength() const { - return length_; - } + inline LengthType GetLength() const; /** * Get the starting point of the path. */ - Point GetStart() const { - return points_.front(); - } + inline Point GetStart() const; /** * Get the end point of the path. */ - Point GetEnd() const { - return points_.back(); - } + inline Point GetEnd() const; /** * Get a specific point of the path. */ - Point GetPoint(std::size_t const index) const { - return points_.at(index); - } + inline Point GetPoint(std::size_t const index) const; /** * Return an iterator to the start of the Path. */ - auto begin() { return points_.begin(); } + inline auto begin(); /** * Return an iterator to the end of the Path. */ - auto end() { return points_.end(); } + inline auto end(); /** * Get the number of steps in the path. - * * This is one less than the number of points that * defines the path. */ - int GetNSegments() const { return points_.size() - 1; } + inline int GetNSegments() const; }; // class Path -} // namespace corsika \ No newline at end of file +} // namespace corsika + +#include <corsika/detail/framework/geometry/Path.inl> \ No newline at end of file -- GitLab