From 623f21aedd9a0fcdef5db9efd9a05e9d73815bd3 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Tue, 7 Jun 2022 17:27:15 +0200 Subject: [PATCH] proper zero values for vectors --- src/core/include/pw/core/point.hpp | 2 +- src/core/include/pw/core/vector.hpp | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/include/pw/core/point.hpp b/src/core/include/pw/core/point.hpp index a07a1a3..5a541ca 100644 --- a/src/core/include/pw/core/point.hpp +++ b/src/core/include/pw/core/point.hpp @@ -32,7 +32,7 @@ struct point_ { using value_type = T_; - T_ x, y; + T_ x {0}, y {0}; point_() = default; point_(T_ x_,T_ y_) : x(x_), y(y_) {} diff --git a/src/core/include/pw/core/vector.hpp b/src/core/include/pw/core/vector.hpp index 05ae7fa..08a28d3 100644 --- a/src/core/include/pw/core/vector.hpp +++ b/src/core/include/pw/core/vector.hpp @@ -54,6 +54,8 @@ struct vector2_ : matrix_<2,1,T> { return std::acos( dot( a.normalized(), b.normalized() ) ); } + static constexpr auto zero() { return vector2_(0,0); } + }; template @@ -84,7 +86,9 @@ struct vector3_ : matrix_<3,1,T> { inline auto xy() const { return vector2_( { x(),y() } ); } inline auto homogenous(T w = 1) const { return matrix_<4,1,T>( { x(),y(),z(),w } ); } - inline static constexpr vector3_ cross(const vector3_& lhs,const vector3_& rhs) { + inline static constexpr vector3_ cross(const vector3_& lhs, + const vector3_& rhs) + { return vector3_( { lhs[1] * rhs[2] - rhs[1] * lhs[2], lhs[2] * rhs[0] - rhs[2] * lhs[0], @@ -104,6 +108,8 @@ struct vector3_ : matrix_<3,1,T> { inline static vector3_ x_axis() { return vector3_ ( { T(1), T(0), T(0) } ); } inline static vector3_ y_axis() { return vector3_ ( { T(0), T(1), T(0) } ); } inline static vector3_ z_axis() { return vector3_ ( { T(0), T(0), T(1) } ); } + + static constexpr auto zero() { return vector3_(0,0,0); } }; template @@ -134,6 +140,8 @@ struct vector4_ : matrix_<4,1,T> { inline auto project() const { return vector3_({ x()/w(),y()/w(),z()/w() } ); } + static constexpr auto zero() { return vector2_(0,0,0,0); } + }; //