From 50446a55c83fd4bcc1cc4666cf2801cb5c5c9ba0 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Sun, 18 Mar 2018 19:52:31 -0400 Subject: [PATCH] Matrix add == and != operators --- matrix/Matrix.hpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/matrix/Matrix.hpp b/matrix/Matrix.hpp index 30b7fa929ea..4d4c238711d 100644 --- a/matrix/Matrix.hpp +++ b/matrix/Matrix.hpp @@ -288,6 +288,29 @@ public: *this = (*this) - scalar; } + bool operator==(const Matrix &other) const + { + const Matrix &self = *this; + + // TODO: set this based on Type + static constexpr float eps = 1e-4f; + + for (size_t i = 0; i < M; i++) { + for (size_t j = 0; j < N; j++) { + if (fabs(self(i, j) - other(i, j) > eps) ) { + return false; + } + } + } + + return true; + } + + bool operator!=(const Matrix &other) const + { + const Matrix &self = *this; + return !(self == other); + } /** * Misc. Functions