-
Notifications
You must be signed in to change notification settings - Fork 2
/
bresenham_tests.py
145 lines (135 loc) · 4.56 KB
/
bresenham_tests.py
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import unittest
import notebook_loader
from Bresenham3D import bresenham
import numpy as np
class Bresenham3dTestCase(unittest.TestCase):
def test_straight_line_along_x(self):
a = np.zeros((10, 10, 10), dtype=np.float32)
start = np.array([0, 1, 2], dtype=np.float32)
target = np.array([5, 1, 2], dtype=np.float32)
step_size = 0.5
voxels = bresenham(start, target, a, step_size=step_size)
self.assertAlmostEqual(np.max(np.abs(np.array(voxels) - np.array([
[0, 2, 4],
[1, 2, 4],
[2, 2, 4],
[3, 2, 4],
[4, 2, 4],
[5, 2, 4],
[6, 2, 4],
[7, 2, 4],
[8, 2, 4],
[9, 2, 4],
[10, 2, 4]
], dtype=np.float32))), 0)
def test_straight_line_along_y(self):
a = np.zeros((10, 10, 10), dtype=np.float32)
start = np.array([0, 0, 2], dtype=np.float32)
target = np.array([0, 5, 2], dtype=np.float32)
step_size = 0.5
voxels = bresenham(start, target, a, step_size=step_size)
self.assertAlmostEqual(np.max(np.abs(np.array(voxels) - np.array([
[0, 0, 4],
[0, 1, 4],
[0, 2, 4],
[0, 3, 4],
[0, 4, 4],
[0, 5, 4],
[0, 6, 4],
[0, 7, 4],
[0, 8, 4],
[0, 9, 4],
[0, 10, 4]
], dtype=np.float32))), 0)
def test_straight_line_along_z(self):
a = np.zeros((10, 10, 10), dtype=np.float32)
start = np.array([0, 5, 0], dtype=np.float32)
target = np.array([0, 5, 5], dtype=np.float32)
step_size = 0.5
voxels = bresenham(start, target, a, step_size=step_size)
self.assertAlmostEqual(np.max(np.abs(np.array(voxels) - np.array([
[0, 10, 0],
[0, 10, 1],
[0, 10, 2],
[0, 10, 3],
[0, 10, 4],
[0, 10, 5],
[0, 10, 6],
[0, 10, 7],
[0, 10, 8],
[0, 10, 9],
[0, 10, 10]
], dtype=np.float32))), 0)
def test_diagonal(self):
a = np.zeros((10, 10, 10), dtype=np.float32)
start = np.array([0, 0, 0], dtype=np.float32)
target = np.array([5, 5, 5], dtype=np.float32)
step_size = 0.5
voxels = bresenham(start, target, a, step_size=step_size)
self.assertAlmostEqual(np.max(np.abs(np.array(voxels) - np.array([
[0, 0, 0],
[1, 1, 1],
[2, 2, 2],
[3, 3, 3],
[4, 4, 4],
[5, 5, 5],
[6, 6, 6],
[7, 7, 7],
[8, 8, 8],
[9, 9, 9],
[10, 10, 10]
], dtype=np.float32))), 0)
def test_diagonal_step1(self):
a = np.zeros((10, 10, 10), dtype=np.float32)
start = np.array([0, 0, 0], dtype=np.float32)
target = np.array([10, 10, 10], dtype=np.float32)
step_size = 1.0
voxels = bresenham(start, target, a, step_size=step_size)
self.assertAlmostEqual(np.max(np.abs(np.array(voxels) - np.array([
[0, 0, 0],
[1, 1, 1],
[2, 2, 2],
[3, 3, 3],
[4, 4, 4],
[5, 5, 5],
[6, 6, 6],
[7, 7, 7],
[8, 8, 8],
[9, 9, 9],
[10, 10, 10]
], dtype=np.float32))), 0)
def test_diagonal_step2(self):
a = np.zeros((5, 5, 5), dtype=np.float32)
start = np.array([0, 0, 0], dtype=np.float32)
target = np.array([10, 10, 10], dtype=np.float32)
step_size = 2.0
voxels = bresenham(start, target, a, step_size=step_size)
self.assertAlmostEqual(np.max(np.abs(np.array(voxels) - np.array([
[0, 0, 0],
[1, 1, 1],
[2, 2, 2],
[3, 3, 3],
[4, 4, 4],
[5, 5, 5]
], dtype=np.float32))), 0)
def test_diagonal_reversed(self):
a = np.zeros((10, 10, 10), dtype=np.float32)
start = np.array([5, 5, 5], dtype=np.float32)
target = np.array([0, 0, 0], dtype=np.float32)
step_size = 0.5
voxels = bresenham(start, target, a, step_size=step_size)
self.assertAlmostEqual(np.max(np.abs(np.array(voxels) - np.array([
[10, 10, 10],
[9, 9, 9],
[8, 8, 8],
[7, 7, 7],
[6, 6, 6],
[5, 5, 5],
[4, 4, 4],
[3, 3, 3],
[2, 2, 2],
[1, 1, 1],
[0, 0, 0]
], dtype=np.float32))), 0)
if __name__ == '__main__':
unittest.main()