diff --git a/generation/bindings_templates/bindings.tmpl.pyi b/generation/bindings_templates/bindings.tmpl.pyi index a12c50b..4e2c883 100644 --- a/generation/bindings_templates/bindings.tmpl.pyi +++ b/generation/bindings_templates/bindings.tmpl.pyi @@ -13,7 +13,7 @@ from pandemonium.builtins import ( Dictionary, NodePath, Plane, - Quat, + Quaternion, Rect2, RID, Transform2D, @@ -94,7 +94,7 @@ class VariantType(IntFlag): VECTOR3: int TRANSFORM2D: int PLANE: int - QUAT: int + QUATERNION: int AABB: int BASIS: int TRANSFORM: int diff --git a/generation/bindings_templates/bindings.tmpl.pyx b/generation/bindings_templates/bindings.tmpl.pyx index d13d804..47d4594 100644 --- a/generation/bindings_templates/bindings.tmpl.pyx +++ b/generation/bindings_templates/bindings.tmpl.pyx @@ -75,7 +75,7 @@ class VariantType(IntFlag): VECTOR3 = pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_VECTOR3 TRANSFORM2D = pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_TRANSFORM2D PLANE = pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_PLANE - QUAT = pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_QUAT + QUATERNION = pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_QUATERNION AABB = pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_AABB BASIS = pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_BASIS TRANSFORM = pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_TRANSFORM diff --git a/generation/builtins_templates/basis.tmpl.pxi b/generation/builtins_templates/basis.tmpl.pxi index 6f4afac..5128d03 100644 --- a/generation/builtins_templates/basis.tmpl.pxi +++ b/generation/builtins_templates/basis.tmpl.pxi @@ -39,10 +39,10 @@ cdef class Basis: pass try: {{ force_mark_rendered("pandemonium_basis_new_with_euler_quat") }} - gdapi10.pandemonium_basis_new_with_euler_quat(&ret._gd_data, &(from_)._gd_data) + gdapi10.pandemonium_basis_new_with_euler_quat(&ret._gd_data, &(from_)._gd_data) return ret except TypeError: - raise TypeError('`from_` must be Quat or Vector3') + raise TypeError('`from_` must be Quaternion or Vector3') @staticmethod def from_axis_angle(Vector3 axis not None, phi): diff --git a/generation/builtins_templates/quat.tmpl.pxi b/generation/builtins_templates/quat.tmpl.pxi index ecac69a..86a2c7e 100644 --- a/generation/builtins_templates/quat.tmpl.pxi +++ b/generation/builtins_templates/quat.tmpl.pxi @@ -5,7 +5,7 @@ @cython.final -cdef class Quat: +cdef class Quaternion: {% block cdef_attributes %} cdef pandemonium_quat _gd_data {% endblock %} @@ -18,7 +18,7 @@ cdef class Quat: @staticmethod def from_axis_angle(Vector3 axis not None, pandemonium_real angle): # Call to __new__ bypasses __init__ constructor - cdef Quat ret = Quat.__new__(Quat) + cdef Quaternion ret = Quaternion.__new__(Quaternion) {{ force_mark_rendered("pandemonium_quat_new_with_axis_angle") }} gdapi10.pandemonium_quat_new_with_axis_angle(&ret._gd_data, &axis._gd_data, angle) return ret @@ -26,7 +26,7 @@ cdef class Quat: @staticmethod def from_basis(Basis basis not None): # Call to __new__ bypasses __init__ constructor - cdef Quat ret = Quat.__new__(Quat) + cdef Quaternion ret = Quaternion.__new__(Quaternion) {{ force_mark_rendered("pandemonium_quat_new_with_basis") }} gdapi11.pandemonium_quat_new_with_basis(&ret._gd_data, &basis._gd_data) return ret @@ -34,30 +34,30 @@ cdef class Quat: @staticmethod def from_euler(Vector3 euler not None): # Call to __new__ bypasses __init__ constructor - cdef Quat ret = Quat.__new__(Quat) + cdef Quaternion ret = Quaternion.__new__(Quaternion) {{ force_mark_rendered("pandemonium_quat_new_with_euler") }} gdapi11.pandemonium_quat_new_with_euler(&ret._gd_data, &euler._gd_data) return ret - def __repr__(Quat self): - return f"" + def __repr__(Quaternion self): + return f"" {{ render_operator_eq() | indent }} {{ render_operator_ne() | indent }} {{ render_method("operator_neg", py_name="__neg__") | indent }} - def __pos__(Quat self): + def __pos__(Quaternion self): return self {{ render_method("operator_add", py_name="__add__") | indent }} {{ render_method("operator_subtract", py_name="__sub__") | indent }} {{ render_method("operator_multiply", py_name="__mul__") | indent }} - def __truediv__(Quat self, pandemonium_real val): + def __truediv__(Quaternion self, pandemonium_real val): if val == 0: raise ZeroDivisionError - cdef Quat ret = Quat.__new__(Quat) + cdef Quaternion ret = Quaternion.__new__(Quaternion) {{ force_mark_rendered("pandemonium_quat_operator_divide") }} ret._gd_data = gdapi10.pandemonium_quat_operator_divide(&self._gd_data, val) return ret @@ -82,5 +82,5 @@ cdef class Quat: {% endblock %} {%- block python_consts %} - IDENTITY = Quat(0, 0, 0, 1) + IDENTITY = Quaternion(0, 0, 0, 1) {% endblock %} diff --git a/generation/builtins_templates/transform.tmpl.pxi b/generation/builtins_templates/transform.tmpl.pxi index 6f567ca..c275865 100644 --- a/generation/builtins_templates/transform.tmpl.pxi +++ b/generation/builtins_templates/transform.tmpl.pxi @@ -33,7 +33,7 @@ cdef class Transform: return ret @staticmethod - def from_quat(Quat quat not None): + def from_quat(Quaternion quat not None): cdef Transform ret = Transform.__new__(Transform) {{ force_mark_rendered("pandemonium_transform_new_with_quat") }} gdapi11.pandemonium_transform_new_with_quat(&ret._gd_data, &quat._gd_data) diff --git a/generation/generate_builtins.py b/generation/generate_builtins.py index 7ad0347..458f9a9 100644 --- a/generation/generate_builtins.py +++ b/generation/generate_builtins.py @@ -24,7 +24,7 @@ from type_specs import ( TYPE_RECT2, TYPE_TRANSFORM2D, TYPE_PLANE, - TYPE_QUAT, + TYPE_QUATERNION, TYPE_TRANSFORM, TYPE_NODEPATH, TYPE_DICTIONARY, @@ -137,7 +137,7 @@ TARGET_TO_TYPE_SPEC = { "rect2": TYPE_RECT2, "transform2d": TYPE_TRANSFORM2D, "plane": TYPE_PLANE, - "quat": TYPE_QUAT, + "quat": TYPE_QUATERNION, "transform": TYPE_TRANSFORM, "node_path": TYPE_NODEPATH, "dictionary": TYPE_DICTIONARY, diff --git a/generation/type_specs.py b/generation/type_specs.py index 6662f95..50b31e7 100644 --- a/generation/type_specs.py +++ b/generation/type_specs.py @@ -204,8 +204,8 @@ TYPE_STRING_NAME = TypeSpec( TYPE_PLANE = TypeSpec( gdapi_type="Plane", c_type="pandemonium_plane", cy_type="Plane", is_builtin=True, is_stack_only=True ) -TYPE_QUAT = TypeSpec( - gdapi_type="Quat", c_type="pandemonium_quat", cy_type="Quat", is_builtin=True, is_stack_only=True +TYPE_QUATERNION = TypeSpec( + gdapi_type="Quaternion", c_type="pandemonium_quat", cy_type="Quaternion", is_builtin=True, is_stack_only=True ) TYPE_RECT2 = TypeSpec( gdapi_type="Rect2", c_type="pandemonium_rect2", cy_type="Rect2", is_builtin=True, is_stack_only=True @@ -383,7 +383,7 @@ ALL_TYPES_EXCEPT_OBJECTS = [ TYPE_NODEPATH, TYPE_STRING_NAME, TYPE_PLANE, - TYPE_QUAT, + TYPE_QUATERNION, TYPE_RECT2, TYPE_RECT2I, TYPE_RID, diff --git a/pythonscript/pandemonium/_hazmat/conversion.pyx b/pythonscript/pandemonium/_hazmat/conversion.pyx index c34d4d2..46beafd 100644 --- a/pythonscript/pandemonium/_hazmat/conversion.pyx +++ b/pythonscript/pandemonium/_hazmat/conversion.pyx @@ -17,7 +17,7 @@ from pandemonium.builtins cimport ( Vector3, Transform2D, Plane, - Quat, + Quaternion, AABB, Basis, Transform, @@ -51,7 +51,7 @@ GD_PY_TYPES = ( (pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_VECTOR3, Vector3), (pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_TRANSFORM2D, Transform2D), (pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_PLANE, Plane), - (pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_QUAT, Quat), + (pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_QUATERNION, Quaternion), (pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_AABB, AABB), (pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_BASIS, Basis), (pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_TRANSFORM, Transform), @@ -143,7 +143,7 @@ cdef object pandemonium_variant_to_pyobj(const pandemonium_variant *p_gdvar): elif gdtype == pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_PLANE: return _pandemonium_variant_to_pyobj_plane(p_gdvar) - elif gdtype == pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_QUAT: + elif gdtype == pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_QUATERNION: return _pandemonium_variant_to_pyobj_quat(p_gdvar) elif gdtype == pandemonium_variant_type.PANDEMONIUM_VARIANT_TYPE_AABB: @@ -241,8 +241,8 @@ cdef inline Plane _pandemonium_variant_to_pyobj_plane(const pandemonium_variant return ret -cdef inline Quat _pandemonium_variant_to_pyobj_quat(const pandemonium_variant *p_gdvar): - cdef Quat ret = Quat.__new__(Quat) +cdef inline Quaternion _pandemonium_variant_to_pyobj_quat(const pandemonium_variant *p_gdvar): + cdef Quaternion ret = Quaternion.__new__(Quaternion) ret._gd_data = gdapi10.pandemonium_variant_as_quat(p_gdvar) return ret @@ -357,8 +357,8 @@ cdef bint pyobj_to_pandemonium_variant(object pyobj, pandemonium_variant *p_var) gdapi10.pandemonium_variant_new_vector3(p_var, &(pyobj)._gd_data) elif isinstance(pyobj, Plane): gdapi10.pandemonium_variant_new_plane(p_var, &(pyobj)._gd_data) - elif isinstance(pyobj, Quat): - gdapi10.pandemonium_variant_new_quat(p_var, &(pyobj)._gd_data) + elif isinstance(pyobj, Quaternion): + gdapi10.pandemonium_variant_new_quat(p_var, &(pyobj)._gd_data) elif isinstance(pyobj, AABB): gdapi10.pandemonium_variant_new_aabb(p_var, &(pyobj)._gd_data) elif isinstance(pyobj, Basis): diff --git a/tests/bindings/test_basis.py b/tests/bindings/test_basis.py index 7dccf50..44294e6 100644 --- a/tests/bindings/test_basis.py +++ b/tests/bindings/test_basis.py @@ -1,6 +1,6 @@ import pytest -from pandemonium import Basis, Vector3, Quat +from pandemonium import Basis, Vector3, Quaternion def test_default(): @@ -38,7 +38,7 @@ def test_bad_init_from_rows(args): [ ["from_axis_angle", (Vector3.ONE, 1.1)], ["from_euler", (Vector3.ONE,)], - ["from_euler", (Quat(),)], + ["from_euler", (Quaternion(),)], ], ) def test_inits(field, args): @@ -98,11 +98,11 @@ def test_repr(): ["scaled", Basis, (Vector3(),)], ["get_scale", Vector3, ()], ["get_euler", Vector3, ()], - ["get_quat", Quat, ()], - ["set_quat", type(None), (Quat(),)], + ["get_quat", Quaternion, ()], + ["set_quat", type(None), (Quaternion(),)], ["set_axis_angle_scale", type(None), (Vector3.ONE, 1.1, Vector3.ONE)], ["set_euler_scale", type(None), (Vector3.ONE, Vector3.ONE)], - ["set_quat_scale", type(None), (Quat(), Vector3.ONE)], + ["set_quat_scale", type(None), (Quaternion(), Vector3.ONE)], ["tdotx", float, (Vector3(),)], ["tdoty", float, (Vector3(),)], ["tdotz", float, (Vector3(),)], diff --git a/tests/bindings/test_quat.py b/tests/bindings/test_quat.py index f1f27a3..5c39156 100644 --- a/tests/bindings/test_quat.py +++ b/tests/bindings/test_quat.py @@ -1,11 +1,11 @@ import pytest -from pandemonium import Basis, Quat, Vector3 +from pandemonium import Basis, Quaternion, Vector3 def test_base(): - v = Quat() - assert type(v) == Quat + v = Quaternion() + assert type(v) == Quaternion @pytest.mark.parametrize( @@ -17,9 +17,9 @@ def test_base(): ], ) def test_inits(field, args): - build = getattr(Quat, field) + build = getattr(Quaternion, field) v = build(*args) - assert isinstance(v, Quat) + assert isinstance(v, Quaternion) @pytest.mark.parametrize( @@ -36,14 +36,14 @@ def test_inits(field, args): ], ) def test_bad_inits(field, args): - build = getattr(Quat, field) + build = getattr(Quaternion, field) with pytest.raises(TypeError): v = build(*args) def test_repr(): - v = Quat(1.0, 2.0, 3.0, 4.0) - assert repr(v) == "" + v = Quaternion(1.0, 2.0, 3.0, 4.0) + assert repr(v) == "" @pytest.mark.parametrize( @@ -59,7 +59,7 @@ def test_instantiate(args): # Can build it with int or float or nothing msg_tmpl = "%s vs (expected) %s (args=%s)" args, expected_x, expected_y, expected_z, expected_w = args - v = Quat(*args) + v = Quaternion(*args) assert pytest.approx(v.x) == expected_x, msg_tmpl % (v.x, expected_x, args) assert pytest.approx(v.y) == expected_y, msg_tmpl % (v.y, expected_y, args) assert pytest.approx(v.z) == expected_z, msg_tmpl % (v.z, expected_z, args) @@ -68,21 +68,21 @@ def test_instantiate(args): def test_bad_instantiate(): with pytest.raises(TypeError): - Quat("a", 2, 3, 4) + Quaternion("a", 2, 3, 4) with pytest.raises(TypeError): - Quat(1, "b", 2, 4) + Quaternion(1, "b", 2, 4) with pytest.raises(TypeError): - Quat(1, 2, "c", 4) + Quaternion(1, 2, "c", 4) with pytest.raises(TypeError): - Quat(1, 2, 3, "d") + Quaternion(1, 2, 3, "d") with pytest.raises(TypeError): - Quat(None, 2, 3, 4) + Quaternion(None, 2, 3, 4) with pytest.raises(TypeError): - Quat(1, None, 2, 4) + Quaternion(1, None, 2, 4) with pytest.raises(TypeError): - Quat(1, 2, None, 4) + Quaternion(1, 2, None, 4) with pytest.raises(TypeError): - Quat(1, 2, 3, None) + Quaternion(1, 2, 3, None) @pytest.mark.parametrize( @@ -90,20 +90,20 @@ def test_bad_instantiate(): [ ["length", float, ()], ["length_squared", float, ()], - ["normalized", Quat, ()], + ["normalized", Quaternion, ()], ["is_normalized", bool, ()], - ["inverse", Quat, ()], - ["dot", float, (Quat(),)], + ["inverse", Quaternion, ()], + ["dot", float, (Quaternion(),)], ["xform", Vector3, (Vector3(),)], - ["slerp", Quat, (Quat(), 1.0)], - ["slerpni", Quat, (Quat(), 1.0)], - ["cubic_slerp", Quat, (Quat(), Quat(), Quat(), 1.0)], + ["slerp", Quaternion, (Quaternion(), 1.0)], + ["slerpni", Quaternion, (Quaternion(), 1.0)], + ["cubic_slerp", Quaternion, (Quaternion(), Quaternion(), Quaternion(), 1.0)], ["set_axis_angle", type(None), (Vector3(1, 2, 3), 3.3)], ], ids=lambda x: x[0], ) def test_methods(field, ret_type, params): - v = Quat() + v = Quaternion() # Don't test methods' validity but bindings one assert hasattr(v, field) method = getattr(v, field) @@ -116,7 +116,7 @@ def test_methods(field, ret_type, params): "field,ret_type", [("x", float), ("y", float), ("z", float), ("w", float)], ids=lambda x: x[0] ) def test_properties(field, ret_type): - v = Quat() + v = Quaternion() assert hasattr(v, field) field_val = getattr(v, field) assert type(field_val) == ret_type @@ -141,13 +141,13 @@ def test_properties(field, ret_type): ids=lambda x: x[0], ) def test_bad_properties(field, bad_value): - v = Quat() + v = Quaternion() with pytest.raises(TypeError): setattr(v, field, bad_value) def test_unary(): - v = Quat(1, 2, 3, 4) + v = Quaternion(1, 2, 3, 4) v2 = -v assert v2.x == -1 assert v2.y == -2 @@ -158,7 +158,7 @@ def test_unary(): assert v3.y == 2 assert v3.z == 3 assert v3.w == 4 - v = Quat(1.5, 2.5, 3.5, 4.5) + v = Quaternion(1.5, 2.5, 3.5, 4.5) v2 = -v assert v2.x == -1.5 assert v2.y == -2.5 @@ -174,89 +174,89 @@ def test_unary(): @pytest.mark.parametrize( "param,result", [ - (Quat(0, 0, 0, 0), Quat(2, 3, 4, 5)), - (Quat(4, 3, 2, 1), Quat(6, 6, 6, 6)), - (Quat(-4, -3, -2, -1), Quat(-2, -0, 2, 4)), + (Quaternion(0, 0, 0, 0), Quaternion(2, 3, 4, 5)), + (Quaternion(4, 3, 2, 1), Quaternion(6, 6, 6, 6)), + (Quaternion(-4, -3, -2, -1), Quaternion(-2, -0, 2, 4)), ], ids=lambda x: x[0], ) def test_add(param, result): - calc = Quat(2, 3, 4, 5) + param + calc = Quaternion(2, 3, 4, 5) + param assert calc == result @pytest.mark.parametrize( "param,result", [ - (Quat(0, 0, 0, 0), Quat(2, 3, 4, 5)), - (Quat(5, 4, 3, 2), Quat(-3, -1, 1, 3)), - (Quat(-1, -1, -1, -1), Quat(3, 4, 5, 6)), + (Quaternion(0, 0, 0, 0), Quaternion(2, 3, 4, 5)), + (Quaternion(5, 4, 3, 2), Quaternion(-3, -1, 1, 3)), + (Quaternion(-1, -1, -1, -1), Quaternion(3, 4, 5, 6)), ], ids=lambda x: x[0], ) def test_sub(param, result): - calc = Quat(2, 3, 4, 5) - param + calc = Quaternion(2, 3, 4, 5) - param assert calc == result @pytest.mark.parametrize("arg", [None, 1, "dummy"], ids=lambda x: x[0]) def test_bad_add(arg): with pytest.raises(TypeError): - Quat(2, 3, 4, 5) + arg + Quaternion(2, 3, 4, 5) + arg @pytest.mark.parametrize("arg", [None, 1, "dummy"], ids=lambda x: x[0]) def test_bad_sub(arg): with pytest.raises(TypeError): - Quat(2, 3, 4, 5) - arg + Quaternion(2, 3, 4, 5) - arg -@pytest.mark.parametrize("arg", [None, "dummy", Quat(1, 1, 1, 1)], ids=lambda x: x[0]) +@pytest.mark.parametrize("arg", [None, "dummy", Quaternion(1, 1, 1, 1)], ids=lambda x: x[0]) def test_bad_div(arg): with pytest.raises(TypeError): - Quat(2, 3, 4, 5) / arg + Quaternion(2, 3, 4, 5) / arg def test_zero_div(): with pytest.raises(ZeroDivisionError): - Quat(2, 3, 4, 5) / 0 + Quaternion(2, 3, 4, 5) / 0 @pytest.mark.parametrize("arg", [None, "dummy"], ids=lambda x: x[0]) def test_bad_mul(arg): with pytest.raises(TypeError): - Quat(2, 3, 4, 5) * arg + Quaternion(2, 3, 4, 5) * arg @pytest.mark.parametrize( "param,result", - [(0, Quat(0, 0, 0, 0)), (1, Quat(2, 3, 4, 5)), (2.5, Quat(5, 7.5, 10, 12.5))], + [(0, Quaternion(0, 0, 0, 0)), (1, Quaternion(2, 3, 4, 5)), (2.5, Quaternion(5, 7.5, 10, 12.5))], ids=lambda x: x[0], ) def test_mul(param, result): - calc = Quat(2, 3, 4, 5) * param + calc = Quaternion(2, 3, 4, 5) * param assert calc == result @pytest.mark.parametrize( "param,result", - [(1, Quat(2, 3, 4, 5)), (0.5, Quat(4, 6, 8, 10)), (2, Quat(1, 1.5, 2, 2.5))], + [(1, Quaternion(2, 3, 4, 5)), (0.5, Quaternion(4, 6, 8, 10)), (2, Quaternion(1, 1.5, 2, 2.5))], ids=lambda x: x[0], ) def test_div(param, result): - calc = Quat(2, 3, 4, 5) / param + calc = Quaternion(2, 3, 4, 5) / param assert calc == result def test_equal(): - arr = Quat(0.1, 1, 2, 3) - other = Quat(0.1, 1, 2, 3) + arr = Quaternion(0.1, 1, 2, 3) + other = Quaternion(0.1, 1, 2, 3) assert arr == other - bad = Quat(0.1, 1, 2, 4) + bad = Quaternion(0.1, 1, 2, 4) assert not arr == bad # Force use of __eq__ -@pytest.mark.parametrize("arg", [None, 0, "foo", Quat(0.1, 1, 2, 4)]) +@pytest.mark.parametrize("arg", [None, 0, "foo", Quaternion(0.1, 1, 2, 4)]) def test_bad_equal(arg): - arr = Quat(0.1, 1, 2, 3) + arr = Quaternion(0.1, 1, 2, 3) assert arr != arg diff --git a/tests/bindings/test_string.py b/tests/bindings/test_string.py index 3a05ee6..42ffa22 100644 --- a/tests/bindings/test_string.py +++ b/tests/bindings/test_string.py @@ -6,7 +6,7 @@ from pandemonium import GDString def test_base(): assert GDString().empty() - # Todo later: GDString creation from GD types: Vector2/3, Transform, Plane, Quat, AABB, Color, ... + # Todo later: GDString creation from GD types: Vector2/3, Transform, Plane, Quaternion, AABB, Color, ... s = GDString("12") assert s.begins_with(GDString("1")) assert s.bigrams().size() == 1