@yr/monotone-cubic-spline
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -19,3 +19,2 @@ 'use strict'; | ||
*/ | ||
points: function points(_points) { | ||
@@ -107,3 +106,3 @@ var tgts = tangents(_points); | ||
var tangents = []; | ||
var tgts = []; | ||
var a = void 0, | ||
@@ -133,6 +132,6 @@ b = void 0, | ||
s = (points[Math.min(n, _i + 1)][0] - points[Math.max(0, _i - 1)][0]) / (6 * (1 + m[_i] * m[_i])); | ||
tangents.push([s || 0, m[_i] * s || 0]); | ||
tgts.push([s || 0, m[_i] * s || 0]); | ||
} | ||
return tangents; | ||
return tgts; | ||
} | ||
@@ -139,0 +138,0 @@ |
{ | ||
"name": "@yr/monotone-cubic-spline", | ||
"description": "Convert a series of points to a monotone cubic spline", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"author": "Alexander Pope <alexander.pope@nrk.no>", | ||
"dependencies": { | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"buddy": "5.1.x", | ||
"buddy-plugin-babel": "6.10.x", | ||
"babel-plugin-syntax-trailing-function-commas": "6.22.0", | ||
"babel-plugin-transform-async-generator-functions": "6.24.1", | ||
"babel-plugin-transform-async-to-generator": "6.24.1", | ||
"babel-plugin-transform-es2015-arrow-functions": "6.22.0", | ||
"babel-plugin-transform-es2015-block-scoped-functions": "6.22.0", | ||
"babel-plugin-transform-es2015-block-scoping": "6.24.1", | ||
"babel-plugin-transform-es2015-classes": "6.24.1", | ||
"babel-plugin-transform-es2015-computed-properties": "6.24.1", | ||
"babel-plugin-transform-es2015-destructuring": "6.23.0", | ||
"babel-plugin-transform-es2015-duplicate-keys": "6.24.1", | ||
"babel-plugin-transform-es2015-for-of": "6.23.0", | ||
"babel-plugin-transform-es2015-function-name": "6.24.1", | ||
"babel-plugin-transform-es2015-literals": "6.22.0", | ||
"babel-plugin-transform-es2015-object-super": "6.24.1", | ||
"babel-plugin-transform-es2015-parameters": "6.24.1", | ||
"babel-plugin-transform-es2015-shorthand-properties": "6.24.1", | ||
"babel-plugin-transform-es2015-spread": "6.22.0", | ||
"babel-plugin-transform-es2015-sticky-regex": "6.24.1", | ||
"babel-plugin-transform-es2015-template-literals": "6.22.0", | ||
"babel-plugin-transform-es2015-unicode-regex": "6.24.1", | ||
"babel-plugin-transform-es5-property-mutators": "6.24.1", | ||
"babel-plugin-transform-exponentiation-operator": "6.24.1", | ||
"babel-plugin-transform-object-rest-spread": "6.23.0", | ||
"buddy": "6.x.x", | ||
"expect.js": "*", | ||
"mocha": "*", | ||
"mocha-phantomjs": "*" | ||
"mocha": "*" | ||
}, | ||
@@ -20,12 +40,12 @@ "main": "src/index.js", | ||
"prepublish": "buddy build", | ||
"test": "NODE_ENV=test mocha test/lib-test.js --reporter spec", | ||
"test-client": "buddy build && mocha-phantomjs test/test-runner.html" | ||
"test": "NODE_ENV=test mocha test/lib-test.js --reporter spec" | ||
}, | ||
"browser": "index.js", | ||
"build": { | ||
"targets": [ | ||
"buddy": { | ||
"build": [ | ||
{ | ||
"input": "src", | ||
"input": "src/", | ||
"output": ".", | ||
"modular": false | ||
"bundle": false, | ||
"version": "es5" | ||
}, | ||
@@ -32,0 +52,0 @@ { |
@@ -10,3 +10,3 @@ [![NPM Version](https://img.shields.io/npm/v/@yr/monotone-cubic-spline.svg?style=flat)](https://npmjs.org/package/@yr/monotone-cubic-spline) | ||
const spline = require('@yr/monotone-cubic-spline'); | ||
const points = spline.points([[0,0], [1,1], [2,1], [3,0], [4,0]]; | ||
const points = spline.points([[0,0], [1,1], [2,1], [3,0], [4,0]]); | ||
const svgPath = spline.svgPath(points); | ||
@@ -13,0 +13,0 @@ |
@@ -19,10 +19,10 @@ 'use strict'; | ||
*/ | ||
points (points) { | ||
points(points) { | ||
const tgts = tangents(points); | ||
let p = points[1]; | ||
let p0 = points[0]; | ||
let pts = []; | ||
let t = tgts[1]; | ||
let t0 = tgts[0]; | ||
const p = points[1]; | ||
const p0 = points[0]; | ||
const pts = []; | ||
const t = tgts[1]; | ||
const t0 = tgts[0]; | ||
@@ -50,4 +50,4 @@ // Add starting 'M' and 'C' points | ||
*/ | ||
slice (points, start, end) { | ||
let pts = points.slice(start, end); | ||
slice(points, start, end) { | ||
const pts = points.slice(start, end); | ||
@@ -59,3 +59,3 @@ if (start) { | ||
pts[1] = [(pts[0][n - 2] * 2) - pts[0][n - 4], (pts[0][n - 1] * 2) - pts[0][n - 3]].concat(pts[1]); | ||
pts[1] = [pts[0][n - 2] * 2 - pts[0][n - 4], pts[0][n - 1] * 2 - pts[0][n - 3]].concat(pts[1]); | ||
} | ||
@@ -74,3 +74,3 @@ // Remove control points for 'M' | ||
*/ | ||
svgPath (points) { | ||
svgPath(points) { | ||
let p = ''; | ||
@@ -83,10 +83,10 @@ | ||
if (!i) { | ||
p += 'M' + (point[n - 2]) + ' ' + (point[n - 1]); | ||
p += `M${point[n - 2]} ${point[n - 1]}`; | ||
} else if (n > 4) { | ||
p += 'C' + (point[0]) + ', ' + (point[1]); | ||
p += ', ' + (point[2]) + ', ' + (point[3]); | ||
p += ', ' + (point[4]) + ', ' + (point[5]); | ||
p += `C${point[0]}, ${point[1]}`; | ||
p += `, ${point[2]}, ${point[3]}`; | ||
p += `, ${point[4]}, ${point[5]}`; | ||
} else { | ||
p += 'S' + (point[0]) + ', ' + (point[1]); | ||
p += ', ' + (point[2]) + ', ' + (point[3]); | ||
p += `S${point[0]}, ${point[1]}`; | ||
p += `, ${point[2]}, ${point[3]}`; | ||
} | ||
@@ -104,7 +104,7 @@ } | ||
*/ | ||
function tangents (points) { | ||
function tangents(points) { | ||
const m = finiteDifferences(points); | ||
const n = points.length - 1; | ||
let tangents = []; | ||
const tgts = []; | ||
let a, b, d, s; | ||
@@ -120,3 +120,3 @@ | ||
b = m[i + 1] / d; | ||
s = (a * a) + (b * b); | ||
s = a * a + b * b; | ||
if (s > 9) { | ||
@@ -132,6 +132,6 @@ s = d * 3 / Math.sqrt(s); | ||
s = (points[Math.min(n, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i])); | ||
tangents.push([s || 0, m[i] * s || 0]); | ||
tgts.push([s || 0, m[i] * s || 0]); | ||
} | ||
return tangents; | ||
return tgts; | ||
} | ||
@@ -145,3 +145,3 @@ | ||
*/ | ||
function slope (p0, p1) { | ||
function slope(p0, p1) { | ||
return (p1[1] - p0[1]) / (p1[0] - p0[0]); | ||
@@ -155,7 +155,7 @@ } | ||
*/ | ||
function finiteDifferences (points) { | ||
let m = []; | ||
function finiteDifferences(points) { | ||
const m = []; | ||
let p0 = points[0]; | ||
let p1 = points[1]; | ||
let d = m[0] = slope(p0, p1); | ||
let d = (m[0] = slope(p0, p1)); | ||
let i = 1; | ||
@@ -171,2 +171,2 @@ | ||
return m; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
11076
272
26