Skip to content

Commit

Permalink
Added more unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesleesaunders committed Aug 12, 2019
1 parent 73c9600 commit 9e4db43
Show file tree
Hide file tree
Showing 6 changed files with 569 additions and 836 deletions.
29 changes: 17 additions & 12 deletions dist/d3-interpolate-curve.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// https://github.com/jamesleesaunders/ v1.0.1 Copyright 2019 James Saunders
// https://github.com/jamesleesaunders/ v1.0.2 Copyright 2019 James Saunders
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-shape'), require('d3-array')) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-shape', 'd3-array'], factory) :
(factory((global.d3 = global.d3 || {}),global.d3,global.d3));
}(this, (function (exports,d3Shape,d3Array) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-shape'), require('d3-array'), require('d3-interpolate')) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-shape', 'd3-array', 'd3-interpolate'], factory) :
(factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3));
}(this, (function (exports,d3Shape,d3Array,d3Interpolate) { 'use strict';

/**
* Curve Polator
*
* @param points
* @param curve
* @param curveFunction
* @param epsilon
* @param samples
* @returns {Function}
*/
function curvePolator(points, curve, epsilon, samples) { // eslint-disable-line max-params
const path = d3Shape.line().curve(curve)(points);
function curvePolator(points, curveFunction, epsilon, samples) { // eslint-disable-line max-params
const path = d3Shape.line().curve(curveFunction)(points);

return svgPathInterpolator(path, epsilon, samples);
}

/**
* SVG Psth Interpolator
* SVG Path Interpolator
*
* @param path
* @param epsilon
Expand Down Expand Up @@ -87,17 +87,22 @@ function svgPathInterpolator(path, epsilon, samples) {
* Interpolate From Curve
*
* @param values
* @param curve
* @param curveFunction
* @param epsilon
* @param samples
* @returns {Function}
*/
function fromCurve(values, curve, epsilon = 0.00001, samples = 100) { // eslint-disable-line max-params
function fromCurve(values, curveFunction, epsilon = 0.00001, samples = 100) { // eslint-disable-line max-params
const length = values.length;
const xrange = d3Array.range(length).map(function(d, i) { return i * (1 / (length - 1)); });
const points = values.map((v, i) => [xrange[i], v]);

return curvePolator(points, curve, epsilon, samples);
// If curveFunction is curveBasis then reach straight for D3's native 'interpolateBasis' function (it's faster!)
if (curveFunction === d3Shape.curveBasis) {
return d3Interpolate.interpolateBasis(values);
} else {
return curvePolator(points, curveFunction, epsilon, samples);
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions dist/d3-interpolate-curve.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9e4db43

Please sign in to comment.