 class LinearInterpolator extends AbstractInterpolator
 	interpolate: (t) ->
 		k = Math.floor t
-		a = @getClippedInput k
-		b = @getClippedInput k+1
 		#Translate t to interpolate between k and k+1
 		t -= k
-		return (1-t)*a + (t)*b
+		return (1-t)*@getClippedInput(k) + (t)*@getClippedInput(k+1)
 
 
 class CubicInterpolator extends AbstractInterpolator
 	constructor: (array, config)->
+		#clamp cubic tension to [0,1] range
 		@tangentFactor = 1 - Math.max 0, Math.min 1, config.cubicTension
 		super
 

		return (2*t3 - 3*t2 + 1)*p[0] + (t3 - 2*t2 + t)*m[0] + (-2*t3 + 3*t2)*p[1] + (t3 - t2)*m[1]

{sin, PI} = Math
sinc = (x) -> 
	if x is 0 then 1
	else sin(PI*x)/(PI*x)

makeLanczosWindow = (a) ->
	(x) -> sinc(x/a) #lanczos window

makeSincKernel = (window) ->
	(x) -> sinc(x)*window(x)

class SincFilterInterpolator extends AbstractInterpolator
	constructor: (array, config) ->

		@array = array.slice 0 #copy the array
		@length = @array.length #cache length

		#Set the clipping helper method
		throw "Invalid clip: #{config.clip}" unless @clipHelper = {
			clamp: @clipHelperClamp
			zero: @clipHelperZero
			periodic: @clipHelperPeriodic
			mirror: @clipHelperMirror
		}[config.clip]


    # Get input array value at i, applying the clipping method
	getClippedInput: (i) ->
