source: node_modules/d3-interpolate/src/basis.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 600 bytes
Line 
1export function basis(t1, v0, v1, v2, v3) {
2 var t2 = t1 * t1, t3 = t2 * t1;
3 return ((1 - 3 * t1 + 3 * t2 - t3) * v0
4 + (4 - 6 * t2 + 3 * t3) * v1
5 + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
6 + t3 * v3) / 6;
7}
8
9export default function(values) {
10 var n = values.length - 1;
11 return function(t) {
12 var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
13 v1 = values[i],
14 v2 = values[i + 1],
15 v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
16 v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
17 return basis((t - i / n) * n, v0, v1, v2, v3);
18 };
19}
Note: See TracBrowser for help on using the repository browser.