From 2118cff623747e043935fc178d255cfe5250430a Mon Sep 17 00:00:00 2001 From: pavel Date: Sun, 5 Jul 2020 04:29:29 +0200 Subject: [PATCH] added matrix 2x2 inverse --- Matrix.hpp | 11 +++++++++++ UniformGrid.hpp | 10 +++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Matrix.hpp b/Matrix.hpp index 5c77035..10485da 100644 --- a/Matrix.hpp +++ b/Matrix.hpp @@ -128,6 +128,7 @@ class Matrix { } }; +using Mat22f = Matrix; using Mat33f = Matrix; using Mat44f = Matrix; @@ -171,6 +172,16 @@ Matrix transpose(const Matrix& m) { return tr; } +inline Mat22f invert(const Mat22f& m) { + float invdet = 1.f / (m(0, 0) * m(1, 1) - m(0, 1) * m(1, 0)); + Mat22f minv; + minv(0, 0) = m(1, 1) * invdet; + minv(0, 1) = -m(0, 1) * invdet; + minv(1, 0) = -m(1, 0) * invdet; + minv(1, 1) = m(0, 0) * invdet; + return minv; +} + inline Mat33f invert(const Mat33f& m) { double det = m(0, 0) * (m(1, 1) * m(2, 2) - m(2, 1) * m(1, 2)) - m(0, 1) * (m(1, 0) * m(2, 2) - m(1, 2) * m(2, 0)) + diff --git a/UniformGrid.hpp b/UniformGrid.hpp index 8b74563..34558c7 100644 --- a/UniformGrid.hpp +++ b/UniformGrid.hpp @@ -61,7 +61,7 @@ class UniformGrid { UniformGrid(const Idxs& dims) : dims_(dims) { - data_.resize(voxelCount()); + data_.resize(voxelCount(), Object()); } Object& operator()(const Idxs& idxs) { @@ -80,6 +80,10 @@ class UniformGrid { return cnt; } + Idxs dimension() const { + return dims_; + } + GridIterator begin() { return { data_.data(), 0, dims_ }; } @@ -96,6 +100,10 @@ class UniformGrid { return { data_.data() + data_.size(), 0, dims_ }; } + Object* data() { + return data_.data(); + } + private: std::size_t map(const Idxs& idxs) const { std::size_t linear = 0;