Skip to content

Commit

Permalink
Implement Matrix4x4.identity()
Browse files Browse the repository at this point in the history
  • Loading branch information
johningve committed Dec 5, 2024
1 parent 7c396d2 commit 9e42add
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions modules/zivid/matrix4x4.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ def save(self, file_path):
"""
super().save(str(file_path))

@staticmethod
def identity():
"""
Return the identity matrix.
Returns:
A new matrix, holding the identity matrix.
"""
return Matrix4x4(_zivid.Matrix4x4.identity())

def __getitem__(self, indexes):
"""
Access specified element with bounds checking.
Expand Down
1 change: 1 addition & 0 deletions src/Matrix4x4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void ZividPython::wrapClass(py::class_<Zivid::Matrix4x4> pyClass)
.def(py::init<const Matrix4x4 &>())
.def(py::init(&createMatrixFrom4x4Array))
.def(py::init<const std::string &>())
.def_static("identity", &Matrix4x4::identity<Matrix4x4::ValueType>)
.def("save", &Matrix4x4::save)
.def("load", &Matrix4x4::load)
.def("_getitem", &getItem)
Expand Down
6 changes: 6 additions & 0 deletions test/test_matrix4x4.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path
import tempfile
import numpy
import numpy as np
import numpy.testing
import pytest
import zivid
Expand Down Expand Up @@ -312,3 +313,8 @@ def test_implicit_convert_to_numpy():
pose2 = zivid.calibration.Pose(numpy.array(sample))

assert_all_equal_2d(zivid.Matrix4x4(pose1.to_matrix()), pose2.to_matrix())


def test_identity():
identity = zivid.Matrix4x4.identity()
assert np.array_equal(identity, np.identity(4, dtype=np.float32))

0 comments on commit 9e42add

Please sign in to comment.