IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 949fabf4 authored by Nikos Karastathis's avatar Nikos Karastathis :ocean:
Browse files

Path class header and inline file in correct format

parent 04d9d4c5
No related branches found
No related tags found
1 merge request!313Resolve "Geometry and environment feature updates - merge to refactored version"
///*
// * (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
......@@ -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
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