Files

39 lines
1.2 KiB
Python

import numpy as np
import pytest
import trimesh
from cxn.loader_common import AXIS_OPTIONS, apply_axis_remap, build_axis_remap
def test_axis_options_complete():
assert AXIS_OPTIONS == ["+X", "-X", "+Y", "-Y", "+Z", "-Z"]
def test_build_axis_remap_is_proper_rotation():
remap = build_axis_remap("+Y", "+Z")
assert np.allclose(remap @ remap.T, np.eye(3)) # orthonormal
assert np.isclose(np.linalg.det(remap), 1.0) # proper rotation
def test_build_axis_remap_rejects_parallel_axes():
with pytest.raises(RuntimeError):
build_axis_remap("+X", "-X") # anti-parallel
with pytest.raises(RuntimeError):
build_axis_remap("+X", "+X") # same axis
def test_apply_axis_remap_transforms_vertices():
box = trimesh.creation.box()
original = np.asarray(box.vertices, dtype=np.float64).copy()
scene = trimesh.Scene(box)
remap = build_axis_remap("+Y", "+Z")
out = apply_axis_remap(scene, remap)
geom = list(out.geometry.values())[0]
assert np.allclose(np.asarray(geom.vertices), original @ remap.T)
def test_apply_axis_remap_identity_is_noop():
scene = trimesh.Scene(trimesh.creation.box())
out = apply_axis_remap(scene, np.eye(3))
assert out is scene