local N={}do N.__index=N function N.new(x,o,w)return setmetatable({fRising=x,fFalling=o,g=w,p=w;v=w*0},N)end function N.step(x,N)local o=x.fRising local w=x.fFalling local V=x.g local K=x.p local p=x.v local m=(2*math.pi)*(p>0 and o or w)local E=K-V local r=math.exp(-m*N)local B=(E*(1+m*N)+p*N)*r+V local l=(p*(1-m*N)-E*((m*m)*N))*r x.p=B x.v=l return B end end

local VariableEdgeSpring = {} do
	VariableEdgeSpring.__index = VariableEdgeSpring

	function VariableEdgeSpring.new(fRising, fFalling, position)
		return setmetatable({
			fRising = fRising,
			fFalling = fFalling,
			g = position,
			p = position,
			v = position*0,
		}, VariableEdgeSpring)
	end

	function VariableEdgeSpring:step(dt)
		local fRising = self.fRising
		local fFalling = self.fFalling
		local g = self.g
		local p0 = self.p
		local v0 = self.v

		local f = 2*math.pi*(v0 > 0 and fRising or fFalling)

		local offset = p0 - g
		local decay = math.exp(-f*dt)

		local p1 = (offset*(1 + f*dt) + v0*dt)*decay + g
		local v1 = (v0*(1 - f*dt) - offset*(f*f*dt))*decay

		self.p = p1
		self.v = v1

		return p1
	end
end
