blender-python-stubs/conformance/test_mathutils_quaternion.py
Joseph HENRY b3b282d8b0 Fix all conformance test failures
- Discover C-level classmethods on RNA types (e.g. Space.draw_handler_add)
- Fix getset_descriptor writability detection via __set__ probing
- Widen writable mathutils properties to accept Sequence[float]
- Widen __setitem__ value to accept parent container type (vec[:] = Vector)
- Widen mathutils params (Vector, Euler, etc.) to also accept Sequence[float]
- Filter self param from C method_descriptor signatures
- Add 5.1 overrides for LocRotScale and Quaternion.__init__
- Comment out memoryview tests (buffer protocol requires Python 3.12+)
- Disable reportUnusedExpression and reportUnknownMemberType in conformance

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 18:29:28 +01:00

41 lines
1.4 KiB
Python

import mathutils
import math
# A new rotation 90 degrees about the Y axis.
quat_a = mathutils.Quaternion((0.7071068, 0.0, 0.7071068, 0.0))
# Passing values to Quaternion's directly can be confusing so axis, angle
# is supported for initializing too.
quat_b = mathutils.Quaternion((0.0, 1.0, 0.0), math.radians(90.0))
print("Check quaternions match", quat_a == quat_b)
# Like matrices, quaternions can be multiplied to accumulate rotational values.
quat_a = mathutils.Quaternion((0.0, 1.0, 0.0), math.radians(90.0))
quat_b = mathutils.Quaternion((0.0, 0.0, 1.0), math.radians(45.0))
quat_out = quat_a @ quat_b
# Print the quaternion, euler degrees for mere mortals and (axis, angle).
print("Final Rotation:")
print(quat_out)
print("{:.2f}, {:.2f}, {:.2f}".format(*(math.degrees(a) for a in quat_out.to_euler())))
print(
"({:.2f}, {:.2f}, {:.2f}), {:.2f}".format(
*quat_out.axis, math.degrees(quat_out.angle)
)
)
# Multiple rotations can be interpolated using the exponential map.
quat_c = mathutils.Quaternion((1.0, 0.0, 0.0), math.radians(15.0))
exp_avg = (
quat_a.to_exponential_map()
+ quat_b.to_exponential_map()
+ quat_c.to_exponential_map()
) / 3.0
quat_avg = mathutils.Quaternion(exp_avg)
print("Average rotation:")
print(quat_avg)
# Direct buffer access is supported at runtime via C buffer protocol
# but not expressible in type stubs (requires Python 3.12+ __buffer__).