Spaces:
Building
Building
File size: 1,782 Bytes
e3df007 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from animated_drawings.model.transform import Transform
from animated_drawings.model.quaternions import Quaternions
import numpy as np
def test_init():
t = Transform()
for m in [t._rotate_m, t._translate_m, t._scale_m, t._local_transform, t._world_transform]:
assert np.array_equal(m, np.identity(4))
def test_set_position():
t = Transform()
t.set_position(np.array([1.0, 1.0, 1.0]))
t.set_position(np.array([2.0, 2.0, 2.0]))
t.update_transforms()
assert np.array_equal(
t._local_transform[:-1, -1], np.array([2.0, 2.0, 2.0]))
def test_offset():
t = Transform()
t.offset(np.array([1.0, 1.0, 1.0]))
t.offset(np.array([2.0, 2.0, 2.0]))
t.update_transforms()
assert np.array_equal(
t._local_transform[:-1, -1], np.array([3.0, 3.0, 3.0]))
def test_update_transforms():
t1 = Transform()
t2 = Transform()
t1.add_child(t2)
t1.set_position(np.array([3.0, 0.0, 0.0]))
t1.update_transforms()
assert np.array_equal(
t2._world_transform[:-1, -1], np.array([3.0, 0.0, 0.0]))
def test_rotate():
t = Transform()
q = Quaternions.from_euler_angles('y', np.array([-90]))
t.set_rotation(q)
t.update_transforms()
m = np.identity(4)
m[0, 0] = 0.0
m[2, 0] = 1.0
m[2, 2] = 0.0
m[0, 2] = -1.0
assert np.isclose(t._local_transform, m).all()
def test_look_at():
t = Transform()
fwd = np.array([0, 0, -1])
t.look_at(fwd)
t.update_transforms()
m = np.identity(4)
m[0, 0] = -1.0
m[2, 2] = -1.0
assert np.isclose(t._local_transform, m).all()
|