diff --git a/corsika/detail/framework/geometry/Path.inl b/corsika/detail/framework/geometry/Path.inl index 102a7d1fcbfb8856c384a852b883a1ea47166659..c367531883c0bce37a488fb2901c6cc13c0bad09 100644 --- a/corsika/detail/framework/geometry/Path.inl +++ b/corsika/detail/framework/geometry/Path.inl @@ -13,22 +13,18 @@ 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) { + } 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); + } 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(); } @@ -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/framework/geometry/Point.inl b/corsika/detail/framework/geometry/Point.inl index aba3af905de8b4235f519c002536b51d45fba87a..fe6e8b162383352523f7ba2399ef8685b0b5a2cb 100644 --- a/corsika/detail/framework/geometry/Point.inl +++ b/corsika/detail/framework/geometry/Point.inl @@ -29,8 +29,8 @@ namespace corsika { return BaseVector<length_d>::getQuantityVector().getX(); } else { return QuantityVector<length_d>( - get_transformation(*cs.get(), *pCS.get()) * - BaseVector<length_d>::getQuantityVector().eigenVector_) + get_transformation(*cs.get(), *pCS.get()) * + BaseVector<length_d>::getQuantityVector().eigenVector_) .getX(); } } @@ -41,8 +41,8 @@ namespace corsika { return BaseVector<length_d>::getQuantityVector().getY(); } else { return QuantityVector<length_d>( - get_transformation(*cs.get(), *pCS.get()) * - BaseVector<length_d>::getQuantityVector().eigenVector_) + get_transformation(*cs.get(), *pCS.get()) * + BaseVector<length_d>::getQuantityVector().eigenVector_) .getY(); } } @@ -53,8 +53,8 @@ namespace corsika { return BaseVector<length_d>::getQuantityVector().getZ(); } else { return QuantityVector<length_d>( - get_transformation(*cs.get(), *pCS.get()) * - BaseVector<length_d>::getQuantityVector().eigenVector_) + get_transformation(*cs.get(), *pCS.get()) * + BaseVector<length_d>::getQuantityVector().eigenVector_) .getZ(); } } @@ -102,7 +102,7 @@ namespace corsika { return os; } - inline LengthType distance(Point const &p1, Point const &p2) { + inline LengthType distance(Point const& p1, Point const& p2) { return (p1 - p2).getNorm(); } diff --git a/corsika/framework/geometry/Path.hpp b/corsika/framework/geometry/Path.hpp index 805650ca55f9a2d8f125b50bc7955c8f418d886f..620cbeeab2210141e8a51f423e9422688313e4d2 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/framework/geometry/Point.hpp b/corsika/framework/geometry/Point.hpp index 80ce77e484489e571ebd6fc3b320611c87ccc328..6eb8786c9df6accf7e654585a5bd4a8d8a957313 100644 --- a/corsika/framework/geometry/Point.hpp +++ b/corsika/framework/geometry/Point.hpp @@ -82,7 +82,7 @@ namespace corsika { /* * calculates the distance between two points */ - inline LengthType distance(Point const &p1, Point const &p2); + inline LengthType distance(Point const& p1, Point const& p2); } // namespace corsika diff --git a/tests/framework/testGeometry.cpp b/tests/framework/testGeometry.cpp index 37deb7fe7cd430564d456dc268c3387677ffcdac..809ae5e1391071b948a6307600cabb4bfc201136 100644 --- a/tests/framework/testGeometry.cpp +++ b/tests/framework/testGeometry.cpp @@ -139,20 +139,20 @@ TEST_CASE("Geometry CoordinateSystems") { CHECK(zPrime.getComponents(rootCS)[0].magnitude() == Approx(0)); CHECK(xPrime.getComponents(rootCS).getEigenVector().dot( - yPrime.getComponents(rootCS).getEigenVector()) == Approx(0)); + yPrime.getComponents(rootCS).getEigenVector()) == Approx(0)); CHECK(zPrime.getComponents(rootCS).getEigenVector().dot( - xPrime.getComponents(rootCS).getEigenVector()) == Approx(0)); + xPrime.getComponents(rootCS).getEigenVector()) == Approx(0)); CHECK(yPrime.getComponents(rootCS).getEigenVector().dot( - zPrime.getComponents(rootCS).getEigenVector()) == Approx(0)); + zPrime.getComponents(rootCS).getEigenVector()) == Approx(0)); CHECK(yPrime.getComponents(rootCS).getEigenVector().dot( - yPrime.getComponents(rootCS).getEigenVector()) == + yPrime.getComponents(rootCS).getEigenVector()) == Approx((5_m * 5_m).magnitude())); CHECK(xPrime.getComponents(rootCS).getEigenVector().dot( - xPrime.getComponents(rootCS).getEigenVector()) == + xPrime.getComponents(rootCS).getEigenVector()) == Approx((5_m * 5_m).magnitude())); CHECK(zPrime.getComponents(rootCS).getEigenVector().dot( - zPrime.getComponents(rootCS).getEigenVector()) == + zPrime.getComponents(rootCS).getEigenVector()) == Approx((5_m * 5_m).magnitude())); } @@ -165,25 +165,25 @@ TEST_CASE("Geometry CoordinateSystems") { CHECK(zPrime.dot(v).magnitude() > 0); CHECK(xPrime.getComponents(rootCS).getEigenVector().dot( - v.getComponents().getEigenVector()) == Approx(0)); + v.getComponents().getEigenVector()) == Approx(0)); CHECK(yPrime.getComponents(rootCS).getEigenVector().dot( - v.getComponents().getEigenVector()) == Approx(0)); + v.getComponents().getEigenVector()) == Approx(0)); CHECK(xPrime.getComponents(rootCS).getEigenVector().dot( - yPrime.getComponents(rootCS).getEigenVector()) == Approx(0)); + yPrime.getComponents(rootCS).getEigenVector()) == Approx(0)); CHECK(zPrime.getComponents(rootCS).getEigenVector().dot( - xPrime.getComponents(rootCS).getEigenVector()) == Approx(0)); + xPrime.getComponents(rootCS).getEigenVector()) == Approx(0)); CHECK(yPrime.getComponents(rootCS).getEigenVector().dot( - zPrime.getComponents(rootCS).getEigenVector()) == Approx(0)); + zPrime.getComponents(rootCS).getEigenVector()) == Approx(0)); CHECK(yPrime.getComponents(rootCS).getEigenVector().dot( - yPrime.getComponents(rootCS).getEigenVector()) == + yPrime.getComponents(rootCS).getEigenVector()) == Approx((5_m * 5_m).magnitude())); CHECK(xPrime.getComponents(rootCS).getEigenVector().dot( - xPrime.getComponents(rootCS).getEigenVector()) == + xPrime.getComponents(rootCS).getEigenVector()) == Approx((5_m * 5_m).magnitude())); CHECK(zPrime.getComponents(rootCS).getEigenVector().dot( - zPrime.getComponents(rootCS).getEigenVector()) == + zPrime.getComponents(rootCS).getEigenVector()) == Approx((5_m * 5_m).magnitude())); } } @@ -315,10 +315,10 @@ TEST_CASE("Geometry Trajectories") { } TEST_CASE("Distance between points") { - //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}); @@ -326,68 +326,65 @@ TEST_CASE("Distance between points") { Point p5(root, {0_m, 4_m, 0_m}); Point p6(root, {0_m, 5_m, 0_m}); - //check distance() function + // check distance() function CHECK(distance(p1, p2) / 1_m == Approx(5)); CHECK(distance(p3, p4) / 1_m == Approx(4)); CHECK(distance(p5, 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)); - } } \ No newline at end of file