From cc4d5259ccc6f5fd97dee2947adf605fe7999704 Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 2 May 2019 19:40:23 +0200 Subject: [PATCH] linmath: fix mat4.get_col3() and mat4.get_row3() when using Eigen --- panda/src/linmath/lmatrix4_src.I | 8 ------- tests/linmath/test_lmatrix4.py | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/panda/src/linmath/lmatrix4_src.I b/panda/src/linmath/lmatrix4_src.I index a887d393f1..fe8ba22bb7 100644 --- a/panda/src/linmath/lmatrix4_src.I +++ b/panda/src/linmath/lmatrix4_src.I @@ -484,13 +484,9 @@ get_col(int col) const { */ INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix4):: get_row3(int row) const { -#ifdef HAVE_EIGEN - return FLOATNAME(LVecBase3)(_m.block<1, 3>(row, 0)); -#else return FLOATNAME(LVecBase3)((*this)(row, 0), (*this)(row, 1), (*this)(row, 2)); -#endif // HAVE_EIGEN } /** @@ -514,13 +510,9 @@ get_row3(FLOATNAME(LVecBase3) &result_vec,int row) const { */ INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix4):: get_col3(int col) const { -#ifdef HAVE_EIGEN - return FLOATNAME(LVecBase3)(_m.block<1, 3>(0, col)); -#else return FLOATNAME(LVecBase3)((*this)(0, col), (*this)(1, col), (*this)(2, col)); -#endif // HAVE_EIGEN } /** diff --git a/tests/linmath/test_lmatrix4.py b/tests/linmath/test_lmatrix4.py index 23c1bcc5e9..05c487f807 100644 --- a/tests/linmath/test_lmatrix4.py +++ b/tests/linmath/test_lmatrix4.py @@ -87,3 +87,39 @@ def test_mat4_invert_correct(type): assert (mat * inv).is_identity() assert (inv * mat).is_identity() + + +@pytest.mark.parametrize("type", (core.LMatrix4d, core.LMatrix4f)) +def test_mat4_rows(type): + mat = type((1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 16)) + + assert mat.rows[0] == (1, 2, 3, 4) + assert mat.rows[1] == (5, 6, 7, 8) + assert mat.rows[2] == (9, 10, 11, 12) + assert mat.rows[3] == (13, 14, 15, 16) + + assert mat.get_row3(0) == (1, 2, 3) + assert mat.get_row3(1) == (5, 6, 7) + assert mat.get_row3(2) == (9, 10, 11) + assert mat.get_row3(3) == (13, 14, 15) + + +@pytest.mark.parametrize("type", (core.LMatrix4d, core.LMatrix4f)) +def test_mat4_cols(type): + mat = type((1, 5, 9, 13, + 2, 6, 10, 14, + 3, 7, 11, 15, + 4, 8, 12, 16)) + + assert mat.cols[0] == (1, 2, 3, 4) + assert mat.cols[1] == (5, 6, 7, 8) + assert mat.cols[2] == (9, 10, 11, 12) + assert mat.cols[3] == (13, 14, 15, 16) + + assert mat.get_col3(0) == (1, 2, 3) + assert mat.get_col3(1) == (5, 6, 7) + assert mat.get_col3(2) == (9, 10, 11) + assert mat.get_col3(3) == (13, 14, 15)