cubic-beziers-through-points
Version:
A function to fit fair (bending energy minimizing) cubic bezier curves through a set of given ordered points in the plane.
90 lines (83 loc) • 2.58 kB
text/typescript
// import { expect, assert, use } from 'chai';
// import { describe, it } from 'mocha';
import { cubicBeziersThroughPoints } from '../src/cubic-beziers-through-points';
// import { nearly } from './helpers/chai-extend-nearly.js';
import { getRandomPoints } from './helpers/get-random-points';
// use(nearly);
test('cubicBeziersThroughPoints', function() {
it('it should return minimum energy cubic bezier curves through the set of ordered points',
function() {
{
const points = [[6, 4], [15, 5], [1, 4]];
const r = cubicBeziersThroughPoints(points);
expect(r).toEqual([
[
[],
[],
[],
[]
],
[
[],
[],
[-1.0472045601713909, 8.206880361705375],
[]
],
[
[],
[],
[],
[]
]
]);
}
{
const points = getRandomPoints(0,5);
const r = cubicBeziersThroughPoints(points);
expect(r).toEqual([
[
[],
[],
[],
[]
],
[
[],
[],
[],
[]
],
[
[],
[],
[],
[]
],
[
[],
[],
[],
[]
],
[
[],
[],
[],
[]
]
]);
}
{
// Two points are identical
const points = [
[],
[],
[],
[],
[],
[]
];
const r = cubicBeziersThroughPoints(points);
}
});
});