diff --git a/codegen/templates/transform_2d.pyx b/codegen/templates/transform_2d.pyx index bfc1499..c487fb9 100644 --- a/codegen/templates/transform_2d.pyx +++ b/codegen/templates/transform_2d.pyx @@ -246,12 +246,15 @@ cdef class Transform2D: return t def __imatmul__(self, Transform2D other) -> Transform2D: - self.xx = other.tdotx(self.xx, self.xy) - self.xy = other.tdoty(self.xx, self.xy) - self.yx = other.tdotx(self.yx, self.yy) - self.yy = other.tdoty(self.yx, self.yy) - self.ox = other.mulx(self.ox, self.oy) - self.oy = other.muly(self.ox, self.oy) + cdef py_float xx = other.tdotx(self.xx, self.xy) + cdef py_float xy = other.tdoty(self.xx, self.xy) + cdef py_float yx = other.tdotx(self.yx, self.yy) + cdef py_float yy = other.tdoty(self.yx, self.yy) + cdef py_float ox = other.mulx(self.ox, self.oy) + cdef py_float oy = other.muly(self.ox, self.oy) + self.xx, self.xy = xx, xy + self.yx, self.yy = yx, yy + self.ox, self.oy = ox, oy return self cdef inline py_float _determinant(self) noexcept: @@ -343,7 +346,7 @@ cdef class Transform2D: return t def rotate_ip(self, py_float rotation, /) -> Transform2D: - self.__imul__(Transform2D.rotation(rotation)) + self.__imatmul__(Transform2D.rotation(rotation)) return self def rotated(self, py_float rotation, /) -> Transform2D: diff --git a/codegen/templates/transform_3d.pyx b/codegen/templates/transform_3d.pyx index f8002a2..0d0c4fa 100644 --- a/codegen/templates/transform_3d.pyx +++ b/codegen/templates/transform_3d.pyx @@ -367,18 +367,22 @@ cdef class Transform3D: return t def __imatmul__(self, Transform3D other) -> Transform3D: - self.xx = other.tdotx(self.xx, self.xy, self.xz) - self.xy = other.tdoty(self.xx, self.xy, self.xz) - self.xz = other.tdotz(self.xx, self.xy, self.xz) - self.yx = other.tdotx(self.yx, self.yy, self.yz) - self.yy = other.tdoty(self.yx, self.yy, self.yz) - self.yz = other.tdotz(self.yx, self.yy, self.yz) - self.zx = other.tdotx(self.zx, self.zy, self.zz) - self.zy = other.tdoty(self.zx, self.zy, self.zz) - self.zz = other.tdotz(self.zx, self.zy, self.zz) - self.ox = other.mulx(self.ox, self.oy, self.oz) - self.oy = other.muly(self.ox, self.oy, self.oz) - self.oz = other.mulz(self.ox, self.oy, self.oz) + cdef py_float xx = other.tdotx(self.xx, self.xy, self.xz) + cdef py_float xy = other.tdoty(self.xx, self.xy, self.xz) + cdef py_float xz = other.tdotz(self.xx, self.xy, self.xz) + cdef py_float yx = other.tdotx(self.yx, self.yy, self.yz) + cdef py_float yy = other.tdoty(self.yx, self.yy, self.yz) + cdef py_float yz = other.tdotz(self.yx, self.yy, self.yz) + cdef py_float zx = other.tdotx(self.zx, self.zy, self.zz) + cdef py_float zy = other.tdoty(self.zx, self.zy, self.zz) + cdef py_float zz = other.tdotz(self.zx, self.zy, self.zz) + cdef py_float ox = other.mulx(self.ox, self.oy, self.oz) + cdef py_float oy = other.muly(self.ox, self.oy, self.oz) + cdef py_float oz = other.mulz(self.ox, self.oy, self.oz) + self.xx, self.xy, self.xz = xx, xy, xz + self.yx, self.yy, self.yz = yx, yy, yz + self.zx, self.zy, self.zz = zx, zy, zz + self.ox, self.oy, self.oz = ox, oy, oz return self cdef inline py_float _determinant(self) noexcept: @@ -424,7 +428,7 @@ cdef class Transform3D: return t def rotate_ip(self, Vec3 axis, py_float angle, /) -> Transform3D: - self.__imul__(Transform3D.rotating(axis, angle)) + self.__imatmul__(Transform3D.rotating(axis, angle)) return self def rotated(self, Vec3 axis, py_float angle, /) -> Transform3D: diff --git a/pyproject.toml b/pyproject.toml index 7bd712e..54e4d11 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = ["setuptools", "cython"] [project] name = "gdmath" -version = "1.4.1" +version = "1.4.2" description = "GdMath: a fast math library for game development" readme = "README.md" requires-python = ">= 3.9" diff --git a/tests/test_transform_2d.py b/tests/test_transform_2d.py index 9a27e91..87e4a11 100644 --- a/tests/test_transform_2d.py +++ b/tests/test_transform_2d.py @@ -71,6 +71,13 @@ def test_matmul(): assert (t1 @ t2).is_close(ans) assert t1(t2).is_close(ans) +def test_imatmul(): + t1 = Transform2D(1, 2, 3, 4, 5, 6) + t2 = Transform2D(3, 1, 2, 6, 5, 4) + t3 = Transform2D(t1) + t3 @= t2 + assert t2 @ t1 == t3 + def test_determinant(): assert isclose(Transform2D(1.6, 2.5, 3.4, 4.3, 5.2, 6.1).determinant, -1.62) diff --git a/tests/test_transform_3d.py b/tests/test_transform_3d.py index 5daefb6..057cb5d 100644 --- a/tests/test_transform_3d.py +++ b/tests/test_transform_3d.py @@ -70,6 +70,13 @@ def test_matmul(): assert (t1 @ t2).is_close(ans) assert t1(t2).is_close(ans) +def test_imatmul(): + t1 = Transform3D(*range(1, 13)) + t2 = Transform3D(10, 8, 4, 6, 12, 7, 5, 3, 2, 1, 11, 9) + t3 = Transform3D(t1) + t3 @= t2 + assert t2 @ t1 == t3 + def test_determinant(): assert isclose(Transform3D(1.12, 2.11, 0, 0, 5.8, 6.7, 7.6, 8.5, 0, 1, 2, 3).determinant, 43.6572)