IAP GITLAB

Skip to content
Snippets Groups Projects
Commit f923073f authored by ralfulrich's avatar ralfulrich
Browse files

FourVector

parent 73a301df
No related branches found
No related tags found
1 merge request!280Refactory 2020
...@@ -10,159 +10,109 @@ ...@@ -10,159 +10,109 @@
#pragma once #pragma once
#include <iostream>
#include <type_traits> #include <type_traits>
#include <corsika/framework/core/PhysicalUnits.hpp> #include <corsika/framework/core/PhysicalUnits.hpp>
#include <corsika/framework/geometry/Vector.hpp> #include <corsika/framework/geometry/Vector.hpp>
namespace corsika { namespace corsika {
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
TimeType FourVector<TimeType, SpaceVecType>::GetTimeLikeComponent() const { TTimeType FourVector<TTimeType, TSpaceVecType>::getTimeLikeComponent() const {
return fTimeLike; return timeLike_;
} }
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
SpaceVecType& FourVector<TimeType, SpaceVecType>::GetSpaceLikeComponents() { TSpaceVecType& FourVector<TTimeType, TSpaceVecType>::spaceLikeComponents() {
return fSpaceLike; return spaceLike_;
} }
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
const SpaceVecType& FourVector<TimeType, SpaceVecType>::GetSpaceLikeComponents() const { const TSpaceVecType& FourVector<TTimeType, TSpaceVecType>::getSpaceLikeComponents()
return fSpaceLike; const {
return spaceLike_;
} }
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
auto FourVector<TimeType, SpaceVecType>::GetNormSqr() const { typename FourVector<TTimeType, TSpaceVecType>::norm_square_type
return GetTimeSquared() - fSpaceLike.squaredNorm(); FourVector<TTimeType, TSpaceVecType>::getNormSqr() const {
return getTimeSquared() - spaceLike_.squaredNorm();
} }
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
typename FourVector<TimeType, SpaceVecType>::SpaceType typename FourVector<TTimeType, TSpaceVecType>::norm_type
FourVector<TimeType, SpaceVecType>::GetNorm() const { FourVector<TTimeType, TSpaceVecType>::getNorm() const {
return sqrt(abs(GetNormSqr())); return sqrt(abs(getNormSqr()));
} }
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
bool FourVector<TimeType, SpaceVecType>::IsTimelike() const { bool FourVector<TTimeType, TSpaceVecType>::isTimelike() const {
return GetTimeSquared() < fSpaceLike.squaredNorm(); return getTimeSquared() < spaceLike_.squaredNorm();
} }
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
bool FourVector<TimeType, SpaceVecType>::IsSpacelike() const { bool FourVector<TTimeType, TSpaceVecType>::isSpacelike() const {
return GetTimeSquared() > fSpaceLike.squaredNorm(); return getTimeSquared() > spaceLike_.squaredNorm();
} }
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
FourVector<TimeType, SpaceVecType>& FourVector<TimeType, SpaceVecType>::operator+=( FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::operator+=(
const FourVector& b) { const FourVector& b) {
fTimeLike += b.fTimeLike; timeLike_ += b.timeLike_;
fSpaceLike += b.fSpaceLike; spaceLike_ += b.spaceLike_;
return *this; return *this;
} }
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
FourVector<TimeType, SpaceVecType>& FourVector<TimeType, SpaceVecType>::operator-=( FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::operator-=(
const FourVector& b) { const FourVector& b) {
fTimeLike -= b.fTimeLike; timeLike_ -= b.timeLike_;
fSpaceLike -= b.fSpaceLike; spaceLike_ -= b.spaceLike_;
return *this; return *this;
} }
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
FourVector<TimeType, SpaceVecType>& FourVector<TimeType, SpaceVecType>::operator*=( FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::operator*=(
const double b) { const double b) {
fTimeLike *= b; timeLike_ *= b;
fSpaceLike *= b; spaceLike_ *= b;
return *this; return *this;
} }
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
FourVector<TimeType, SpaceVecType>& FourVector<TimeType, SpaceVecType>::operator/=( FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::operator/=(
const double b) { const double b) {
fTimeLike /= b; timeLike_ /= b;
fSpaceLike.GetComponents() /= b; // TODO: WHY IS THIS?????? spaceLike_.GetComponents() /= b;
return *this; return *this;
} }
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
FourVector<TimeType, SpaceVecType>& FourVector<TimeType, SpaceVecType>::operator/( FourVector<TTimeType, TSpaceVecType>& FourVector<TTimeType, TSpaceVecType>::operator/(
const double b) { const double b) {
*this /= b; *this /= b;
return *this; return *this;
} }
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
typename FourVector<TimeType, SpaceVecType>::SpaceType typename FourVector<TTimeType, TSpaceVecType>::norm_type
FourVector<TimeType, SpaceVecType>::operator*(const FourVector& b) { FourVector<TTimeType, TSpaceVecType>::operator*(const FourVector& b) {
if constexpr (std::is_same<typename std::decay<TimeType>::type, if constexpr (std::is_same<time_type, decltype(std::declval<space_type>() / meter *
decltype(std::declval<SpaceType>() / meter * second)>::value)
second)>::value) return timeLike_ * b.timeLike_ * constants::cSquared - spaceLike_.norm();
return fTimeLike * b.fTimeLike * (constants::c * constants::c) - fSpaceLike.norm();
else else
return fTimeLike * fTimeLike - fSpaceLike.norm(); return timeLike_ * timeLike_ - spaceLike_.norm();
} }
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
auto FourVector<TimeType, SpaceVecType>::GetTimeSquared() const { typename FourVector<TTimeType, TSpaceVecType>::norm_square_type
if constexpr (std::is_same<typename std::decay<TimeType>::type, FourVector<TTimeType, TSpaceVecType>::getTimeSquared() const {
decltype(std::declval<SpaceType>() / meter * if constexpr (std::is_same<time_type, decltype(std::declval<space_type>() / meter *
second)>::value) second)>::value)
return fTimeLike * fTimeLike * constants::cSquared; return timeLike_ * timeLike_ * constants::cSquared;
else else
return fTimeLike * fTimeLike; return timeLike_ * timeLike_;
}
/**
The math operator+
*/
template <typename TimeType, typename SpaceVecType>
inline FourVector<typename std::decay<TimeType>::type,
typename std::decay<SpaceVecType>::type>
operator+(const FourVector<TimeType, SpaceVecType>& a,
const FourVector<TimeType, SpaceVecType>& b) {
return FourVector<typename std::decay<TimeType>::type,
typename std::decay<SpaceVecType>::type>(
a.fTimeLike + b.fTimeLike, a.fSpaceLike + b.fSpaceLike);
}
/**
The math operator-
*/
template <typename TimeType, typename SpaceVecType>
inline FourVector<typename std::decay<TimeType>::type,
typename std::decay<SpaceVecType>::type>
operator-(const FourVector<TimeType, SpaceVecType>& a,
const FourVector<TimeType, SpaceVecType>& b) {
return FourVector<typename std::decay<TimeType>::type,
typename std::decay<SpaceVecType>::type>(
a.fTimeLike - b.fTimeLike, a.fSpaceLike - b.fSpaceLike);
}
/**
The math operator*
*/
template <typename TimeType, typename SpaceVecType>
inline FourVector<typename std::decay<TimeType>::type,
typename std::decay<SpaceVecType>::type>
operator*(const FourVector<TimeType, SpaceVecType>& a, const double b) {
return FourVector<typename std::decay<TimeType>::type,
typename std::decay<SpaceVecType>::type>(a.fTimeLike * b,
a.fSpaceLike * b);
}
/**
The math operator/
*/
template <typename TimeType, typename SpaceVecType>
inline FourVector<typename std::decay<TimeType>::type,
typename std::decay<SpaceVecType>::type>
operator/(const FourVector<TimeType, SpaceVecType>& a, const double b) {
return FourVector<typename std::decay<TimeType>::type,
typename std::decay<SpaceVecType>::type>(a.fTimeLike / b,
a.fSpaceLike / b);
} }
} // namespace corsika } // namespace corsika
...@@ -16,185 +16,179 @@ ...@@ -16,185 +16,179 @@
namespace corsika { namespace corsika {
/** /**
FourVector supports "full" units, e.g. E in [GeV/c] and p in [GeV], FourVector fully supports units, e.g. E in [GeV/c] and p in [GeV],
or also t in [s] and r in [m], etc. or also t in [s] and r in [m], etc.
However, for HEP applications it is also possible to use E and p However, for HEP applications it is also possible to use E and p
both in [GeV]. both in [GeV].
Thus, the input units of time-like and space-like coordinates
must either be idential (e.g. GeV) or scaled by "c" as in
[E/c]=[p].
The FourVector can return NormSqr and Norm, whereas Norm is The FourVector can return NormSqr and Norm, whereas Norm is
sqrt(abs(NormSqr)). The physical units are always calculated and sqrt(abs(NormSqr)). The physical units are always calculated and
returned properly. returned properly.
FourVector can also return if it is TimeLike, SpaceLike or PhotonLike. FourVector can also return if it is TimeLike, SpaceLike or PhotonLike.
When a FourVector is initialized with a lvalue reference, this is When a FourVector is initialized with a lvalue references,
also used for the internal storage, which should lead to complete e.g. as `FourVector<TimeType&, Vector<length_d>&>`, references
disappearance of the FourVector class during optimization. are also used as internal data types, which should lead to
complete disappearance of the FourVector class during
optimization.
*/ */
template <typename TimeType, typename SpaceVecType> template <typename TTimeType, typename TSpaceVecType>
class FourVector { class FourVector {
public: public:
using SpaceType = typename std::decay<SpaceVecType>::type::Quantity; using space_vec_type = typename std::decay<TSpaceVecType>::type;
using space_type = typename space_vec_type::Quantity;
using time_type = typename std::decay<TTimeType>::type;
//! check the types and the physical units here: //! check the types and the physical units here:
static_assert( static_assert(std::is_same<time_type, space_type>::value ||
std::is_same<typename std::decay<TimeType>::type, SpaceType>::value || std::is_same<time_type, decltype(std::declval<space_type>() /
std::is_same<typename std::decay<TimeType>::type, meter * second)>::value,
decltype(std::declval<SpaceType>() / meter * second)>::value, "Units of time-like and space-like coordinates must either be idential "
"Units of time-like and space-like coordinates must either be idential " "(e.g. GeV) or [E/c]=[p]");
"(e.g. GeV) or [E/c]=[p]");
using norm_type = space_type;
using norm_square_type =
decltype(std::declval<norm_type>() * std::declval<norm_type>());
public: public:
FourVector() = default; FourVector() = default;
FourVector(const TimeType& eT, const SpaceVecType& eS) FourVector(TTimeType const& eT, TSpaceVecType const& eS)
: fTimeLike(eT) : timeLike_(eT)
, fSpaceLike(eS) {} , spaceLike_(eS) {}
/* /*
* FIXME: These Getters are mis-leading and does not favor * FIXME: These Getters are mis-leading and does not favor
* locality. Adhere to Getter/Setter * locality. Adhere to Getter/Setter
*/ */
/** /**
* @brief
* *
* @return fTimeLike * @return timeLike_
*/ */
TimeType GetTimeLikeComponent() const; TTimeType getTimeLikeComponent() const;
/** /**
* @brief
* *
* @return fSpaceLike * @return spaceLike_
*/ */
SpaceVecType& GetSpaceLikeComponents(); TSpaceVecType& spaceLikeComponents();
/** /**
* @brief
* *
* @return fSpaceLike; * @return spaceLike_;
*/ */
const SpaceVecType& GetSpaceLikeComponents() const; TSpaceVecType const& getSpaceLikeComponents() const;
/** /**
* @brief
* *
* @return * @return $p_0^2 - \vec{p}^2$
*/ */
auto GetNormSqr() const; norm_square_type getNormSqr() const;
/** /**
* @brief
* *
* @return * @return $sqrt(p_0^2 - \vec{p}^2)$
*/ */
SpaceType GetNorm() const; norm_type getNorm() const;
/* /*
* FIXME: a better alternative would be to define an enumeration * FIXME: a better alternative would be to define an enumeration
* enum { SpaceLike =-1, TimeLike, LightLike } V4R_Category; * enum { SpaceLike =-1, TimeLike, LightLike } V4R_Category;
* and a method called V4R_Category GetCategory() const; * and a method called V4R_Category GetCategory() const;
*
* RU: then you have to decide in the constructor which avoids "lazyness"
*/ */
/** /**
* @brief
* *
* @return * @return
*/ */
bool IsTimelike() const; bool isTimelike() const;
/** /**
* @brief * @defgroup math operators (class members)
* * @{
* @return
*/ */
bool IsSpacelike() const; bool isSpacelike() const;
FourVector& operator+=(const FourVector& b); FourVector& operator+=(FourVector const&);
FourVector& operator-=(const FourVector&);
FourVector& operator-=(const FourVector& b); FourVector& operator*=(const double);
FourVector& operator/=(const double);
FourVector& operator*=(const double b); FourVector& operator/(const double);
FourVector& operator/=(const double b);
FourVector& operator/(const double b);
/** /**
Scalar product of two FourVectors
Note that the product between two 4-vectors assumes that you use Note that the product between two 4-vectors assumes that you use
the same "c" convention for both. Only the LHS vector is checked the same "c" convention for both. Only the LHS vector is checked
for this. You cannot mix different conventions due to for this. You cannot mix different conventions due to
unit-checking. unit-checking.
*/ */
SpaceType operator*(const FourVector& b); norm_type operator*(const FourVector& b);
/** @} */
protected: protected:
//! the data members //! the data members
TimeType fTimeLike; TTimeType timeLike_;
SpaceVecType fSpaceLike; TSpaceVecType spaceLike_;
//! the friends: math operators
template <typename T, typename U>
friend FourVector<typename std::decay<T>::type, typename std::decay<U>::type>
operator+(const FourVector<T, U>&, const FourVector<T, U>&);
template <typename T, typename U> /**
friend FourVector<typename std::decay<T>::type, typename std::decay<U>::type> * @defgroup the friends: (free) math operators
operator-(const FourVector<T, U>&, const FourVector<T, U>&); * @{
*
template <typename T, typename U> * We need to define them inline here since we do not want to
friend FourVector<typename std::decay<T>::type, typename std::decay<U>::type> * implement them as template functions. They are valid only for
operator*(const FourVector<T, U>&, const double); * the specific types as defined right here.
*
template <typename T, typename U> *
friend FourVector<typename std::decay<T>::type, typename std::decay<U>::type> * Note, these are "free function" (event if they don't look as
operator/(const FourVector<T, U>&, const double); * such). Thus, even if the input object uses internal references
* for storage, the free math operators, of course, must provide
* value-copies.
*
**/
friend FourVector<time_type, space_vec_type> operator+(FourVector const& a,
FourVector const& b) {
return FourVector<time_type, space_vec_type>(a.timeLike_ + b.timeLike_,
a.spaceLike_ + b.spaceLike_);
}
friend FourVector<time_type, space_vec_type> operator-(FourVector const& a,
FourVector const& b) {
return FourVector<time_type, space_vec_type>(a.timeLike_ - b.timeLike_,
a.spaceLike_ - b.spaceLike_);
}
friend FourVector<time_type, space_vec_type> operator*(FourVector const& a,
const double b) {
return FourVector<time_type, space_vec_type>(a.timeLike_ * b, a.spaceLike_ * b);
}
friend FourVector<time_type, space_vec_type> operator/(FourVector const& a,
double b) {
return FourVector<time_type, space_vec_type>(a.timeLike_ / b, a.spaceLike_ / b);
}
/** @} */
private: private:
/** /**
This function is automatically compiled to use of ignore the This function is there to automatically remove the eventual
extra factor of "c" for the time-like quantity extra factor of "c" for the time-like quantity.
*/ */
auto GetTimeSquared() const; norm_square_type getTimeSquared() const;
}; };
/**
The math operator+
*/
template <typename TimeType, typename SpaceVecType>
inline FourVector<typename std::decay<TimeType>::type,
typename std::decay<SpaceVecType>::type>
operator+(const FourVector<TimeType, SpaceVecType>& a,
const FourVector<TimeType, SpaceVecType>& b);
/**
The math operator-
*/
template <typename TimeType, typename SpaceVecType>
inline FourVector<typename std::decay<TimeType>::type,
typename std::decay<SpaceVecType>::type>
operator-(const FourVector<TimeType, SpaceVecType>& a,
const FourVector<TimeType, SpaceVecType>& b);
/**
The math operator*
FIXME: Add overload to deal with multiplication by a scalar and 3-vectors
*/
template <typename TimeType, typename SpaceVecType>
inline FourVector<typename std::decay<TimeType>::type,
typename std::decay<SpaceVecType>::type>
operator*(const FourVector<TimeType, SpaceVecType>& a, const double b);
/**
The math operator/
*/
template <typename TimeType, typename SpaceVecType>
inline FourVector<typename std::decay<TimeType>::type,
typename std::decay<SpaceVecType>::type>
operator/(const FourVector<TimeType, SpaceVecType>& a, const double b);
} // namespace corsika } // namespace corsika
#include <corsika/detail/framework/geometry/FourVector.inl> #include <corsika/detail/framework/geometry/FourVector.inl>
...@@ -38,8 +38,8 @@ TEST_CASE("four vectors") { ...@@ -38,8 +38,8 @@ TEST_CASE("four vectors") {
FourVector p0(E0, P0); FourVector p0(E0, P0);
REQUIRE(p0.GetNormSqr() == -200_GeV * 1_GeV); REQUIRE(p0.getNormSqr() == -200_GeV * 1_GeV);
REQUIRE(p0.GetNorm() == sqrt(200_GeV * 1_GeV)); REQUIRE(p0.getNorm() == sqrt(200_GeV * 1_GeV));
} }
/* /*
...@@ -56,17 +56,14 @@ TEST_CASE("four vectors") { ...@@ -56,17 +56,14 @@ TEST_CASE("four vectors") {
FourVector p1(E0, P1); FourVector p1(E0, P1);
FourVector p2(E0, P2); FourVector p2(E0, P2);
CHECK(p0.IsSpacelike()); CHECK(p0.isSpacelike());
CHECK(!p0.IsTimelike()); CHECK(!p0.isTimelike());
// CHECK(!p0.IsPhotonlike());
CHECK(!p1.IsSpacelike()); CHECK(!p1.isSpacelike());
CHECK(p1.IsTimelike()); CHECK(p1.isTimelike());
// CHECK(!p1.IsPhotonlike());
CHECK(!p2.IsSpacelike()); CHECK(!p2.isSpacelike());
CHECK(!p2.IsTimelike()); CHECK(!p2.isTimelike());
// CHECK(p2.IsPhotonlike());
} }
/* /*
...@@ -82,8 +79,8 @@ TEST_CASE("four vectors") { ...@@ -82,8 +79,8 @@ TEST_CASE("four vectors") {
const double check = 100 * 100 - 10 * 10 - 5 * 5 - 15 * 15; // for dummies... const double check = 100 * 100 - 10 * 10 - 5 * 5 - 15 * 15; // for dummies...
REQUIRE(p1.GetNormSqr() / 1_GeV / 1_GeV == Approx(check)); REQUIRE(p1.getNormSqr() / 1_GeV / 1_GeV == Approx(check));
REQUIRE(p1.GetNorm() / 1_GeV == Approx(sqrt(check))); REQUIRE(p1.getNorm() / 1_GeV == Approx(sqrt(check)));
} }
/** /**
...@@ -99,8 +96,8 @@ TEST_CASE("four vectors") { ...@@ -99,8 +96,8 @@ TEST_CASE("four vectors") {
FourVector p2(T2, P2); FourVector p2(T2, P2);
REQUIRE(p2.GetNormSqr() == check * 1_m * 1_m); REQUIRE(p2.getNormSqr() == check * 1_m * 1_m);
REQUIRE(p2.GetNorm() == sqrt(abs(check)) * 1_m); REQUIRE(p2.getNorm() == sqrt(abs(check)) * 1_m);
} }
/** /**
...@@ -118,35 +115,35 @@ TEST_CASE("four vectors") { ...@@ -118,35 +115,35 @@ TEST_CASE("four vectors") {
FourVector p1(E1, P1); FourVector p1(E1, P1);
const FourVector p2(E2, P2); const FourVector p2(E2, P2);
REQUIRE(p1.GetNorm() / 1_GeV == Approx(100.)); REQUIRE(p1.getNorm() / 1_GeV == Approx(100.));
REQUIRE(p2.GetNorm() / 1_GeV == Approx(10.)); REQUIRE(p2.getNorm() / 1_GeV == Approx(10.));
SECTION("product") { SECTION("product") {
FourVector p3 = p1 + p2; FourVector p3 = p1 + p2;
REQUIRE(p3.GetNorm() / 1_GeV == Approx(sqrt(100. * 100. - 100.))); REQUIRE(p3.getNorm() / 1_GeV == Approx(sqrt(100. * 100. - 100.)));
p3 -= p2; p3 -= p2;
REQUIRE(p3.GetNorm() / 1_GeV == Approx(100.)); REQUIRE(p3.getNorm() / 1_GeV == Approx(100.));
REQUIRE(p1.GetNorm() / 1_GeV == Approx(100.)); REQUIRE(p1.getNorm() / 1_GeV == Approx(100.));
REQUIRE(p2.GetNorm() / 1_GeV == Approx(10.)); REQUIRE(p2.getNorm() / 1_GeV == Approx(10.));
} }
SECTION("difference") { SECTION("difference") {
FourVector p3 = p1 - p2; FourVector p3 = p1 - p2;
REQUIRE(p3.GetNorm() / 1_GeV == Approx(sqrt(100. * 100. - 100.))); REQUIRE(p3.getNorm() / 1_GeV == Approx(sqrt(100. * 100. - 100.)));
p3 += p2; p3 += p2;
REQUIRE(p3.GetNorm() / 1_GeV == Approx(100.)); REQUIRE(p3.getNorm() / 1_GeV == Approx(100.));
REQUIRE(p1.GetNorm() / 1_GeV == Approx(100.)); REQUIRE(p1.getNorm() / 1_GeV == Approx(100.));
REQUIRE(p2.GetNorm() / 1_GeV == Approx(10.)); REQUIRE(p2.getNorm() / 1_GeV == Approx(10.));
} }
SECTION("scale") { SECTION("scale") {
double s = 10; double s = 10;
FourVector p3 = p1 * s; FourVector p3 = p1 * s;
REQUIRE(p3.GetNorm() / 1_GeV == Approx(sqrt(100. * 100. * s * s))); REQUIRE(p3.getNorm() / 1_GeV == Approx(sqrt(100. * 100. * s * s)));
p3 /= 10; p3 /= 10;
REQUIRE(p3.GetNorm() / 1_GeV == Approx(sqrt(100. * 100.))); REQUIRE(p3.getNorm() / 1_GeV == Approx(sqrt(100. * 100.)));
REQUIRE(p1.GetNorm() / 1_GeV == Approx(100.)); REQUIRE(p1.getNorm() / 1_GeV == Approx(100.));
REQUIRE(p2.GetNorm() / 1_GeV == Approx(10.)); REQUIRE(p2.getNorm() / 1_GeV == Approx(10.));
} }
} }
...@@ -177,8 +174,8 @@ TEST_CASE("four vectors") { ...@@ -177,8 +174,8 @@ TEST_CASE("four vectors") {
// p3 *= 10; // this does not compile, and it shoudn't !! // p3 *= 10; // this does not compile, and it shoudn't !!
const double check = 10 * 10 - 10 * 10 - 5 * 5 - 5 * 5; // for dummies... const double check = 10 * 10 - 10 * 10 - 5 * 5 - 5 * 5; // for dummies...
REQUIRE(p1.GetNormSqr() / (1_m * 1_m) == Approx(10. * 10. * check)); REQUIRE(p1.getNormSqr() / (1_m * 1_m) == Approx(10. * 10. * check));
REQUIRE(p2.GetNorm() / 1_m == Approx(10 * sqrt(abs(check)))); REQUIRE(p2.getNorm() / 1_m == Approx(10 * sqrt(abs(check))));
REQUIRE(p3.GetNorm() / 1_m == Approx(sqrt(abs(check)))); REQUIRE(p3.getNorm() / 1_m == Approx(sqrt(abs(check))));
} }
} }
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