Skip to content

Commit

Permalink
added matrix 2x2 inverse
Browse files Browse the repository at this point in the history
  • Loading branch information
sevec committed Jul 5, 2020
1 parent cf4a9bb commit 2118cff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class Matrix {
}
};

using Mat22f = Matrix<float, 2, 2>;
using Mat33f = Matrix<float, 3, 3>;
using Mat44f = Matrix<float, 4, 4>;

Expand Down Expand Up @@ -171,6 +172,16 @@ Matrix<T, Rows, Cols> transpose(const Matrix<T, Cols, Rows>& 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)) +
Expand Down
10 changes: 9 additions & 1 deletion UniformGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class UniformGrid {

UniformGrid(const Idxs& dims)
: dims_(dims) {
data_.resize(voxelCount());
data_.resize(voxelCount(), Object());
}

Object& operator()(const Idxs& idxs) {
Expand All @@ -80,6 +80,10 @@ class UniformGrid {
return cnt;
}

Idxs dimension() const {
return dims_;
}

GridIterator<Object, Dim> begin() {
return { data_.data(), 0, dims_ };
}
Expand All @@ -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;
Expand Down

0 comments on commit 2118cff

Please sign in to comment.