Skip to content

Commit 90fb7e1

Browse files
committed
introduce array_fps
1 parent a3730dd commit 90fb7e1

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/array_fps.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const round = require('./round');
2+
3+
const EPS = 0.00001;
4+
5+
function array_fps(duration_sec, fps)
6+
{
7+
const total_frames = Math.floor(duration_sec * fps);
8+
9+
if (total_frames <= 1) {
10+
return [0];
11+
}
12+
13+
const out = [];
14+
for (let i = 0; i < total_frames; ++i) {
15+
// console.log((i / (total_frames - 1)) * (duration_sec - EPS), round((i / (total_frames - 1)) * (duration_sec - EPS), EPS));
16+
out.push(round((i / (total_frames - 1)) * (duration_sec - EPS), EPS));
17+
}
18+
return out;
19+
}
20+
21+
module.exports = array_fps;

src/array_fps.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const array_fps = require('./array_fps');
2+
const assert = require('assert');
3+
4+
describe('array_fps', function () {
5+
it('should handle basic input', function () {
6+
assert.deepStrictEqual(array_fps(1, 1), [0]);
7+
assert.deepStrictEqual(array_fps(1, 2), [0, 0.99999]);
8+
assert.deepStrictEqual(array_fps(1, 3), [0, 0.49999, 0.99999]);
9+
assert.deepStrictEqual(array_fps(1, 4), [0, 0.33333, 0.66666, 0.99999]);
10+
});
11+
});

0 commit comments

Comments
 (0)