diff --git a/corsika/detail/framework/geometry/Path.inl b/corsika/detail/framework/geometry/Path.inl index 13e38f33ea230cceb1f76c432cbaf0b5b02cef8f..102a7d1fcbfb8856c384a852b883a1ea47166659 100644 --- a/corsika/detail/framework/geometry/Path.inl +++ b/corsika/detail/framework/geometry/Path.inl @@ -13,54 +13,66 @@ 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(); } } } - inline void Path::AddToEnd(Point const& point) { + inline void Path::addToEnd(Point const& point) { length_ += (point - points_.back()).getNorm(); points_.push_back(point); } - inline void Path::RemoveFromEnd() { + 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) { + } + 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(); } inline auto Path::end() { return points_.end(); } - inline int Path::GetNSegments() const { return points_.size() - 1; } + inline int Path::getNSegments() const { return points_.size() - 1; } } // namespace corsika \ No newline at end of file diff --git a/corsika/detail/framework/geometry/Point.inl b/corsika/detail/framework/geometry/Point.inl index ee28975fe4dac77c4a940827d25fa35128217374..aba3af905de8b4235f519c002536b51d45fba87a 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,16 +53,12 @@ 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(); } } - inline LengthType Point::distance_to(Point const& point) const { - return (*this - point).getNorm(); - } - /// this always returns a QuantityVector as triple inline QuantityVector<length_d> Point::getCoordinates( CoordinateSystemPtr const& pCS) const { @@ -106,4 +102,8 @@ namespace corsika { return os; } -} // namespace corsika + inline LengthType distance(Point const &p1, Point const &p2) { + return (p1 - p2).getNorm(); + } + +} // namespace corsika \ No newline at end of file diff --git a/corsika/detail/media/ExponentialRefractiveIndex.inl b/corsika/detail/media/ExponentialRefractiveIndex.inl index e8f39fbd87b87080fb6fe0f62bf9182dacfd3f44..760abb9e2410b3e9f1a1fced6560b3a75998779b 100644 --- a/corsika/detail/media/ExponentialRefractiveIndex.inl +++ b/corsika/detail/media/ExponentialRefractiveIndex.inl @@ -23,8 +23,6 @@ namespace corsika { 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()); } diff --git a/corsika/framework/geometry/Path.hpp b/corsika/framework/geometry/Path.hpp index f7933cb4aae3c8a2e68353bc962fb46375a761e8..805650ca55f9a2d8f125b50bc7955c8f418d886f 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. @@ -34,32 +34,32 @@ namespace corsika { /** * Add a new Point to the end of the path. */ - inline void AddToEnd(Point const& point); + inline void addToEnd(Point const& point); /** * Remove a point from the end of the path. */ - inline void RemoveFromEnd(); + inline void removeFromEnd(); /** * Get the total length of the path. */ - inline LengthType GetLength() const; + inline LengthType getLength() const; /** * Get the starting point of the path. */ - inline Point GetStart() const; + inline Point getStart() const; /** * Get the end point of the path. */ - inline Point GetEnd() const; + inline Point getEnd() const; /** * Get a specific point of the path. */ - inline Point GetPoint(std::size_t const index) const; + inline Point getPoint(std::size_t const index) const; /** * Return an iterator to the start of the Path. @@ -76,9 +76,9 @@ namespace corsika { * This is one less than the number of points that * defines the path. */ - inline int GetNSegments() const; + 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 4d92dd330c1cac2e2c886ee6c0033990f72f41d7..80ce77e484489e571ebd6fc3b320611c87ccc328 100644 --- a/corsika/framework/geometry/Point.hpp +++ b/corsika/framework/geometry/Point.hpp @@ -31,8 +31,8 @@ namespace corsika { /** \todo TODO: this should be private or protected, we don NOT want to expose numbers * without reference to outside: */ - QuantityVector<length_d> const& getCoordinates() const; - QuantityVector<length_d>& getCoordinates(); + inline QuantityVector<length_d> const& getCoordinates() const; + inline QuantityVector<length_d>& getCoordinates(); /** this always returns a QuantityVector as triple @@ -40,7 +40,7 @@ namespace corsika { \returns A value type QuantityVector, since it may have to create a temporary object to transform to pCS. **/ - QuantityVector<length_d> getCoordinates(CoordinateSystemPtr const& pCS) const; + inline QuantityVector<length_d> getCoordinates(CoordinateSystemPtr const& pCS) const; /** * this always returns a QuantityVector as triple @@ -49,7 +49,7 @@ namespace corsika { * is actually transformed to pCS, if needed. Thus, there may be an implicit call to * \ref rebase. **/ - QuantityVector<length_d>& getCoordinates(CoordinateSystemPtr const& pCS); + inline QuantityVector<length_d>& getCoordinates(CoordinateSystemPtr const& pCS); /** * \name access coordinate components @@ -60,30 +60,30 @@ namespace corsika { * created and destroyed each call. This can be avoided by using * \ref rebase first. **/ - LengthType getX(CoordinateSystemPtr const& pCS) const; - LengthType getY(CoordinateSystemPtr const& pCS) const; - LengthType getZ(CoordinateSystemPtr const& pCS) const; + inline LengthType getX(CoordinateSystemPtr const& pCS) const; + inline LengthType getY(CoordinateSystemPtr const& pCS) const; + inline LengthType getZ(CoordinateSystemPtr const& pCS) const; /** \} **/ - /* - * calculates the distance between two points - */ - inline LengthType distance_to(Point const& point) const; - /*! * transforms the Point into another CoordinateSystem by changing its * coordinates interally */ - void rebase(CoordinateSystemPtr const& pCS); + inline void rebase(CoordinateSystemPtr const& pCS); - Point operator+(Vector<length_d> const& pVec) const; + inline Point operator+(Vector<length_d> const& pVec) const; /*! * returns the distance Vector between two points */ - Vector<length_d> operator-(Point const& pB) const; + inline Vector<length_d> operator-(Point const& pB) const; }; + /* + * calculates the distance between two points + */ + inline LengthType distance(Point const &p1, Point const &p2); + } // namespace corsika -#include <corsika/detail/framework/geometry/Point.inl> +#include <corsika/detail/framework/geometry/Point.inl> \ No newline at end of file diff --git a/corsika/media/ExponentialRefractiveIndex.hpp b/corsika/media/ExponentialRefractiveIndex.hpp index 64fde5a125b184bd0cb1e53726370433452170c7..cc3ec838e9531a57d2ebd45d3434e00538481a06 100644 --- a/corsika/media/ExponentialRefractiveIndex.hpp +++ b/corsika/media/ExponentialRefractiveIndex.hpp @@ -41,7 +41,7 @@ namespace corsika { Args&&... args); /** - * Evaluate the refractive index at a given location. + * Evaluate the refractive index at a given location using its z-coordinate. * * @param point The location to evaluate at. * @returns The refractive index at this point. diff --git a/tests/framework/testGeometry.cpp b/tests/framework/testGeometry.cpp index e889927e75f93c20e5dda568bca8aac881ac18c2..37deb7fe7cd430564d456dc268c3387677ffcdac 100644 --- a/tests/framework/testGeometry.cpp +++ b/tests/framework/testGeometry.cpp @@ -20,7 +20,7 @@ #include <corsika/framework/geometry/StraightTrajectory.hpp> #include <corsika/framework/geometry/LeapFrogTrajectory.hpp> -#include <PhysicalUnitsCatch2.hpp> // namespace corsika::testing +#include <PhysicalUnitsCatch2.hpp> // namespace corsike::testing using namespace corsika; using namespace corsika::testing; @@ -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())); } } @@ -314,11 +314,11 @@ TEST_CASE("Geometry Trajectories") { } } -TEST_CASE("Point") { - // define a known CS +TEST_CASE("Distance between points") { + //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,66 +326,68 @@ TEST_CASE("Point") { Point p5(root, {0_m, 4_m, 0_m}); Point p6(root, {0_m, 5_m, 0_m}); - SECTION("Test 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)); + //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 - 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((P3.GetEnd() - P3.GetStart()).getNorm() / 1_m == Approx(2)); - CHECK((P1.GetPoint(1) - p2).getNorm() / 1_m == Approx(0)); - // 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 - 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.GetNSegments() - 3 == Approx(0)); + //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((P3.getEnd() - P3.getStart()).getNorm() / 1_m == Approx(2)); + CHECK((P1.getPoint(1) - p2).getNorm() / 1_m == Approx(0)); + //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 + 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.getNSegments() - 3 == Approx(0)); + } } \ No newline at end of file