q5 2.10.6 → 2.10.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +35 -0
- package/package.json +3 -6
- package/q5-deno-server.js +38 -0
- package/q5-server.js +3 -3
- package/q5.js +20 -11
- package/q5.min.js +1 -1
- package/src/q5-2d-drawing.js +2 -2
- package/src/q5-canvas.js +14 -8
- package/src/q5-input.js +1 -1
- package/src/q5-webgpu-canvas.js +3 -0
- package/test/core.test.js +33 -0
- package/test/readme.md +5 -0
- package/.vscode/launch.json +0 -26
- package/.vscode/settings.json +0 -3
- package/bun.lockb +0 -0
- package/p5-tests/js/chai_helpers.js +0 -20
- package/p5-tests/js/mocha_setup.js +0 -2
- package/p5-tests/js/modernizr.js +0 -5
- package/p5-tests/js/p5_helpers.js +0 -135
- package/p5-tests/js/sinon.js +0 -5949
- package/p5-tests/mocha.css +0 -289
- package/p5-tests/test.html +0 -71
- package/p5-tests/unit/color/color_conversion.js +0 -68
- package/p5-tests/unit/color/creating_reading.js +0 -217
- package/p5-tests/unit/color/p5.Color.js +0 -1000
- package/p5-tests/unit/color/setting.js +0 -289
- package/p5-tests/unit/core/2d_primitives.js +0 -490
- package/p5-tests/unit/core/attributes.js +0 -115
- package/p5-tests/unit/core/curves.js +0 -139
- package/p5-tests/unit/core/environment.js +0 -248
- package/p5-tests/unit/core/error_helpers.js +0 -1158
- package/p5-tests/unit/core/main.js +0 -340
- package/p5-tests/unit/core/p5.Element.js +0 -773
- package/p5-tests/unit/core/p5.Graphics.js +0 -179
- package/p5-tests/unit/core/preload.js +0 -285
- package/p5-tests/unit/core/rendering.js +0 -116
- package/p5-tests/unit/core/structure.js +0 -293
- package/p5-tests/unit/core/transform.js +0 -144
- package/p5-tests/unit/core/version.js +0 -28
- package/p5-tests/unit/core/vertex.js +0 -137
- package/p5-tests/unit/dom/dom.js +0 -2146
- package/p5-tests/unit/events/acceleration.js +0 -213
- package/p5-tests/unit/events/keyboard.js +0 -179
- package/p5-tests/unit/events/mouse.js +0 -487
- package/p5-tests/unit/events/touch.js +0 -180
- package/p5-tests/unit/image/downloading.js +0 -379
- package/p5-tests/unit/image/filters.js +0 -92
- package/p5-tests/unit/image/loading.js +0 -413
- package/p5-tests/unit/image/p5.Image.js +0 -201
- package/p5-tests/unit/image/pixels.js +0 -234
- package/p5-tests/unit/io/files.js +0 -378
- package/p5-tests/unit/io/loadBytes.js +0 -149
- package/p5-tests/unit/io/loadImage.js +0 -123
- package/p5-tests/unit/io/loadJSON.js +0 -185
- package/p5-tests/unit/io/loadModel.js +0 -215
- package/p5-tests/unit/io/loadShader.js +0 -176
- package/p5-tests/unit/io/loadStrings.js +0 -140
- package/p5-tests/unit/io/loadTable.js +0 -183
- package/p5-tests/unit/io/loadXML.js +0 -127
- package/p5-tests/unit/io/saveModel.js +0 -113
- package/p5-tests/unit/io/saveTable.js +0 -142
- package/p5-tests/unit/math/calculation.js +0 -452
- package/p5-tests/unit/math/noise.js +0 -66
- package/p5-tests/unit/math/p5.Vector.js +0 -1886
- package/p5-tests/unit/math/random.js +0 -177
- package/p5-tests/unit/math/trigonometry.js +0 -144
- package/p5-tests/unit/spec.js +0 -50
- package/p5-tests/unit/typography/attributes.js +0 -120
- package/p5-tests/unit/typography/loadFont.js +0 -162
- package/p5-tests/unit/typography/p5.Font.js +0 -63
- package/p5-tests/unit/utilities/conversion.js +0 -329
- package/p5-tests/unit/utilities/time_date.js +0 -133
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
suite('saveModel',function() {
|
|
2
|
-
var myp5;
|
|
3
|
-
setup(function(done) {
|
|
4
|
-
new p5(function(p) {
|
|
5
|
-
p.setup = function() {
|
|
6
|
-
myp5 = p;
|
|
7
|
-
done();
|
|
8
|
-
};
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
teardown(function() {
|
|
12
|
-
myp5.remove();
|
|
13
|
-
});
|
|
14
|
-
testWithDownload(
|
|
15
|
-
'should download an .obj file with expected contents',
|
|
16
|
-
async function(blobContainer) {
|
|
17
|
-
//.obj content as a string
|
|
18
|
-
const objContent = `v 100 0 0
|
|
19
|
-
v 0 -100 0
|
|
20
|
-
v 0 0 -100
|
|
21
|
-
v 0 100 0
|
|
22
|
-
v 100 0 0
|
|
23
|
-
v 0 0 -100
|
|
24
|
-
v 0 100 0
|
|
25
|
-
v 0 0 100
|
|
26
|
-
v 100 0 0
|
|
27
|
-
v 0 100 0
|
|
28
|
-
v 0 0 -100
|
|
29
|
-
v -100 0 0
|
|
30
|
-
v -100 0 0
|
|
31
|
-
v 0 -100 0
|
|
32
|
-
v 0 0 100
|
|
33
|
-
v 0 0 -100
|
|
34
|
-
v 0 -100 0
|
|
35
|
-
v -100 0 0
|
|
36
|
-
v 0 100 0
|
|
37
|
-
v -100 0 0
|
|
38
|
-
v 0 0 100
|
|
39
|
-
v 0 0 100
|
|
40
|
-
v 0 -100 0
|
|
41
|
-
v 100 0 0
|
|
42
|
-
vt 0 0
|
|
43
|
-
vt 0 0
|
|
44
|
-
vt 0 0
|
|
45
|
-
vt 0 0
|
|
46
|
-
vt 0 0
|
|
47
|
-
vt 0 0
|
|
48
|
-
vt 0 0
|
|
49
|
-
vt 0 0
|
|
50
|
-
vt 0 0
|
|
51
|
-
vt 0 0
|
|
52
|
-
vt 0 0
|
|
53
|
-
vt 0 0
|
|
54
|
-
vt 0 0
|
|
55
|
-
vt 0 0
|
|
56
|
-
vt 0 0
|
|
57
|
-
vt 0 0
|
|
58
|
-
vt 0 0
|
|
59
|
-
vt 0 0
|
|
60
|
-
vt 0 0
|
|
61
|
-
vt 0 0
|
|
62
|
-
vt 0 0
|
|
63
|
-
vt 0 0
|
|
64
|
-
vt 0 0
|
|
65
|
-
vt 0 0
|
|
66
|
-
vn 0 0 1
|
|
67
|
-
vn 0 0 1
|
|
68
|
-
vn 0 0 1
|
|
69
|
-
vn 0 0 1
|
|
70
|
-
vn 0 0 1
|
|
71
|
-
vn 0 0 1
|
|
72
|
-
vn 0 0 1
|
|
73
|
-
vn 0 0 1
|
|
74
|
-
vn 0 0 1
|
|
75
|
-
vn 0 0 1
|
|
76
|
-
vn 0 0 1
|
|
77
|
-
vn 0 0 1
|
|
78
|
-
vn 0 0 1
|
|
79
|
-
vn 0 0 1
|
|
80
|
-
vn 0 0 1
|
|
81
|
-
vn 0 0 1
|
|
82
|
-
vn 0 0 1
|
|
83
|
-
vn 0 0 1
|
|
84
|
-
vn 0 0 1
|
|
85
|
-
vn 0 0 1
|
|
86
|
-
vn 0 0 1
|
|
87
|
-
vn 0 0 1
|
|
88
|
-
vn 0 0 1
|
|
89
|
-
vn 0 0 1
|
|
90
|
-
f 1 2 3
|
|
91
|
-
f 4 5 6
|
|
92
|
-
f 7 8 9
|
|
93
|
-
f 10 11 12
|
|
94
|
-
f 13 14 15
|
|
95
|
-
f 16 17 18
|
|
96
|
-
f 19 20 21
|
|
97
|
-
f 22 23 24
|
|
98
|
-
`;
|
|
99
|
-
|
|
100
|
-
const objBlob = new Blob([objContent], { type: 'text/plain' });
|
|
101
|
-
|
|
102
|
-
myp5.downloadFile(objBlob, 'model', 'obj');
|
|
103
|
-
|
|
104
|
-
let myBlob = blobContainer.blob;
|
|
105
|
-
|
|
106
|
-
let text = await myBlob.text();
|
|
107
|
-
|
|
108
|
-
assert.strictEqual(text, objContent);
|
|
109
|
-
},
|
|
110
|
-
true
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
});
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
suite('saveTable', function() {
|
|
2
|
-
let validFile = 'unit/assets/csv.csv';
|
|
3
|
-
let myp5;
|
|
4
|
-
let myTable;
|
|
5
|
-
|
|
6
|
-
setup(function(done) {
|
|
7
|
-
new p5(function(p) {
|
|
8
|
-
p.setup = function() {
|
|
9
|
-
myp5 = p;
|
|
10
|
-
done();
|
|
11
|
-
};
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
teardown(function() {
|
|
16
|
-
myp5.remove();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
setup(function disableFileLoadError() {
|
|
20
|
-
sinon.stub(p5, '_friendlyFileLoadError');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
teardown(function restoreFileLoadError() {
|
|
24
|
-
p5._friendlyFileLoadError.restore();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
setup(function loadMyTable(done) {
|
|
28
|
-
myp5.loadTable(validFile, 'csv', 'header', function(table) {
|
|
29
|
-
myTable = table;
|
|
30
|
-
done();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('should be a function', function() {
|
|
35
|
-
assert.ok(myp5.saveTable);
|
|
36
|
-
assert.typeOf(myp5.saveTable, 'function');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('no friendly-err-msg I', function() {
|
|
40
|
-
assert.doesNotThrow(
|
|
41
|
-
function() {
|
|
42
|
-
myp5.saveTable(myTable, 'myfile');
|
|
43
|
-
},
|
|
44
|
-
Error,
|
|
45
|
-
'got unwanted exception'
|
|
46
|
-
);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('no friendly-err-msg II', function() {
|
|
50
|
-
assert.doesNotThrow(
|
|
51
|
-
function() {
|
|
52
|
-
myp5.saveTable(myTable, 'myfile', 'csv');
|
|
53
|
-
},
|
|
54
|
-
Error,
|
|
55
|
-
'got unwanted exception'
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
testUnMinified('missing param #1', function() {
|
|
60
|
-
assert.validationError(function() {
|
|
61
|
-
myp5.saveTable(myTable);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
testUnMinified('wrong param type #0', function() {
|
|
66
|
-
assert.validationError(function() {
|
|
67
|
-
myp5.saveTable('myTable', 'myfile');
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
testUnMinified('wrong param type #1', function() {
|
|
72
|
-
assert.validationError(function() {
|
|
73
|
-
myp5.saveTable(myTable, 2);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
testUnMinified('wrong param type #2', function() {
|
|
78
|
-
assert.validationError(function() {
|
|
79
|
-
myp5.saveTable(myTable, 'myfile', 2);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
testWithDownload(
|
|
84
|
-
'should download a file with expected contents',
|
|
85
|
-
async function(blobContainer) {
|
|
86
|
-
myp5.saveTable(myTable, 'filename');
|
|
87
|
-
let myBlob = blobContainer.blob;
|
|
88
|
-
let text = await myBlob.text();
|
|
89
|
-
let myTableStr = myTable.columns.join(',') + '\n';
|
|
90
|
-
for (let i = 0; i < myTable.rows.length; i++) {
|
|
91
|
-
myTableStr += myTable.rows[i].arr.join(',') + '\n';
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
assert.strictEqual(text, myTableStr);
|
|
95
|
-
},
|
|
96
|
-
true
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
testWithDownload(
|
|
100
|
-
'should download a file with expected contents (tsv)',
|
|
101
|
-
async function(blobContainer) {
|
|
102
|
-
myp5.saveTable(myTable, 'filename', 'tsv');
|
|
103
|
-
let myBlob = blobContainer.blob;
|
|
104
|
-
let text = await myBlob.text();
|
|
105
|
-
let myTableStr = myTable.columns.join('\t') + '\n';
|
|
106
|
-
for (let i = 0; i < myTable.rows.length; i++) {
|
|
107
|
-
myTableStr += myTable.rows[i].arr.join('\t') + '\n';
|
|
108
|
-
}
|
|
109
|
-
assert.strictEqual(text, myTableStr);
|
|
110
|
-
},
|
|
111
|
-
true
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
testWithDownload(
|
|
115
|
-
'should download a file with expected contents (html)',
|
|
116
|
-
async function(blobContainer) {
|
|
117
|
-
myp5.saveTable(myTable, 'filename', 'html');
|
|
118
|
-
let myBlob = blobContainer.blob;
|
|
119
|
-
let text = await myBlob.text();
|
|
120
|
-
let domparser = new DOMParser();
|
|
121
|
-
let htmldom = domparser.parseFromString(text, 'text/html');
|
|
122
|
-
let trs = htmldom.querySelectorAll('tr');
|
|
123
|
-
for (let i = 0; i < trs.length; i++) {
|
|
124
|
-
let tds = trs[i].querySelectorAll('td');
|
|
125
|
-
for (let j = 0; j < tds.length; j++) {
|
|
126
|
-
// saveTable generates an HTML file with indentation spaces and line-breaks. The browser ignores these
|
|
127
|
-
// while displaying. But they will still remain a part of the parsed DOM and hence must be removed.
|
|
128
|
-
// More info at: https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Whitespace
|
|
129
|
-
let tdText = tds[j].innerHTML.trim().replace(/\n/g, '');
|
|
130
|
-
let tbText;
|
|
131
|
-
if (i === 0) {
|
|
132
|
-
tbText = myTable.columns[j].trim().replace(/\n/g, '');
|
|
133
|
-
} else {
|
|
134
|
-
tbText = myTable.rows[i - 1].arr[j].trim().replace(/\n/g, '');
|
|
135
|
-
}
|
|
136
|
-
assert.strictEqual(tdText, tbText);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
true
|
|
141
|
-
);
|
|
142
|
-
});
|
|
@@ -1,452 +0,0 @@
|
|
|
1
|
-
suite('Calculation', function() {
|
|
2
|
-
var myp5;
|
|
3
|
-
|
|
4
|
-
setup(function(done) {
|
|
5
|
-
new p5(function(p) {
|
|
6
|
-
p.setup = function() {
|
|
7
|
-
myp5 = p;
|
|
8
|
-
done();
|
|
9
|
-
};
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
teardown(function() {
|
|
14
|
-
myp5.remove();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
suite('p5.prototype.abs', function() {
|
|
18
|
-
var result;
|
|
19
|
-
test('should be a function', function() {
|
|
20
|
-
assert.ok(myp5.abs);
|
|
21
|
-
assert.typeOf(myp5.abs, 'function');
|
|
22
|
-
});
|
|
23
|
-
test('should return a number', function() {
|
|
24
|
-
result = myp5.abs();
|
|
25
|
-
assert.typeOf(result, 'number');
|
|
26
|
-
});
|
|
27
|
-
test('should return an absolute value', function() {
|
|
28
|
-
result = myp5.abs(-1);
|
|
29
|
-
assert.equal(result, 1);
|
|
30
|
-
assert.notEqual(result, -1);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
suite('p5.prototype.ceil', function() {
|
|
35
|
-
var result;
|
|
36
|
-
test('should be a function', function() {
|
|
37
|
-
assert.ok(myp5.ceil);
|
|
38
|
-
assert.typeOf(myp5.ceil, 'function');
|
|
39
|
-
});
|
|
40
|
-
test('should return ceil value given negative value', function() {
|
|
41
|
-
result = myp5.ceil(-1.9);
|
|
42
|
-
assert.equal(result, -1);
|
|
43
|
-
});
|
|
44
|
-
test('should return a ceil value given positive value', function() {
|
|
45
|
-
result = myp5.ceil(0.1);
|
|
46
|
-
assert.equal(result, 1);
|
|
47
|
-
});
|
|
48
|
-
test('should return same number', function() {
|
|
49
|
-
result = myp5.ceil(1);
|
|
50
|
-
assert.equal(result, 1);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
suite('p5.prototype.dist', function() {
|
|
55
|
-
var result;
|
|
56
|
-
test('should be a function', function() {
|
|
57
|
-
assert.ok(myp5.dist);
|
|
58
|
-
assert.typeOf(myp5.dist, 'function');
|
|
59
|
-
});
|
|
60
|
-
test('should return a number', function() {
|
|
61
|
-
result = myp5.dist(0, 0, 2, 3);
|
|
62
|
-
assert.typeOf(result, 'number');
|
|
63
|
-
});
|
|
64
|
-
test('should return correct distance', function() {
|
|
65
|
-
result = myp5.dist(0, 0, 2, 3);
|
|
66
|
-
assert.approximately(result, 3.605551, 0.000001); // Math.hypot(2, 3)
|
|
67
|
-
});
|
|
68
|
-
test('should return positive distance', function() {
|
|
69
|
-
result = myp5.dist(0, 0, -2, -3);
|
|
70
|
-
assert.approximately(result, 3.605551, 0.000001); // Math.hypot(2, 3)
|
|
71
|
-
});
|
|
72
|
-
test('should return correct distance', function() {
|
|
73
|
-
result = myp5.dist(0, 0, 0, 2, 3, 5);
|
|
74
|
-
assert.approximately(result, 6.164414, 0.000001); // Math.hypot(2, 3, 5)
|
|
75
|
-
});
|
|
76
|
-
test('should return positive distance', function() {
|
|
77
|
-
result = myp5.dist(0, 0, 0, -2, -3, 5);
|
|
78
|
-
assert.approximately(result, 6.164414, 0.000001); // Math.hypot(2, 3, 5)
|
|
79
|
-
});
|
|
80
|
-
test('should not underflow', function() {
|
|
81
|
-
result = myp5.dist(0, 0, 1e-200, 2e-200);
|
|
82
|
-
assert.notEqual(result, 0);
|
|
83
|
-
});
|
|
84
|
-
test('should not overflow', function() {
|
|
85
|
-
result = myp5.dist(0, 0, 1e200, 2e200);
|
|
86
|
-
assert.notEqual(result, Infinity);
|
|
87
|
-
});
|
|
88
|
-
test('should return 0 for identical 2D points', function() {
|
|
89
|
-
result = myp5.dist(2, 3, 2, 3);
|
|
90
|
-
assert.equal(result, 0);
|
|
91
|
-
});
|
|
92
|
-
test('should return 0 for identical 3D points', function() {
|
|
93
|
-
result = myp5.dist(2, 3, 5, 2, 3, 5);
|
|
94
|
-
assert.equal(result, 0);
|
|
95
|
-
});
|
|
96
|
-
test('should return infinity if coordinate of a point is at infinity (2D)', function() {
|
|
97
|
-
result = myp5.dist(0, 0, Infinity, 0);
|
|
98
|
-
assert.equal(result, Infinity);
|
|
99
|
-
});
|
|
100
|
-
test('should return infinity if coordinate of a point is at -infinity (2D)', function() {
|
|
101
|
-
result = myp5.dist(0, 0, -Infinity, 0);
|
|
102
|
-
assert.equal(result, Infinity);
|
|
103
|
-
});
|
|
104
|
-
test('should handle overflow correctly (2D)', function() {
|
|
105
|
-
result = myp5.dist(0, 1e200, 0, 1e199);
|
|
106
|
-
assert.equal(result, 9e199);
|
|
107
|
-
});
|
|
108
|
-
test('should handle rounding correctly (2D)', function() {
|
|
109
|
-
result = myp5.dist(0, 1e-200, 0, 1e-199);
|
|
110
|
-
assert.equal(result, 9e-200);
|
|
111
|
-
});
|
|
112
|
-
test('should handle string parameters correctly (2D)', function() {
|
|
113
|
-
result = myp5.dist(0, 0, '4', '3');
|
|
114
|
-
assert.equal(result, 5);
|
|
115
|
-
});
|
|
116
|
-
test('should return infinity if coordinate of a point is at infinity (3D)', function() {
|
|
117
|
-
result = myp5.dist(0, 0, 0, Infinity, 0, 0);
|
|
118
|
-
assert.equal(result, Infinity);
|
|
119
|
-
});
|
|
120
|
-
test('should return infinity if coordinate of a point is at -infinity (3D)', function() {
|
|
121
|
-
result = myp5.dist(0, 0, 0, -Infinity, 0, 0);
|
|
122
|
-
assert.equal(result, Infinity);
|
|
123
|
-
});
|
|
124
|
-
test('should handle overflow correctly (3D)', function() {
|
|
125
|
-
result = myp5.dist(0, 0, 1e200, 0, 0, 1e199);
|
|
126
|
-
assert.equal(result, 9e199);
|
|
127
|
-
});
|
|
128
|
-
test('should handle rounding correctly (3D)', function() {
|
|
129
|
-
result = myp5.dist(0, 0, 1e-200, 0, 0, 1e-199);
|
|
130
|
-
assert.equal(result, 9e-200);
|
|
131
|
-
});
|
|
132
|
-
test('should handle string parameters correctly (3D)', function() {
|
|
133
|
-
result = myp5.dist(0, 0, 0, '4', '4', '2');
|
|
134
|
-
assert.equal(result, 6);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
suite('p5.prototype.exp', function() {
|
|
139
|
-
var result;
|
|
140
|
-
test('should be a function', function() {
|
|
141
|
-
assert.ok(myp5.exp);
|
|
142
|
-
assert.typeOf(myp5.exp, 'function');
|
|
143
|
-
});
|
|
144
|
-
test('should return exp value given negative value', function() {
|
|
145
|
-
result = myp5.exp(-1);
|
|
146
|
-
assert.approximately(result, Math.exp(-1), 0.000001);
|
|
147
|
-
});
|
|
148
|
-
test('should return exp value given positive value', function() {
|
|
149
|
-
result = myp5.exp(1);
|
|
150
|
-
assert.approximately(result, Math.exp(1), 0.000001);
|
|
151
|
-
});
|
|
152
|
-
test('should return 1', function() {
|
|
153
|
-
result = myp5.exp(0);
|
|
154
|
-
assert.equal(result, 1);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
suite('p5.prototype.floor', function() {
|
|
159
|
-
var result;
|
|
160
|
-
test('should be a function', function() {
|
|
161
|
-
assert.ok(myp5.floor);
|
|
162
|
-
assert.typeOf(myp5.floor, 'function');
|
|
163
|
-
});
|
|
164
|
-
test('should return floor value given negative value', function() {
|
|
165
|
-
result = myp5.floor(-1.9);
|
|
166
|
-
assert.equal(result, -2);
|
|
167
|
-
});
|
|
168
|
-
test('should return a floor value given positive value', function() {
|
|
169
|
-
result = myp5.floor(0.1);
|
|
170
|
-
assert.equal(result, 0);
|
|
171
|
-
});
|
|
172
|
-
test('should return same number', function() {
|
|
173
|
-
result = myp5.floor(1);
|
|
174
|
-
assert.equal(result, 1);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
suite('p5.prototype.lerp', function() {
|
|
179
|
-
var result;
|
|
180
|
-
test('should be a function', function() {
|
|
181
|
-
assert.ok(myp5.lerp);
|
|
182
|
-
assert.typeOf(myp5.lerp, 'function');
|
|
183
|
-
});
|
|
184
|
-
test('should return start', function() {
|
|
185
|
-
result = myp5.lerp(0, 5, 0);
|
|
186
|
-
assert.equal(result, 0);
|
|
187
|
-
});
|
|
188
|
-
test('should return average', function() {
|
|
189
|
-
result = myp5.lerp(0, 5, 0.5);
|
|
190
|
-
assert.equal(result, 2.5);
|
|
191
|
-
});
|
|
192
|
-
test('should return stop', function() {
|
|
193
|
-
result = myp5.lerp(0, 5, 1);
|
|
194
|
-
assert.equal(result, 5);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
suite('p5.prototype.log', function() {
|
|
199
|
-
var result;
|
|
200
|
-
test('should be a function', function() {
|
|
201
|
-
assert.ok(myp5.log);
|
|
202
|
-
assert.typeOf(myp5.log, 'function');
|
|
203
|
-
});
|
|
204
|
-
test('should return log value given negative value', function() {
|
|
205
|
-
result = myp5.log(Math.exp(-1));
|
|
206
|
-
assert.approximately(result, -1, 0.0001);
|
|
207
|
-
});
|
|
208
|
-
test('should return log value given positive value', function() {
|
|
209
|
-
result = myp5.log(Math.exp(1));
|
|
210
|
-
assert.approximately(result, 1, 0.0001);
|
|
211
|
-
});
|
|
212
|
-
test('should return 0', function() {
|
|
213
|
-
result = myp5.log(Math.exp(0));
|
|
214
|
-
assert.equal(result, 0);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
suite('p5.prototype.mag', function() {
|
|
219
|
-
var result;
|
|
220
|
-
test('should be a function', function() {
|
|
221
|
-
assert.ok(myp5.mag);
|
|
222
|
-
assert.typeOf(myp5.mag, 'function');
|
|
223
|
-
});
|
|
224
|
-
test('should return a number', function() {
|
|
225
|
-
result = myp5.mag(2, 3);
|
|
226
|
-
assert.typeOf(result, 'number');
|
|
227
|
-
});
|
|
228
|
-
test('should return correct magitude', function() {
|
|
229
|
-
result = myp5.mag(2, 3);
|
|
230
|
-
assert.approximately(result, 3.605551, 0.000001); // Math.hypot(2, 3)
|
|
231
|
-
});
|
|
232
|
-
test('should return positive magnitude given negative inputs', function() {
|
|
233
|
-
result = myp5.mag(-2, -3);
|
|
234
|
-
assert.approximately(result, 3.605551, 0.000001); // Math.hypot(2, 3)
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
suite('p5.prototype.map', function() {
|
|
239
|
-
var result;
|
|
240
|
-
test('should be a function', function() {
|
|
241
|
-
assert.ok(myp5.map);
|
|
242
|
-
assert.typeOf(myp5.map, 'function');
|
|
243
|
-
});
|
|
244
|
-
test('should return a number', function() {
|
|
245
|
-
result = myp5.map(1, 0, 10, 0, 20);
|
|
246
|
-
assert.typeOf(result, 'number');
|
|
247
|
-
});
|
|
248
|
-
test('should return scaled value', function() {
|
|
249
|
-
result = myp5.map(1, 0, 10, 0, 20);
|
|
250
|
-
assert.equal(result, 2);
|
|
251
|
-
});
|
|
252
|
-
test('should extrapolate by default', function() {
|
|
253
|
-
assert.approximately(myp5.map(10, 0, 1, 10, 11), 20, 0.01);
|
|
254
|
-
assert.approximately(myp5.map(-1, 0, 1, 10, 11), 9, 0.01);
|
|
255
|
-
assert.approximately(myp5.map(2, 0, 1, 20, 10), 0, 0.01);
|
|
256
|
-
});
|
|
257
|
-
test('shaould clamp correctly', function() {
|
|
258
|
-
assert.approximately(myp5.map(1, 0, 10, 0, 20, true), 2, 0.01);
|
|
259
|
-
|
|
260
|
-
assert.approximately(myp5.map(10, 0, 1, 10, 11, true), 11, 0.01);
|
|
261
|
-
assert.approximately(myp5.map(-1, 0, 1, 10, 11, true), 10, 0.01);
|
|
262
|
-
assert.approximately(myp5.map(2, 0, 1, 20, 10, true), 10, 0.01);
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
suite('p5.prototype.max', function() {
|
|
267
|
-
var result;
|
|
268
|
-
test('should be a function', function() {
|
|
269
|
-
assert.ok(myp5.max);
|
|
270
|
-
assert.typeOf(myp5.max, 'function');
|
|
271
|
-
});
|
|
272
|
-
test('should return larger left argument', function() {
|
|
273
|
-
result = myp5.max(10, -1);
|
|
274
|
-
assert.equal(result, 10);
|
|
275
|
-
});
|
|
276
|
-
test('should return larger right argument', function() {
|
|
277
|
-
result = myp5.max(-1, 10);
|
|
278
|
-
assert.equal(result, 10);
|
|
279
|
-
});
|
|
280
|
-
test('should return single value', function() {
|
|
281
|
-
result = myp5.max(10, 10);
|
|
282
|
-
assert.equal(result, 10);
|
|
283
|
-
});
|
|
284
|
-
test('should return larger value from array', function() {
|
|
285
|
-
result = myp5.max([10, -1]);
|
|
286
|
-
assert.equal(result, 10);
|
|
287
|
-
});
|
|
288
|
-
test('should return larger value from array', function() {
|
|
289
|
-
result = myp5.max(-1, 10);
|
|
290
|
-
assert.equal(result, 10);
|
|
291
|
-
});
|
|
292
|
-
test('should return single value from array', function() {
|
|
293
|
-
result = myp5.max([10, 10]);
|
|
294
|
-
assert.equal(result, 10);
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
suite('p5.prototype.min', function() {
|
|
299
|
-
var result;
|
|
300
|
-
test('should be a function', function() {
|
|
301
|
-
assert.ok(myp5.min);
|
|
302
|
-
assert.typeOf(myp5.min, 'function');
|
|
303
|
-
});
|
|
304
|
-
test('should return smaller right argument', function() {
|
|
305
|
-
result = myp5.min(10, -1);
|
|
306
|
-
assert.equal(result, -1);
|
|
307
|
-
});
|
|
308
|
-
test('should return smaller left argument', function() {
|
|
309
|
-
result = myp5.min(-1, 10);
|
|
310
|
-
assert.equal(result, -1);
|
|
311
|
-
});
|
|
312
|
-
test('should return single value', function() {
|
|
313
|
-
result = myp5.min(10, 10);
|
|
314
|
-
assert.equal(result, 10);
|
|
315
|
-
});
|
|
316
|
-
test('should return smaller value from array', function() {
|
|
317
|
-
result = myp5.min([10, -1]);
|
|
318
|
-
assert.equal(result, -1);
|
|
319
|
-
});
|
|
320
|
-
test('should return smaller value from array', function() {
|
|
321
|
-
result = myp5.min([-1, 10]);
|
|
322
|
-
assert.equal(result, -1);
|
|
323
|
-
});
|
|
324
|
-
test('should return single value from array', function() {
|
|
325
|
-
result = myp5.min([10, 10]);
|
|
326
|
-
assert.equal(result, 10);
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
suite('p5.prototype.norm', function() {
|
|
331
|
-
var result;
|
|
332
|
-
test('should be a function', function() {
|
|
333
|
-
assert.ok(myp5.norm);
|
|
334
|
-
assert.typeOf(myp5.norm, 'function');
|
|
335
|
-
});
|
|
336
|
-
test('should return scaled decimal value', function() {
|
|
337
|
-
// note: there is currently scoping issues with "this" keyword
|
|
338
|
-
result = myp5.norm(20, 0, 50);
|
|
339
|
-
assert.equal(result, 0.4);
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
suite('p5.prototype.constrain', function() {
|
|
344
|
-
var result;
|
|
345
|
-
test('should be a function', function() {
|
|
346
|
-
assert.ok(myp5.constrain);
|
|
347
|
-
assert.typeOf(myp5.constrain, 'function');
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
test('should return same number', function() {
|
|
351
|
-
result = myp5.constrain(1, 3, 5);
|
|
352
|
-
assert.equal(result, 3);
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
test('should return lower bound', function() {
|
|
356
|
-
result = myp5.constrain(1, -1, 5);
|
|
357
|
-
assert.equal(result, 1);
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
test('should return upper bound', function() {
|
|
361
|
-
result = myp5.constrain(1, 10, 5);
|
|
362
|
-
assert.equal(result, 10);
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
suite('p5.prototype.sq', function() {
|
|
367
|
-
var result;
|
|
368
|
-
test('should be a function', function() {
|
|
369
|
-
assert.ok(myp5.sq);
|
|
370
|
-
assert.typeOf(myp5.sq, 'function');
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
test('should return sauare value', function() {
|
|
374
|
-
result = myp5.sq(10);
|
|
375
|
-
assert.equal(result, 100);
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
test('should return squared value given negative number', function() {
|
|
379
|
-
result = myp5.sq(-10);
|
|
380
|
-
assert.equal(result, 100);
|
|
381
|
-
});
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
suite('p5.prototype.pow', function() {
|
|
385
|
-
var result;
|
|
386
|
-
test('should be a function', function() {
|
|
387
|
-
assert.ok(myp5.pow);
|
|
388
|
-
assert.typeOf(myp5.pow, 'function');
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
test('should return pow for negative exponential', function() {
|
|
392
|
-
result = myp5.pow(2, -1);
|
|
393
|
-
assert.equal(result, 0.5);
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
test('should return pow for positive exponential', function() {
|
|
397
|
-
result = myp5.pow(2, 4);
|
|
398
|
-
assert.equal(result, 16);
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
suite('p5.prototype.round', function() {
|
|
403
|
-
var result;
|
|
404
|
-
test('should be a function', function() {
|
|
405
|
-
assert.ok(myp5.round);
|
|
406
|
-
assert.typeOf(myp5.round, 'function');
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
test('should round down', function() {
|
|
410
|
-
result = myp5.round(2.1);
|
|
411
|
-
assert.equal(result, 2);
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
test('should round up from midpoint', function() {
|
|
415
|
-
result = myp5.round(2.5);
|
|
416
|
-
assert.equal(result, 3);
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
test('should round up', function() {
|
|
420
|
-
result = myp5.round(2.8);
|
|
421
|
-
assert.equal(result, 3);
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
test('should round two decimal places', function() {
|
|
425
|
-
result = myp5.round(12.31833, 2);
|
|
426
|
-
assert.equal(result, 12.32);
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
test('should round very small numbers to zero', function() {
|
|
430
|
-
result = myp5.round(1.234567e-14);
|
|
431
|
-
assert.equal(result, 0);
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
test('should round very small numbers to zero when decimal places are specified', function() {
|
|
435
|
-
result = myp5.round(1.234567e-14, 2);
|
|
436
|
-
assert.equal(result, 0);
|
|
437
|
-
});
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
suite('p5.prototype.sqrt', function() {
|
|
441
|
-
var result;
|
|
442
|
-
test('should be a function', function() {
|
|
443
|
-
assert.ok(myp5.sqrt);
|
|
444
|
-
assert.typeOf(myp5.sqrt, 'function');
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
test('should return square root', function() {
|
|
448
|
-
result = myp5.sqrt(100);
|
|
449
|
-
assert.equal(result, 10);
|
|
450
|
-
});
|
|
451
|
-
});
|
|
452
|
-
});
|