This repository has been archived by the owner on Jul 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
blur-test.js
79 lines (67 loc) · 2.39 KB
/
blur-test.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
const tape = require("tape"),
arrays = require("../");
require("./inDelta");
tape("blur() returns a default blur generator", function(test) {
const h = arrays.blur();
test.equal(h.radius(), 5);
test.equal(h.radiusX(), 5);
test.equal(h.radiusY(), 5);
test.equal(h.width(), undefined);
test.equal(h.value(), undefined);
test.end();
});
tape("blur() blurs in 1D", function(test) {
const h = arrays.blur();
test.deepEqual(
h.radius(1).width(0)([0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0]),
Object.assign([0, 0, 0, 1, 3, 6, 7, 6, 3, 1, 0, 0, 0, 0], { width: 14, height: 1 })
);
test.end();
});
tape("blur() blurs in 2D", function(test) {
const h = arrays.blur();
test.deepEqual(
h.width(4).radiusX(1).radiusY(1)([0, 0, 0, 0, 729, 0, 0, 0, 0, 0, 0, 0]),
Object.assign([117, 81, 36, 9, 117, 81, 36, 9, 117, 81, 36, 9], { width: 4, height: 3 })
);
test.end();
});
tape("blur().radiusY(0) blurs horizontally", function(test) {
const h = arrays.blur();
test.deepEqual(
h.width(4).radiusX(1).radiusY(0)([27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
Object.assign([13, 9, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0], { width: 4, height: 3 })
);
test.end();
});
tape("blur().radiusX(0) blurs vertically", function(test) {
const h = arrays.blur();
test.deepEqual(
h.width(4).radiusX(0).radiusY(1)([0, 0, 0, 27, 3, -9, 0, 0, 0, 0, 0, 0]),
Object.assign([1, -3, 0, 13, 1, -3, 0, 9, 1, -3, 0, 5], { width: 4, height: 3 })
);
test.end();
});
tape("blur().radius(0.5) does a fraction of blur", function(test) {
const h = arrays.blur().width(5), V = [0,0,0,0,0, 0,0,5184,0,0, 0,0,0,0,0];
test.deepEqual(
h.radius(0.5)(V),
Object.assign([64, 96, 544, 96, 64, 256, 384, 2176, 384, 256, 64, 96, 544, 96, 64], { width: 5, height: 3 })
);
test.end();
});
tape("blur().radius(1.2) does a fraction of blur", function(test) {
const h = arrays.blur(), V = [0,0,0,0,0, 0,0,1,0,0, 0,0,0,0,0];
const V1 = h.radius(1)(V);
const V2 = h.radius(2)(V);
for (let i = 0; i < V1.length; i++) V1[i] = 0.8 * V1[i] + 0.2 * V2[i];
test.inDelta(Array.from(h.radius(1.2)(V)), Array.from(V1));
test.end();
});
tape("blur().radius() returns the (average) radius", function(test) {
const h = arrays.blur();
test.equal(h.width(2).radiusX(1).radiusY(1).radius(), 1);
test.equal(h.width(2).radius(2).radius(), 2);
test.equal(h.width(2).radiusX(1).radiusY(5).radius(), 3);
test.end();
});