diff --git a/corsika/detail/framework/geometry/Point.inl b/corsika/detail/framework/geometry/Point.inl index c5c0a98a64491d3c6c752b647d60cdb1c2090e73..ee28975fe4dac77c4a940827d25fa35128217374 100644 --- a/corsika/detail/framework/geometry/Point.inl +++ b/corsika/detail/framework/geometry/Point.inl @@ -59,6 +59,10 @@ namespace corsika { } } + 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 { diff --git a/corsika/framework/geometry/Point.hpp b/corsika/framework/geometry/Point.hpp index 2c684438438455985d0bebfbb95ed6bdafa4c86b..4d92dd330c1cac2e2c886ee6c0033990f72f41d7 100644 --- a/corsika/framework/geometry/Point.hpp +++ b/corsika/framework/geometry/Point.hpp @@ -65,6 +65,11 @@ namespace corsika { 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 diff --git a/tests/framework/testGeometry.cpp b/tests/framework/testGeometry.cpp index e8847ee5e824242344147f46afeb37dfe0eb3708..8153b3a4e65b7d4623e4c5929080f1a002dfb7c2 100644 --- a/tests/framework/testGeometry.cpp +++ b/tests/framework/testGeometry.cpp @@ -312,3 +312,23 @@ TEST_CASE("Geometry Trajectories") { .magnitude() == Approx(0).margin(absMargin)); } } + + +TEST_CASE("Point") { + //define a known CS + CoordinateSystemPtr root = get_root_CoordinateSystem(); + + //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}); + Point p4(root, {5_m, 0_m, 0_m}); + 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)); +}