IAP GITLAB

Skip to content
Snippets Groups Projects
Commit e5998623 authored by Ralf Ulrich's avatar Ralf Ulrich
Browse files

Merge branch...

Merge branch '430-commutative-property-with-scalar-multiplication-is-not-supported-in-c8' into 'master'

Resolve "Commutative property with scalar multiplication is not supported in C8"

Closes #430

See merge request !372
parents 10727ecb 0da1e57a
No related branches found
No related tags found
1 merge request!372Resolve "Commutative property with scalar multiplication is not supported in C8"
Pipeline #5584 passed with warnings
...@@ -238,4 +238,17 @@ namespace corsika { ...@@ -238,4 +238,17 @@ namespace corsika {
return os; return os;
} }
/*
* scalar * vector multiplication
*/
template <typename TDimension, typename UDimension>
inline Vector<phys::units::detail::product_d<TDimension, UDimension>> operator*(
quantity<UDimension> const n, Vector<TDimension> const& vec) {
return vec * n;
}
template <typename TDimension>
inline Vector<TDimension> operator*(double const n, Vector<TDimension> const& vec) {
return vec * n;
}
} // namespace corsika } // namespace corsika
...@@ -142,6 +142,31 @@ namespace corsika { ...@@ -142,6 +142,31 @@ namespace corsika {
auto dot(Vector<TDimension2> const& pV) const; auto dot(Vector<TDimension2> const& pV) const;
}; };
/**
* Free operator to allow commutative multiplications of quantities and Vector.
*
* @tparam TDimension
* @tparam UDimension
* @param n
* @param vec
* @return auto
*/
template <typename TDimension, typename UDimension>
Vector<phys::units::detail::product_d<TDimension, UDimension>> operator*(
quantity<UDimension> const n, Vector<TDimension> const& vec);
/**
* Free operator to allow commutative multiplications of normal double with Vector.
*
* @tparam TDimension
* @tparam UDimension
* @param n
* @param vec
* @return auto
*/
template <typename TDimension>
Vector<TDimension> operator*(double const n, Vector<TDimension> const& vec);
} // namespace corsika } // namespace corsika
#include <corsika/detail/framework/geometry/Vector.inl> #include <corsika/detail/framework/geometry/Vector.inl>
...@@ -46,6 +46,17 @@ TEST_CASE("Geometry CoordinateSystems") { ...@@ -46,6 +46,17 @@ TEST_CASE("Geometry CoordinateSystems") {
CHECK((p1.getCoordinates(rootCS) - coordinates).getNorm().magnitude() == CHECK((p1.getCoordinates(rootCS) - coordinates).getNorm().magnitude() ==
Approx(0).margin(absMargin)); Approx(0).margin(absMargin));
SECTION("basic operations") {
auto testV0 = v1 * 6;
CHECK(testV0.getNorm() / tesla == Approx(6));
auto testV1 = 6 * v1;
CHECK(testV1.getNorm() / tesla == Approx(6));
auto testV2 = 6_m * v1;
CHECK(testV2.getNorm() / (tesla * meter) == Approx(6));
auto testV3 = v1 * 6_m;
CHECK(testV3.getNorm() / (tesla * meter) == Approx(6));
}
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);
......
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