feat(pose_3d): POST /apply + quaternion normalization
This commit is contained in:
1 parent
71f2ef596e
commit
40c3fff755
3 files changed
+154
No files matched your search
@@ -0,0 +1,32 @@
|
||||
"""Unit test della normalizzazione quaternion server-side."""
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from presa_mano.api.pose_3d_routes import normalize_quaternion
|
||||
|
||||
|
||||
def test_already_normalized_is_unchanged():
|
||||
q = [0.0, 0.0, 0.0, 1.0]
|
||||
out = normalize_quaternion(q)
|
||||
assert np.allclose(out, q)
|
||||
|
||||
|
||||
def test_not_normalized_gets_normalized_to_unit_length():
|
||||
# scala 2.0
|
||||
q = [0.0, 0.0, 0.0, 2.0]
|
||||
out = normalize_quaternion(q)
|
||||
norm = math.sqrt(sum(x*x for x in out))
|
||||
assert abs(norm - 1.0) < 1e-9
|
||||
|
||||
|
||||
def test_degenerate_zero_quat_raises():
|
||||
with pytest.raises(ValueError, match="degenerate"):
|
||||
normalize_quaternion([0.0, 0.0, 0.0, 0.0])
|
||||
|
||||
|
||||
def test_near_zero_quat_raises():
|
||||
with pytest.raises(ValueError, match="degenerate"):
|
||||
normalize_quaternion([1e-9, 0.0, 0.0, 1e-9])
|
||||
Reference in new issue
Block a user