function SpringClass.Update(f,r)if not f.instant then local a,m,g,j,n=f.t,f.k,f.d,f.x,f.v local Y=m*(a-j)+n*g local d=n+Y*(r/2)local P=m*(a-(j+n*(r/2)))+d*g local z=n+P*(r/2)local S=m*(a-(j+d*(r/2)))+z*g local I=n+S*r local i=j+((n+2*(d+z))+I)*(r/6)f.x,f.v=i,n+(((Y+2*(P+S))+m*(a-(j+z*r)))+I*g)*(r/6)if getAbsDist(i,f.t)>f.marginOfError then return i end end f.x,f.v=f.t,f.v*0 return f.x end


function SpringClass:Update(dt)
	if (not self.instant) then
		local t, k, d, x0, v0 = self.t, self.k, self.d, self.x, self.v
		local a0 = k*(t - x0) + v0*d
		local v1 = v0 + a0*(dt/2)
		local a1 = k*(t - (x0 + v0*(dt/2))) + v1*d
		local v2 = v0 + a1*(dt/2)
		local a2 = k*(t - (x0 + v1*(dt/2))) + v2*d
		local v3 = v0 + a2*dt
		local x4 = x0 + (v0 + 2*(v1 + v2) + v3)*(dt/6)
		self.x, self.v = x4, v0 + (a0 + 2*(a1 + a2) + k*(t - (x0 + v2*dt)) + v3*d)*(dt/6)
		
		if (getAbsDist(x4, self.t) > self.marginOfError) then
			return x4
		end
	end
	
	self.x, self.v = self.t, self.v*0
	return self.x
end
