Skip to content

Commit

Permalink
Throw error if value of samples is not valid. Solves issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
kjerandp committed Jun 5, 2020
1 parent c1fecad commit b36e8c5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": false,
"name": "curve-interpolator",
"version": "2.0.7",
"version": "2.0.8",
"description": "Interpolate values on a Cardinal/Catmull-Rom spline curve",
"repository": "https://github.com/kjerandp/curve-interpolator",
"bugs": {
Expand Down
2 changes: 2 additions & 0 deletions src/curve-interpolator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ export default class CurveInterpolator {
getPoints<T extends VectorType>(samples:number, returnType: { new() : T }) : T[]
getPoints<T extends VectorType>(samples:number, returnType: { new() : T }, from:number) : T[]
getPoints<T extends VectorType>(samples:number, returnType: { new() : T }, from:number, to:number) : T[]
getPoints()
getPoints(samples:number)
getPoints(samples:number, returnType: null, from:number, to:number) : Vector[]
getPoints(samples:number = 100, returnType?: { new() : VectorType }, from:number = 0, to:number = 1) : Vector[] {
if (!samples || samples <= 0) throw Error('Invalid arguments passed to getPoints(). You must specify at least 1 sample/segment.')
if (from < 0 || to > 1 || to < from) return undefined;

const pts = [];
Expand Down
3 changes: 3 additions & 0 deletions test/curve-interpolator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ describe('curve-interpolator.ts', () => {
expect(result[result.length - 1].x).to.eq(points[points.length - 1][0]);
expect(result[result.length - 1].y).to.eq(points[points.length - 1][1]);
result.every(r => expect(r).to.be.instanceof(Point));

expect(() => interp.getPoints(0)).to.throw();
expect(() => interp.getPoints()).not.to.throw();
});

it('should be able to lookup values on curve', () => {
Expand Down

0 comments on commit b36e8c5

Please sign in to comment.