From b17ca1d07d5726469e247e9326a56f8b2ee1644f Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 2 Apr 2018 17:57:20 +0200 Subject: Improve boundary cond impl via better vector support --- src/vector.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/vector.h b/src/vector.h index e0dc239..3a3ed5c 100644 --- a/src/vector.h +++ b/src/vector.h @@ -31,6 +31,10 @@ struct Vector { }; } + Vector operator-() const { + return -1 * *this; + } + Vector& operator+=(const Vector& rhs) { data[0] += rhs[0]; data[1] += rhs[1]; @@ -39,9 +43,25 @@ struct Vector { }; template -Vector operator*(T scalar, const Vector& vec) { +Vector operator*(T scalar, const Vector& v) { + return Vector{ + v[0] * scalar, + v[1] * scalar + }; +} + +template +Vector operator-(const Vector& a, const Vector& b) { + return Vector{ + a[0] - b[0], + a[1] - b[1] + }; +} + +template +Vector operator+(const Vector& a, const Vector& b) { return Vector{ - vec[0] * scalar, - vec[1] * scalar + a[0] + b[0], + a[1] + b[1] }; } -- cgit v1.2.3