From 41c1d3ad77bd63e1cc209f0c4c0c205058aef182 Mon Sep 17 00:00:00 2001
From: Nikos Karastathis <n.karastathis@kit.edu>
Date: Mon, 25 Jan 2021 12:42:17 +0100
Subject: [PATCH] Added and tested distance_to() method

---
 corsika/detail/framework/geometry/Point.inl |  4 ++++
 corsika/framework/geometry/Point.hpp        |  5 +++++
 tests/framework/testGeometry.cpp            | 20 ++++++++++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/corsika/detail/framework/geometry/Point.inl b/corsika/detail/framework/geometry/Point.inl
index c5c0a98a6..ee28975fe 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 2c6844384..4d92dd330 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 e8847ee5e..8153b3a4e 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));
+}
-- 
GitLab