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