Debian Codegraph @

src/pycolmap/geometry/eigen_test.py

raw
1 import numpy as np
2
3 import pycolmap
4
5
6 def test_rotation3d_default_init():
7 rotation = pycolmap.Rotation3d()
8 assert rotation is not None
9
10
11 def test_rotation3d_init_from_xyzw():
12 rotation = pycolmap.Rotation3d(xyzw=np.array([0.0, 0.0, 0.0, 1.0]))
13 assert rotation is not None
14
15
16 def test_rotation3d_init_from_matrix():
17 rotation = pycolmap.Rotation3d(matrix=np.eye(3))
18 assert rotation is not None
19
20
21 def test_rotation3d_init_from_axis_angle():
22 rotation = pycolmap.Rotation3d(axis_angle=np.zeros(3))
23 assert rotation is not None
24
25
26 def test_rotation3d_from_buffer():
27 array = np.array([0.0, 0.0, 0.0, 1.0])
28 rotation = pycolmap.Rotation3d.from_buffer(array)
29 assert rotation is not None
30
31
32 def test_rotation3d_quat_readwrite():
33 rotation = pycolmap.Rotation3d()
34 quat = rotation.quat
35 assert quat.shape == (4,)
36 rotation.quat = np.array([0.0, 0.0, 0.0, 1.0])
37 np.testing.assert_array_almost_equal(rotation.quat, [0.0, 0.0, 0.0, 1.0])
38
39
40 def test_rotation3d_matrix():
41 rotation = pycolmap.Rotation3d(xyzw=np.array([0.0, 0.0, 0.0, 1.0]))
42 matrix = rotation.matrix()
43 assert matrix.shape == (3, 3)
44 np.testing.assert_array_almost_equal(matrix, np.eye(3))
45
46
47 def test_rotation3d_norm():
48 rotation = pycolmap.Rotation3d(xyzw=np.array([0.0, 0.0, 0.0, 1.0]))
49 assert isinstance(rotation.norm(), float)
50
51
52 def test_rotation3d_angle():
53 rotation = pycolmap.Rotation3d(axis_angle=np.zeros(3))
54 angle = rotation.angle()
55 assert isinstance(angle, float)
56 assert angle >= 0.0
57
58
59 def test_rotation3d_angle_to():
60 rotation1 = pycolmap.Rotation3d()
61 rotation2 = pycolmap.Rotation3d()
62 angle = rotation1.angle_to(rotation2)
63 assert isinstance(angle, float)
64
65
66 def test_rotation3d_inverse():
67 rotation = pycolmap.Rotation3d(xyzw=np.array([0.0, 0.0, 0.0, 1.0]))
68 inverse = rotation.inverse()
69 assert inverse is not None
70
71
72 def test_rotation3d_normalize():
73 rotation = pycolmap.Rotation3d(xyzw=np.array([0.0, 0.0, 0.0, 1.0]))
74 rotation.normalize()
75 assert abs(rotation.norm() - 1.0) < 1e-10
76
77
78 def test_rotation3d_multiply_rotation3d():
79 rotation1 = pycolmap.Rotation3d()
80 rotation2 = pycolmap.Rotation3d()
81 result = rotation1 * rotation2
82 assert result is not None
83
84
85 def test_rotation3d_multiply_vector3d():
86 rotation = pycolmap.Rotation3d()
87 vector = np.array([1.0, 2.0, 3.0])
88 result = rotation * vector
89 assert result.shape == (3,)
90
91
92 def test_rotation3d_multiply_nx3_matrix():
93 rotation = pycolmap.Rotation3d()
94 points = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
95 result = rotation * points
96 assert result.shape == (2, 3)
97
98
99 def test_alignedbox3d_default_init():
100 bbox = pycolmap.AlignedBox3d()
101 assert bbox is not None
102
103
104 def test_alignedbox3d_init_min_max():
105 bbox = pycolmap.AlignedBox3d(
106 min=np.array([0.0, 0.0, 0.0]),
107 max=np.array([1.0, 1.0, 1.0]),
108 )
109 assert bbox is not None
110
111
112 def test_alignedbox3d_min_max_readwrite():
113 bbox = pycolmap.AlignedBox3d(
114 min=np.array([0.0, 0.0, 0.0]),
115 max=np.array([1.0, 1.0, 1.0]),
116 )
117 np.testing.assert_array_almost_equal(bbox.min, [0.0, 0.0, 0.0])
118 np.testing.assert_array_almost_equal(bbox.max, [1.0, 1.0, 1.0])
119 bbox.min = np.array([-1.0, -1.0, -1.0])
120 bbox.max = np.array([2.0, 2.0, 2.0])
121 np.testing.assert_array_almost_equal(bbox.min, [-1.0, -1.0, -1.0])
122 np.testing.assert_array_almost_equal(bbox.max, [2.0, 2.0, 2.0])
123
124
125 def test_alignedbox3d_diagonal():
126 bbox = pycolmap.AlignedBox3d(
127 min=np.array([0.0, 0.0, 0.0]),
128 max=np.array([1.0, 2.0, 3.0]),
129 )
130 diagonal = bbox.diagonal()
131 np.testing.assert_array_almost_equal(diagonal, [1.0, 2.0, 3.0])
132
133
134 def test_alignedbox3d_contains_point_inside():
135 bbox = pycolmap.AlignedBox3d(
136 min=np.array([0.0, 0.0, 0.0]),
137 max=np.array([1.0, 1.0, 1.0]),
138 )
139 assert bbox.contains_point(np.array([0.5, 0.5, 0.5]))
140
141
142 def test_alignedbox3d_contains_point_outside():
143 bbox = pycolmap.AlignedBox3d(
144 min=np.array([0.0, 0.0, 0.0]),
145 max=np.array([1.0, 1.0, 1.0]),
146 )
147 assert not bbox.contains_point(np.array([2.0, 2.0, 2.0]))
148
149
150 def test_alignedbox3d_contains_bbox():
151 outer = pycolmap.AlignedBox3d(
152 min=np.array([0.0, 0.0, 0.0]),
153 max=np.array([10.0, 10.0, 10.0]),
154 )
155 inner = pycolmap.AlignedBox3d(
156 min=np.array([1.0, 1.0, 1.0]),
157 max=np.array([2.0, 2.0, 2.0]),
158 )
159 assert outer.contains_bbox(inner)
160 assert not inner.contains_bbox(outer)