Newer
Older
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from unittest import TestCase
import numpy as np
import orcasong.extractors.bundles as bundles
class TestGetPlanePositions(TestCase):
def setUp(self) -> None:
self.positions = np.array([
[0, 0, 0],
[0, 0, 5],
[5, 3, 2],
[0, 0, 2],
])
self.directions = np.array([
[0, 0, 1],
[0, 0, 1],
[0, 0, 1],
[0, 1, -1],
])
def test_positions_flat_plane(self):
plane_point = np.array([0, 0, 0])
plane_normal = np.array([0, 0, 1])
result = bundles.get_plane_positions(
self.positions, self.directions, plane_point, plane_normal,
)
target = np.array([
[0, 0],
[0, 0],
[5, 3],
[0, 2],
])
np.testing.assert_array_equal(result, target)
def test_positions_flat_plane_no_plane_normal(self):
plane_point = np.array([0, 0, 0])
with self.assertRaises(ValueError):
bundles.get_plane_positions(
self.positions, self.directions, plane_point,
)
def test_positions_shifted_plane(self):
plane_point = np.array([1, 0, 0])
plane_normal = np.array([0, 0, 1])
result = bundles.get_plane_positions(
self.positions, self.directions, plane_point, plane_normal,
)
target = np.array([
[-1, 0],
[-1, 0],
[4, 3],
[-1, 2],
])
np.testing.assert_array_equal(result, target)
def test_positions_angled_plane(self):
plane_point = np.array([0, 0, 0])
plane_normal = np.array([1, 0, 1])
result = bundles.get_plane_positions(
self.positions, self.directions, plane_point, plane_normal,
)
target = np.array([
[0, 0],
[0, 0],
[np.sqrt(50), 3],
[0, 2],
])
np.testing.assert_array_equal(result, target)
def test_positions_angled_plane_2(self):
result = bundles.get_plane_positions(
positions=np.array([[-1, 0, 1]]),
directions=np.array([[1, 0, -1]]),
plane_point=np.array([0, 0, 0]),
plane_normal=np.array([-1, 0, 1]),
)
np.testing.assert_array_equal(result, np.array([[0, 0]]))
class TestPairwiseDistances(TestCase):
def setUp(self) -> None:
self.positions_plane = np.array([
[0, -3],
[4, 0],
[0, 3],
])
def test_matrix(self):
result = bundles.get_pairwise_distances(
positions_plane=self.positions_plane,
as_matrix=True,
)
target = np.array([
[0, 5, 6],
[5, 0, 5],
[6, 5, 0],
])
np.testing.assert_array_equal(result, target)
def test_flat(self):
result = bundles.get_pairwise_distances(
positions_plane=self.positions_plane,
)
target = np.array([5, 6, 5])
np.testing.assert_array_equal(result, target)