From b2539e89f054b066ddbe0741d79553321d54a049 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Wed, 22 Nov 2017 14:21:18 +0000 Subject: Vector element-wise multiplication. --- src/math.hpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/math.hpp') diff --git a/src/math.hpp b/src/math.hpp index 2957d00..13eb36a 100644 --- a/src/math.hpp +++ b/src/math.hpp @@ -122,6 +122,24 @@ public: return v; } + friend vec_t operator^(const vec_t &a, const vec_t &b) + { + vec_t r; + + for (size_t i = 0; i < N; i++) + r[i] = a[i] * b[i]; + + return r; + } + + friend vec_t &operator^=(vec_t &v, const vec_t &b) + { + for (size_t i = 0; i < N; i++) + v[i] *= b[i]; + + return v; + } + friend T operator*(const vec_t &a, const vec_t &b) { T r = (T)0; @@ -209,6 +227,11 @@ public: return atan2(v[1], v[0]); } + vec_t norm(void) + { + return *this / len(); + } + // Compatibility with SFML template -- cgit