diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-05-20 09:55:00 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-05-20 09:55:00 -0600 |
commit | ffa152eab2f8b641d8750902fc4a6c79a4087771 (patch) | |
tree | a75f330cc629473d4e5b8dbfe7a66127de6884a3 | |
parent | f8507034753eca08c6f5dcab3e515a72d48e6aa0 (diff) | |
download | dimension-ffa152eab2f8b641d8750902fc4a6c79a4087771.tar.xz |
Fix Matrix repr() and tests.
-rw-r--r-- | libdimension-python/Matrix.c | 4 | ||||
-rwxr-xr-x | libdimension-python/tests/geometry.py | 38 |
2 files changed, 28 insertions, 14 deletions
diff --git a/libdimension-python/Matrix.c b/libdimension-python/Matrix.c index 0de8acc..b18b2d7 100644 --- a/libdimension-python/Matrix.c +++ b/libdimension-python/Matrix.c @@ -110,8 +110,8 @@ dmnsn_py_Matrix_repr(dmnsn_py_Matrix *self) return NULL; } - PyObject *repr = PyUnicode_FromFormat("dimension.Matrix(%R, %R, %R, %R," - "%R, %R, %R, %R," + PyObject *repr = PyUnicode_FromFormat("dimension.Matrix(%R, %R, %R, %R, " + "%R, %R, %R, %R, " "%R, %R, %R, %R)", floats[0][0], floats[0][1], floats[0][2], floats[0][3], diff --git a/libdimension-python/tests/geometry.py b/libdimension-python/tests/geometry.py index 8f76ef7..9c79ef5 100755 --- a/libdimension-python/tests/geometry.py +++ b/libdimension-python/tests/geometry.py @@ -51,15 +51,29 @@ assert v, bool(v) assert not Zero, not Zero assert proj(v, X) == 2*X, proj(v, X) -assert scale(1, 2, 3) == Matrix(1, 0, 0, 0, - 0, 2, 0, 0, - 0, 0, 3, 0), \ - scale(1, 2, 3) -assert translate(x = 1, y = 2, z = 3) == Matrix(1, 0, 0, 1, - 0, 1, 0, 2, - 0, 0, 1, 3), \ - translate(x = 1, y = 2, z = 3) -assert rotate(90*Y) == Matrix( 0, 0, 1, 0, - 0, 1, 0, 0, - -1, 0, 0, 0), \ - rotate(90*Y) +m = Matrix(1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12) + +assert repr(m) == 'dimension.Matrix(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, \ +9.0, 10.0, 11.0, 12.0)', repr(m) +assert str(m) == '\n' \ + '[1.0\t2.0\t3.0\t4.0]\n' \ + '[5.0\t6.0\t7.0\t8.0]\n' \ + '[9.0\t10.0\t11.0\t12.0]\n' \ + '[0.0\t0.0\t0.0\t1.0]', str(m) + +s = scale(1, 2, 3) +assert s == Matrix(1, 0, 0, 0, + 0, 2, 0, 0, + 0, 0, 3, 0), s + +t = translate(x = 1, y = 2, z = 3) +assert t == Matrix(1, 0, 0, 1, + 0, 1, 0, 2, + 0, 0, 1, 3), t + +r = rotate(90*Y).inverse() +assert r == Matrix(0, 0, -1, 0, + 0, 1, 0, 0, + 1, 0, 0, 0), r |