diff --git a/corsika/detail/framework/geometry/Vector.inl b/corsika/detail/framework/geometry/Vector.inl index 93907b944206f64364c254473739aa324f9c6aeb..0e2cfdd6104bd4062d3bf752c43e7ffc858fe70a 100644 --- a/corsika/detail/framework/geometry/Vector.inl +++ b/corsika/detail/framework/geometry/Vector.inl @@ -238,4 +238,17 @@ namespace corsika { 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 diff --git a/corsika/framework/geometry/Vector.hpp b/corsika/framework/geometry/Vector.hpp index 2a4b34a196a9363fc87926daeb9d5f5fcdb86076..13d47d7172b89d7406d6ce94fa2450b2f0aa6ede 100644 --- a/corsika/framework/geometry/Vector.hpp +++ b/corsika/framework/geometry/Vector.hpp @@ -142,6 +142,31 @@ namespace corsika { 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 #include <corsika/detail/framework/geometry/Vector.inl> diff --git a/tests/framework/testGeometry.cpp b/tests/framework/testGeometry.cpp index f3b69693146f7c7aee114ce2f25ad459f00fe7c2..19c311881c728524aa7256464f30d7ed52975d55 100644 --- a/tests/framework/testGeometry.cpp +++ b/tests/framework/testGeometry.cpp @@ -46,6 +46,17 @@ TEST_CASE("Geometry CoordinateSystems") { CHECK((p1.getCoordinates(rootCS) - coordinates).getNorm().magnitude() == 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") { QuantityVector<length_d> const translationVector{0_m, 4_m, 0_m}; CORSIKA_LOG_INFO("QuantityVector<length_d> translationVector={}", translationVector);