IAP GITLAB

Skip to content
Snippets Groups Projects
Commit dfc7af3b authored by Maximilian Reininghaus's avatar Maximilian Reininghaus :vulcan:
Browse files

Merge branch 'expand_point_operations' into 'master'

Added subtraction operator to Point, added tests

See merge request !474
parents e2d967eb 859e8402
No related branches found
No related tags found
1 merge request!474Added subtraction operator to Point, added tests
Pipeline #9786 passed with warnings
...@@ -67,11 +67,15 @@ namespace corsika { ...@@ -67,11 +67,15 @@ namespace corsika {
return Point(cs, getCoordinates() + pVec.getComponents(cs)); 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 { inline Vector<length_d> Point::operator-(Point const& pB) const {
CoordinateSystemPtr const& cs = BaseVector<length_d>::getCoordinateSystem(); CoordinateSystemPtr const& cs = BaseVector<length_d>::getCoordinateSystem();
return Vector<length_d>(cs, getCoordinates() - pB.getCoordinates(cs)); return Vector<length_d>(cs, getCoordinates() - pB.getCoordinates(cs));
} }
inline std::ostream& operator<<(std::ostream& os, corsika::Point const& p) { inline std::ostream& operator<<(std::ostream& os, corsika::Point const& p) {
auto const& qv = p.getCoordinates(); auto const& qv = p.getCoordinates();
os << qv << " (ref:" << fmt::ptr(p.getCoordinateSystem()) << ")"; os << qv << " (ref:" << fmt::ptr(p.getCoordinateSystem()) << ")";
......
...@@ -72,6 +72,7 @@ namespace corsika { ...@@ -72,6 +72,7 @@ namespace corsika {
inline void rebase(CoordinateSystemPtr const& pCS); inline void rebase(CoordinateSystemPtr const& pCS);
inline Point operator+(Vector<length_d> const& pVec) const; 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 * returns the distance Vector between two points
......
...@@ -60,6 +60,20 @@ TEST_CASE("Geometry CoordinateSystems") { ...@@ -60,6 +60,20 @@ TEST_CASE("Geometry CoordinateSystems") {
CHECK(testV3.getNorm() / (tesla * meter) == Approx(6)); 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") { SECTION("translations") {
QuantityVector<length_d> const translationVector{0_m, 4_m, 0_m}; QuantityVector<length_d> const translationVector{0_m, 4_m, 0_m};
CORSIKA_LOG_INFO("QuantityVector<length_d> translationVector={}", translationVector); CORSIKA_LOG_INFO("QuantityVector<length_d> translationVector={}", translationVector);
...@@ -527,4 +541,4 @@ TEST_CASE("Path") { ...@@ -527,4 +541,4 @@ TEST_CASE("Path") {
P3.removeFromEnd(); P3.removeFromEnd();
CHECK(P3.getNSegments() == Approx(0)); CHECK(P3.getNSegments() == Approx(0));
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment