From c7f46af8b11cbd8f3bedfe12f24d66fa37fa7dd9 Mon Sep 17 00:00:00 2001 From: Maximilian Reininghaus <maximilian.reininghaus@kit.edu> Date: Tue, 31 Jul 2018 19:18:47 +0200 Subject: [PATCH] addition & subtraction for Vector & Point --- Framework/Geometry/Point.h | 13 ++++++++++++- Framework/Geometry/QuantityVector.h | 17 +++++++++++++++++ Framework/Geometry/Vector.h | 9 ++++----- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Framework/Geometry/Point.h b/Framework/Geometry/Point.h index 633279e4c..d60be1266 100644 --- a/Framework/Geometry/Point.h +++ b/Framework/Geometry/Point.h @@ -3,13 +3,13 @@ #include "BaseVector.h" #include "QuantityVector.h" +#include "Vector.h" #include <phys/units/quantity.hpp> class Point : public BaseVector<phys::units::length_d> { using Length = phys::units::quantity<phys::units::length_d, double>; - public: Point(CoordinateSystem const& pCS, QuantityVector<phys::units::length_d> pQVector) : BaseVector<phys::units::length_d>(pCS, pQVector) @@ -43,6 +43,17 @@ public: BaseVector<phys::units::length_d>::qVector = getCoordinates(pCS); BaseVector<phys::units::length_d>::cs = &pCS; } + + Point operator+(Vector<phys::units::length_d> const& pVec) const + { + return Point(*BaseVector<phys::units::length_d>::cs, getCoordinates() + pVec.getComponents(*BaseVector<phys::units::length_d>::cs)); + } + + Vector<phys::units::length_d> operator-(Point const& pB) const + { + auto& cs = *BaseVector<phys::units::length_d>::cs; + return Vector<phys::units::length_d>(cs, getCoordinates() - pB.getCoordinates(cs)); + } }; #endif diff --git a/Framework/Geometry/QuantityVector.h b/Framework/Geometry/QuantityVector.h index 647303791..c874f2277 100644 --- a/Framework/Geometry/QuantityVector.h +++ b/Framework/Geometry/QuantityVector.h @@ -29,6 +29,23 @@ public: { return Quantity(phys::units::detail::magnitude_tag, eVector[index]); } + + Quantity norm() const + { + return Quantity(phys::units::detail::magnitude_tag, eVector.norm()); + } + + auto operator+(QuantityVector<dim> const& pQVec) const + { + return QuantityVector<dim>(eVector + pQVec.eVector); + } + + auto operator-(QuantityVector<dim> const& pQVec) const + { + return QuantityVector<dim>(eVector - pQVec.eVector); + } + + //auto operator*( }; template <typename dim> diff --git a/Framework/Geometry/Vector.h b/Framework/Geometry/Vector.h index bf8ab9d40..6e8b7fbbc 100644 --- a/Framework/Geometry/Vector.h +++ b/Framework/Geometry/Vector.h @@ -10,13 +10,12 @@ class Vector : public BaseVector<dim> { using Quantity = phys::units::quantity<dim, double>; +public: Vector(CoordinateSystem const& pCS, QuantityVector<dim> pQVector) : - BaseVector<Quantity>(pCS, pQVector) + BaseVector<dim>(pCS, pQVector) { } - - -public: + Vector(CoordinateSystem const& cs, Quantity x, Quantity y, Quantity z) : BaseVector<dim>(cs, QuantityVector<dim>(x, y, z)) { @@ -47,7 +46,7 @@ public: auto norm() const { - return Quantity(BaseVector<dim>::qVector.eVector.norm()); + return BaseVector<dim>::qVector.norm(); } //~ template <typename dim2> -- GitLab