Commit 1572c45b authored by Matt Clarkson's avatar Matt Clarkson

Issue #10: Add function to check if something looks like 4x4 matrix.

parent 4e7d7170
Pipeline #1285 passed with stages
in 29 minutes and 9 seconds
......@@ -105,3 +105,22 @@ def validate_translation_column_vector(matrix):
if matrix.shape[1] != 1:
raise ValueError("Translation matrix should have 1 column.")
return True
def validate_rigid_matrix(matrix):
Validates that a matrix is a 4x4 rigid transform.
:param matrix: rigid transform
:raises: TypeError, ValueError if not
:return: True
if not isinstance(matrix, np.ndarray):
raise TypeError('Rigid matrix is not an np.ndarray')
if len(matrix.shape) != 2:
raise ValueError("Rigid matrix should have 2 dimensions.")
if matrix.shape[0] != 4:
raise ValueError("Rigid matrix should have 4 rows.")
if matrix.shape[1] != 4:
raise ValueError("Rigid matrix should have 4 columns.")
validate_rotation_matrix(matrix[0:3, 0:3])
......@@ -138,3 +138,27 @@ def test_translation_matrix_invalid_because_too_few_rows():
def test_translation_matrix_valid():
translation_matrix = np.zeros((3, 1))
assert vm.validate_translation_column_vector(translation_matrix)
def test_rigid_matrix_invalid_because_wrong_type():
with pytest.raises(TypeError):
def test_rigid_matrix_invalid_because_wrong_dimensions():
with pytest.raises(ValueError):
vm.validate_rigid_matrix(np.ones((2, 1, 2)))
def test_rigid_matrix_invalid_because_wrong_rows():
with pytest.raises(ValueError):
vm.validate_rigid_matrix(np.ones((2, 2)))
def test_rigid_matrix_invalid_because_wrong_columns():
with pytest.raises(ValueError):
vm.validate_rigid_matrix(np.ones((4, 2)))
def test_rigid_matrix_valid_because_identity():
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment