diff --git a/corsika/detail/framework/geometry/Point.inl b/corsika/detail/framework/geometry/Point.inl index 156723dd149102ecec8ee88ab773dafa5cfec84d..ffd783292aaf3892c7958a849db11d70b9a6af06 100644 --- a/corsika/detail/framework/geometry/Point.inl +++ b/corsika/detail/framework/geometry/Point.inl @@ -67,11 +67,15 @@ namespace corsika { return Point(cs, getCoordinates() + pVec.getComponents(cs)); } + inline Point Point::operator-(Vector<length_d> const& pVec) const { + CoordinateSystemPtr const& cs = BaseVector<length_d>::getCoordinateSystem(); + return Point(cs, getCoordinates() - pVec.getComponents(cs)); + } + inline Vector<length_d> Point::operator-(Point const& pB) const { CoordinateSystemPtr const& cs = BaseVector<length_d>::getCoordinateSystem(); return Vector<length_d>(cs, getCoordinates() - pB.getCoordinates(cs)); } - inline std::ostream& operator<<(std::ostream& os, corsika::Point const& p) { auto const& qv = p.getCoordinates(); os << qv << " (ref:" << fmt::ptr(p.getCoordinateSystem()) << ")"; diff --git a/corsika/framework/geometry/Point.hpp b/corsika/framework/geometry/Point.hpp index 6eb8786c9df6accf7e654585a5bd4a8d8a957313..09aaa1f50f30619fbbfe68c8ccac7b2769c045de 100644 --- a/corsika/framework/geometry/Point.hpp +++ b/corsika/framework/geometry/Point.hpp @@ -72,6 +72,7 @@ namespace corsika { inline void rebase(CoordinateSystemPtr const& pCS); inline Point operator+(Vector<length_d> const& pVec) const; + inline Point operator-(Vector<length_d> const& pVec) const; /*! * returns the distance Vector between two points diff --git a/tests/framework/testGeometry.cpp b/tests/framework/testGeometry.cpp index 85fef905f80a885721a628b9cb563380a7f6b07b..8cc52855a21de3b8de2f15b409ff9c33dcb5656c 100644 --- a/tests/framework/testGeometry.cpp +++ b/tests/framework/testGeometry.cpp @@ -60,6 +60,20 @@ TEST_CASE("Geometry CoordinateSystems") { CHECK(testV3.getNorm() / (tesla * meter) == Approx(6)); } + SECTION("point") { + Point const p00 = Point(rootCS, {0_m, 0_m, 0_m}); + Point const p01 = Point(rootCS, {3_m, 3_m, 3_m}); + Point const p02 = Point(rootCS, {1_m, -5_m, 6_m}); + + LengthVector const d01 = p00 - p01; + LengthVector const d12 = p01 - p02; + LengthVector const d20 = p02 - p00; + + CHECK(d12.getNorm() / (p01 - p02).getNorm() == Approx(1)); + CHECK(d12.getNorm() / distance(p01, p02) == Approx(1)); + CHECK(d12.getNorm() / distance(p02, p01) == Approx(1)); + } + SECTION("translations") { QuantityVector<length_d> const translationVector{0_m, 4_m, 0_m}; CORSIKA_LOG_INFO("QuantityVector<length_d> translationVector={}", translationVector); @@ -527,4 +541,4 @@ TEST_CASE("Path") { P3.removeFromEnd(); CHECK(P3.getNSegments() == Approx(0)); } -} \ No newline at end of file +}