-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.bresenham-line.js
105 lines (98 loc) · 1.69 KB
/
test.bresenham-line.js
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
import test from 'tape';
import line from './src/bresenham-line';
function buildArray(fn, startPoint, finalPoint){
const arr = [];
for (const point of fn(startPoint, finalPoint)) {
arr.push(point);
}
return arr;
}
test('Bresenham\'s line algoritm ', (assert) => {
[
{
start: {
x: 1,
y: 1
},
final: {
x: 6,
y: 2
},
expect: [
{ x: 1, y: 1 },
{ x: 2, y: 1 },
{ x: 3, y: 1 },
{ x: 4, y: 2 },
{ x: 5, y: 2 },
{ x: 6, y: 2 }
]
},{
start: {
x: -1,
y: -1
},
final: {
x: -6,
y: -2
},
expect: [
{ x: -1, y: -1 },
{ x: -2, y: -1 },
{ x: -3, y: -1 },
{ x: -4, y: -2 },
{ x: -5, y: -2 },
{ x: -6, y: -2 }
]
}, {
start: {
x: 1,
y: 1
},
final: {
x: 2,
y: 5
},
expect: [
{ x: 1, y: 1 },
{ x: 1, y: 2 },
{ x: 2, y: 3 },
{ x: 2, y: 4 },
{ x: 2, y: 5 }
]
}, {
start: {
x: 3,
y: 3
},
final: {
x: 7,
y: -2
},
expect: [
{ x: 3, y: 3 },
{ x: 4, y: 2 },
{ x: 5, y: 1 },
{ x: 5, y: 0 },
{ x: 6, y: -1 },
{ x: 7, y: -2 }
]
}, {
start: {
x: 2,
y: 2
},
final: {
x: 2,
y: 2
},
expect: [
{ x: 2, y: 2 }
]
}
].forEach((ele) => {
const { start, final, expect } = ele;
const points = buildArray(line, start, final);
assert.deepEqual(points, expect);
});
assert.end();
});