[affine] fix for >1 vertex
This commit is contained in:
parent
031d93598d
commit
dd16f19004
2 changed files with 33 additions and 1 deletions
|
|
@ -68,3 +68,35 @@ def test_affine_rejects_zero_homogeneous_coordinate() -> None:
|
|||
|
||||
with pytest.raises(adze.AdzeError, match='zero homogeneous coordinate'):
|
||||
adze.transform.affine(poly, xform)
|
||||
|
||||
|
||||
def test_affine_identity_preserves_multiple_vertices() -> None:
|
||||
poly = {
|
||||
'vertices': numpy.array([
|
||||
[1.0, 0.0, 0.0],
|
||||
[2.0, 1.0, 0.0],
|
||||
]),
|
||||
'neighbors': numpy.empty((0, 3), dtype=int),
|
||||
}
|
||||
|
||||
transformed = adze.transform.affine(poly, numpy.eye(4))
|
||||
assert_allclose(transformed['vertices'], [[1.0, 0.0, 0.0], [2.0, 1.0, 0.0]])
|
||||
|
||||
|
||||
def test_affine_translation_applies_to_multiple_vertices() -> None:
|
||||
poly = {
|
||||
'vertices': numpy.array([
|
||||
[1.0, 0.0, 0.0],
|
||||
[2.0, 1.0, 0.0],
|
||||
]),
|
||||
'neighbors': numpy.empty((0, 3), dtype=int),
|
||||
}
|
||||
xform = numpy.array([
|
||||
[1.0, 0.0, 0.0, 1.0],
|
||||
[0.0, 1.0, 0.0, 2.0],
|
||||
[0.0, 0.0, 1.0, 3.0],
|
||||
[0.0, 0.0, 0.0, 1.0],
|
||||
])
|
||||
|
||||
transformed = adze.transform.affine(poly, xform)
|
||||
assert_allclose(transformed['vertices'], [[2.0, 2.0, 3.0], [3.0, 3.0, 3.0]])
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ def affine(poly: poly_t, xform: ArrayLike) -> poly_t:
|
|||
raise AdzeError('Affine transform matrix must contain only finite values')
|
||||
|
||||
mat4x3 = xform[:, :3]
|
||||
mat4x1 = xform[:, 3]
|
||||
mat4x1 = xform[:, 3:4]
|
||||
vh = mat4x3 @ poly['vertices'].T + mat4x1
|
||||
if numpy.any(vh[3, :] == 0):
|
||||
raise AdzeError('Affine transform produced points with zero homogeneous coordinate')
|
||||
|
|
|
|||
Loading…
Reference in a new issue