diff --git a/package.json b/package.json index 6025ad1..0ced6ab 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/curve-interpolator.ts b/src/curve-interpolator.ts index 01a63f9..c95290d 100644 --- a/src/curve-interpolator.ts +++ b/src/curve-interpolator.ts @@ -137,9 +137,11 @@ export default class CurveInterpolator { getPoints(samples:number, returnType: { new() : T }) : T[] getPoints(samples:number, returnType: { new() : T }, from:number) : T[] getPoints(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 = []; diff --git a/test/curve-interpolator.spec.ts b/test/curve-interpolator.spec.ts index a17d8ae..7a26473 100644 --- a/test/curve-interpolator.spec.ts +++ b/test/curve-interpolator.spec.ts @@ -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', () => {