function catmull( points, steps )

	if #points < 3 then
		return points
	end

	local steps = steps or 5

	local spline = {}
	local count = #points - 1
	local p0, p1, p2, p3, x, y

	for i = 1, count do

		if i == 1 then
			p0, p1, p2, p3 = points[i], points[i], points[i + 1], points[i + 2]
		elseif i == count then
			p0, p1, p2, p3 = points[#points - 2], points[#points - 1], points[#points], points[#points]
		else
			p0, p1, p2, p3 = points[i - 1], points[i], points[i + 1], points[i + 2]
		end	

		for t = 0, 1, 1 / steps do

			x = 0.5 * ( ( 2 * p1.x ) + ( p2.x - p0.x ) * t + ( 2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x ) * t * t + ( 3 * p1.x - p0.x - 3 * p2.x + p3.x ) * t * t * t )
			y = 0.5 * ( ( 2 * p1.y ) + ( p2.y - p0.y ) * t + ( 2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y ) * t * t + ( 3 * p1.y - p0.y - 3 * p2.y + p3.y ) * t * t * t )

			--prevent duplicate entries
			if not(#spline > 0 and spline[#spline].x == x and spline[#spline].y == y) then
				table.insert( spline , { x = x , y = y } )				
			end	
			
		end

	end	

	return spline

end

local buffer = {}
function catmullLine( points, steps , temp)
	local n = 1
	if #points < 3 then
		return points, n
	end

	local steps = math.max(0,mf(steps) or 3)+1
	if steps==1 then return points,#points end

	local spline = temp and buffer or {}

	local count = #points - 1
	local p0, p1, p2, p3, x, y = vec2(),vec2(),vec2(),vec2()
	local add = false
	for i = 1, count,2 do
		add = false
		if i == 1 then
			p0.x,p0.y =  points[i]   ,  points[i+1]
			p1.x,p1.y =  points[i]     ,  points[i+1]
			p2.x,p2.y =  points[i+2]   ,  points[i+3]
			p3.x,p3.y =  points[i+4] or p2.x   ,  points[i+5] or p2.y
		elseif i == count then
			p0.x,p0.y =  points[i-4] or points[i-2]   ,  points[i-3] or points[i-1]
			p1.x,p1.y =  points[i-2]     ,  points[i-1]
			p2.x,p2.y =  points[i]   ,  points[i+1]
			p3.x,p3.y =  points[i] or p2.x   ,  points[i+1] or p2.y
		else
			p0.x,p0.y =  points[i-2]   ,  points[i-1]
			p1.x,p1.y =  points[i]     ,  points[i+1]
			p2.x,p2.y =  points[i+2]   ,  points[i+3]
			p3.x,p3.y =  points[i+4] or p2.x   ,  points[i+5] or p2.y
		end	

		for t = 0, 1, 1 / steps do

			x = 0.5 * ( 
									( 2 * p1.x ) + ( p2.x - p0.x ) * t 
								+ ( 2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x ) * t * t 
								+ ( 3 * p1.x - p0.x - 3 * p2.x + p3.x ) * t * t * t 
								)
			y = 0.5 * ( 
									( 2 * p1.y ) + ( p2.y - p0.y ) * t 
								+ ( 2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y ) * t * t 
								+ ( 3 * p1.y - p0.y - 3 * p2.y + p3.y ) * t * t * t 
								)

			if not(#spline > 0 and spline[#spline-1] == x and spline[#spline] == y) then
				if temp then 
					spline[n]= x ; n = n + 1
					spline[n]= y ; n = n + 1
				else
					table.insert( spline , x  )	
					table.insert( spline , y  )	
				end
			end	
			
		end

		if temp then 
			n=n-2
		else 
			if i<count then 
				table.remove(spline,#spline)
				table.remove(spline,#spline)
			end
		end

	end	

	return spline,n

end
