IAP GITLAB

Skip to content
Snippets Groups Projects
Commit d75101db authored by Nikos Karastathis's avatar Nikos Karastathis :ocean: Committed by Maximilian Reininghaus
Browse files

clang-format on

(cherry picked from commit 64e63aa0)
parent c1b7e8ce
No related branches found
No related tags found
No related merge requests found
...@@ -13,26 +13,22 @@ ...@@ -13,26 +13,22 @@
namespace corsika { namespace corsika {
Path::Path(Point const& point) { Path::Path(Point const& point) { points_.push_front(point); }
points_.push_front(point);
}
Path::Path(std::deque<Point> const& points) Path::Path(std::deque<Point> const& points)
: points_(points) { : points_(points) {
int dequesize_ = points.size(); int dequesize_ = points.size();
if (dequesize_ == 0 || dequesize_ == 1) { if (dequesize_ == 0 || dequesize_ == 1) {
length_ = LengthType::zero(); length_ = LengthType::zero();
} } else if (dequesize_ == 2) {
else if (dequesize_ == 2) { length_ = (points.back() - points.front()).getNorm();
length_ = (points.back() - points.front()).getNorm(); } else {
} for (auto point = points.begin(); point != points.end() - 1; ++point) {
else { auto point_next = *(point + 1);
for (auto point = points.begin(); point != points.end() - 1; ++point) { auto point_now = *(point);
auto point_next = *(point+1); length_ += (point_next - point_now).getNorm();
auto point_now = *(point);
length_ += (point_next - point_now).getNorm();
}
} }
}
} }
inline void Path::AddToEnd(Point const& point) { inline void Path::AddToEnd(Point const& point) {
...@@ -46,28 +42,20 @@ namespace corsika { ...@@ -46,28 +42,20 @@ namespace corsika {
int dequesize_ = points_.size(); int dequesize_ = points_.size();
if (dequesize_ == 0 || dequesize_ == 1) { if (dequesize_ == 0 || dequesize_ == 1) {
length_ = LengthType::zero(); length_ = LengthType::zero();
} } else if (dequesize_ == 2) {
else if (dequesize_ == 2) {
length_ = (points_.back() - points_.front()).getNorm(); length_ = (points_.back() - points_.front()).getNorm();
} else {
length_ -= (lastpoint_ - points_.back()).getNorm();
} }
else { length_ -= (lastpoint_ - points_.back()).getNorm(); }
} }
inline LengthType Path::GetLength() const { inline LengthType Path::GetLength() const { return length_; }
return length_;
}
inline Point Path::GetStart() const { inline Point Path::GetStart() const { return points_.front(); }
return points_.front();
}
inline Point Path::GetEnd() const { inline Point Path::GetEnd() const { return points_.back(); }
return points_.back();
}
inline Point Path::GetPoint(std::size_t const index) const { inline Point Path::GetPoint(std::size_t const index) const { return points_.at(index); }
return points_.at(index);
}
inline auto Path::begin() { return points_.begin(); } inline auto Path::begin() { return points_.begin(); }
......
...@@ -15,17 +15,17 @@ namespace corsika { ...@@ -15,17 +15,17 @@ namespace corsika {
template <typename T> template <typename T>
template <typename... Args> template <typename... Args>
ExponentialRefractiveIndex<T>::ExponentialRefractiveIndex(double const n0, ExponentialRefractiveIndex<T>::ExponentialRefractiveIndex(
InverseLengthType const lambda, Args&&... args) double const n0, InverseLengthType const lambda, Args&&... args)
: T(std::forward<Args>(args)...) : T(std::forward<Args>(args)...)
, n_0(n0) , n_0(n0)
, lambda_(lambda) {} , lambda_(lambda) {}
template <typename T> template <typename T>
double ExponentialRefractiveIndex<T>::getRefractiveIndex(Point const& point) const { double ExponentialRefractiveIndex<T>::getRefractiveIndex(Point const& point) const {
//TODO: THIS METHOD CURRENTLY ONLY USES THE Z-COORDINATE. // TODO: THIS METHOD CURRENTLY ONLY USES THE Z-COORDINATE.
//NEED TO THINK IT FOR FUTURE WORK ON ARBITRARY GEOMETRIES. // NEED TO THINK IT FOR FUTURE WORK ON ARBITRARY GEOMETRIES.
return n_0 * exp((-lambda_) * point.getCoordinates().getZ()); return n_0 * exp((-lambda_) * point.getCoordinates().getZ());
} }
} // namespace corsika } // namespace corsika
...@@ -18,8 +18,8 @@ namespace corsika { ...@@ -18,8 +18,8 @@ namespace corsika {
* points using N >= 1 straight-line segments. * points using N >= 1 straight-line segments.
*/ */
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.
public: public:
/** /**
* Create a Path with a given starting Point. * Create a Path with a given starting Point.
...@@ -78,7 +78,7 @@ namespace corsika { ...@@ -78,7 +78,7 @@ namespace corsika {
*/ */
inline int GetNSegments() const; inline int GetNSegments() const;
}; // class Path }; // class Path
} // namespace corsika } // namespace corsika
......
...@@ -23,7 +23,7 @@ namespace corsika { ...@@ -23,7 +23,7 @@ namespace corsika {
template <typename T> template <typename T>
class ExponentialRefractiveIndex : public T { class ExponentialRefractiveIndex : public T {
double n_0; ///< n0 constant. double n_0; ///< n0 constant.
InverseLengthType lambda_; ///< lambda parameter. InverseLengthType lambda_; ///< lambda parameter.
public: public:
...@@ -37,8 +37,8 @@ namespace corsika { ...@@ -37,8 +37,8 @@ namespace corsika {
* @param field The refractive index to return to a given point. * @param field The refractive index to return to a given point.
*/ */
template <typename... Args> template <typename... Args>
ExponentialRefractiveIndex(double const n0, ExponentialRefractiveIndex(double const n0, InverseLengthType const lambda,
InverseLengthType const lambda, Args&&... args); Args&&... args);
/** /**
* Evaluate the refractive index at a given location. * Evaluate the refractive index at a given location.
......
...@@ -316,12 +316,11 @@ TEST_CASE("Geometry Trajectories") { ...@@ -316,12 +316,11 @@ TEST_CASE("Geometry Trajectories") {
} }
} }
TEST_CASE("Point") { TEST_CASE("Point") {
//define a known CS // define a known CS
CoordinateSystemPtr root = get_root_CoordinateSystem(); CoordinateSystemPtr root = get_root_CoordinateSystem();
//define known points // define known points
Point p1(root, {0_m, 0_m, 0_m}); Point p1(root, {0_m, 0_m, 0_m});
Point p2(root, {0_m, 0_m, 5_m}); Point p2(root, {0_m, 0_m, 5_m});
Point p3(root, {1_m, 0_m, 0_m}); Point p3(root, {1_m, 0_m, 0_m});
...@@ -330,68 +329,65 @@ TEST_CASE("Point") { ...@@ -330,68 +329,65 @@ TEST_CASE("Point") {
Point p6(root, {0_m, 5_m, 0_m}); Point p6(root, {0_m, 5_m, 0_m});
SECTION("Test distance_to() method") SECTION("Test distance_to() method")
//check distance_to() method // check distance_to() method
CHECK(p1.distance_to(p2) / 1_m == Approx(5)); CHECK(p1.distance_to(p2) / 1_m == Approx(5));
CHECK(p3.distance_to(p4) / 1_m == Approx(4)); CHECK(p3.distance_to(p4) / 1_m == Approx(4));
CHECK(p5.distance_to(p6) / 1_m == Approx(1)); CHECK(p5.distance_to(p6) / 1_m == Approx(1));
} }
TEST_CASE("Path") { TEST_CASE("Path") {
//define a known CS // define a known CS
CoordinateSystemPtr root = get_root_CoordinateSystem(); CoordinateSystemPtr root = get_root_CoordinateSystem();
//define known points // define known points
Point p1(root, {0_m, 0_m, 0_m}); Point p1(root, {0_m, 0_m, 0_m});
Point p2(root, {0_m, 0_m, 1_m}); Point p2(root, {0_m, 0_m, 1_m});
Point p3(root, {0_m, 0_m, 2_m}); Point p3(root, {0_m, 0_m, 2_m});
Point p4(root, {0_m, 0_m, 3_m}); Point p4(root, {0_m, 0_m, 3_m});
Point p5(root, {0_m, 0_m, 4_m}); Point p5(root, {0_m, 0_m, 4_m});
//define paths // define paths
Path P1(p1); Path P1(p1);
Path P2({p1,p2}); Path P2({p1, p2});
Path P3({p1, p2, p3}); Path P3({p1, p2, p3});
//define deque that include point(s) // define deque that include point(s)
std::deque<Point> l1 = {p1}; std::deque<Point> l1 = {p1};
std::deque<Point> l2 = {p1, p2}; std::deque<Point> l2 = {p1, p2};
std::deque<Point> l3 = {p1, p2, p3}; std::deque<Point> l3 = {p1, p2, p3};
//test the various path constructors // test the various path constructors
SECTION("Test Constructors") { SECTION("Test Constructors") {
//check constructor for one point // check constructor for one point
CHECK(std::equal(P1.begin(), P1.end(), l1.begin(),[](Point a, Point b) CHECK(std::equal(P1.begin(), P1.end(), l1.begin(),
{ return (a - b).getNorm() / 1_m < 1e-5;})); [](Point a, Point b) { return (a - b).getNorm() / 1_m < 1e-5; }));
//check constructor for collection of points // check constructor for collection of points
CHECK(std::equal(P3.begin(), P3.end(), l3.begin(),[](Point a, Point b) CHECK(std::equal(P3.begin(), P3.end(), l3.begin(),
{ return (a - b).getNorm() / 1_m < 1e-5;})); [](Point a, Point b) { return (a - b).getNorm() / 1_m < 1e-5; }));
} }
//test the length and access methods // test the length and access methods
SECTION("Test GetLength() and modifications to Path") { SECTION("Test GetLength() and modifications to Path") {
P1.AddToEnd(p2); P1.AddToEnd(p2);
P2.RemoveFromEnd(); P2.RemoveFromEnd();
//Check modifications to path // Check modifications to path
CHECK(std::equal(P1.begin(), P1.end(), l2.begin(),[](Point a, Point b) CHECK(std::equal(P1.begin(), P1.end(), l2.begin(),
{ return (a - b).getNorm() / 1_m < 1e-5;})); [](Point a, Point b) { return (a - b).getNorm() / 1_m < 1e-5; }));
CHECK(std::equal(P2.begin(), P2.end(), l1.begin(),[](Point a, Point b) CHECK(std::equal(P2.begin(), P2.end(), l1.begin(),
{ return (a - b).getNorm() / 1_m < 1e-5;})); [](Point a, Point b) { return (a - b).getNorm() / 1_m < 1e-5; }));
//Check GetStart(), GetEnd(), GetPoint() // Check GetStart(), GetEnd(), GetPoint()
CHECK((P3.GetEnd() - P3.GetStart()).getNorm() / 1_m == Approx(2)); CHECK((P3.GetEnd() - P3.GetStart()).getNorm() / 1_m == Approx(2));
CHECK((P1.GetPoint(1) - p2).getNorm() / 1_m == Approx(0)); CHECK((P1.GetPoint(1) - p2).getNorm() / 1_m == Approx(0));
//Check GetLength() // Check GetLength()
CHECK(P1.GetLength() / 1_m == Approx(1)); CHECK(P1.GetLength() / 1_m == Approx(1));
CHECK(P2.GetLength() / 1_m == Approx(0)); CHECK(P2.GetLength() / 1_m == Approx(0));
CHECK(P3.GetLength() / 1_m == Approx(2)); CHECK(P3.GetLength() / 1_m == Approx(2));
P2.RemoveFromEnd(); P2.RemoveFromEnd();
CHECK(P2.GetLength() / 1_m == Approx(0)); //Check the length of an empty path CHECK(P2.GetLength() / 1_m == Approx(0)); // Check the length of an empty path
P3.AddToEnd(p4); P3.AddToEnd(p4);
P3.AddToEnd(p5); P3.AddToEnd(p5);
CHECK(P3.GetLength() / 1_m == Approx(4)); CHECK(P3.GetLength() / 1_m == Approx(4));
P3.RemoveFromEnd(); P3.RemoveFromEnd();
CHECK(P3.GetLength() / 1_m == Approx(3)); //Check RemoveFromEnd() else case CHECK(P3.GetLength() / 1_m == Approx(3)); // Check RemoveFromEnd() else case
//Check GetNSegments() // Check GetNSegments()
CHECK(P3.GetNSegments() - 3 == Approx(0)); CHECK(P3.GetNSegments() - 3 == Approx(0));
} }
} }
...@@ -91,7 +91,6 @@ TEST_CASE("UniformRefractiveIndex w/ Homogeneous") { ...@@ -91,7 +91,6 @@ TEST_CASE("UniformRefractiveIndex w/ Homogeneous") {
CHECK((medium.getArclengthFromGrammage(track, density * 5_m) / 5_m) == Approx(1)); CHECK((medium.getArclengthFromGrammage(track, density * 5_m) / 5_m) == Approx(1));
} }
TEST_CASE("ExponentialRefractiveIndex w/ Homogeneous medium") { TEST_CASE("ExponentialRefractiveIndex w/ Homogeneous medium") {
logging::set_level(logging::level::info); logging::set_level(logging::level::info);
...@@ -158,8 +157,8 @@ TEST_CASE("ExponentialRefractiveIndex w/ Homogeneous medium") { ...@@ -158,8 +157,8 @@ TEST_CASE("ExponentialRefractiveIndex w/ Homogeneous medium") {
// and the associated trajectory // and the associated trajectory
setup::Trajectory const track = setup::Trajectory const track =
setup::testing::make_track<setup::Trajectory>(line, tEnd); setup::testing::make_track<setup::Trajectory>(line, tEnd);
// // and the associated trajectory // // and the associated trajectory
// Trajectory<Line> const trajectory(line, tEnd); // Trajectory<Line> const trajectory(line, tEnd);
// and check the integrated grammage // and check the integrated grammage
REQUIRE((medium.getIntegratedGrammage(track, 3_m) / (density * 3_m)) == Approx(1)); REQUIRE((medium.getIntegratedGrammage(track, 3_m) / (density * 3_m)) == Approx(1));
......
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