local V=2.718281828459 local B=1 local G=1 local F=0 local K=0*F local E=F local L=K local q=tick()local function c(B,G,F,K,E,L,q)if G==0 then return F elseif B<.99999999 then local c=(1-B*B)^.5 local X=(F-E)+((2*B)/G)*L local m=((B/c)*(F-E)+K/(c*G))+(((2*B)*B-1)/(c*G))*L local h=math.cos((c*G)*q)local I=math.sin((c*G)*q)local d=V^((B*G)*q)return(((h/d)*X+(I/d)*m)+E)+(q-(2*B)/G)*L,(((G*(h*c-B*I))/d)*m-((G*(h*B+c*I))/d)*X)+L elseif B<1.00000001 then local B=(F-E)+(2/G)*L local c=(F-E)+(K+L)/G local X=V^(G*q)return((B+(c*G)*q)/X+E)+(q-2/G)*L,L-(G/X)*(B+(G*q-1)*c)else local c=(B*B-1)^.5 local X=(L-K)/((2*G)*c)local m=(B/G)*L-(E-F)/2 local h=(1-B/c)*m+X local I=(1+B/c)*m-X local d=V^((-(c+B)*G)*q)local U=V^(((c-B)*G)*q)return((h*d+I*U)+E)+(q-(2*B)/G)*L,(((U*(c-B))*G)*I-((d*(B+c))*G)*h)+L end end local function X(V,B,G)return V+G*B,B end local m={}function m.accelerate(m,V)local h=tick()local I,d=c(B,G,F,K,E,L,h-q)local U,s=X(E,L,h-q)F,K=I,d+V E,L=U,s q=h return setmetatable(m)end

local e=2.718281828459045
local d=1
local s=1
local p0=0
local v0=0*p0
local p1=p0
local v1=v0
local t0=tick()

local function posvel(d,s,p0,v0,p1,v1,x)
	if s==0 then
		return p0
	elseif d<1-1e-8 then
		local h=(1-d*d)^0.5
		local c1=(p0-p1+2*d/s*v1)
		local c2=d/h*(p0-p1)+v0/(h*s)+(2*d*d-1)/(h*s)*v1
		local co=math.cos(h*s*x)
		local si=math.sin(h*s*x)
		local ex=e^(d*s*x)
		return co/ex*c1+si/ex*c2+p1+(x-2*d/s)*v1,
			s*(co*h-d*si)/ex*c2-s*(co*d+h*si)/ex*c1+v1
	elseif d<1+1e-8 then
		local c1=p0-p1+2/s*v1
		local c2=p0-p1+(v0+v1)/s
		local ex=e^(s*x)
		return (c1+c2*s*x)/ex+p1+(x-2/s)*v1,
			v1-s/ex*(c1+(s*x-1)*c2)
	else
		local h=(d*d-1)^0.5
		local a=(v1-v0)/(2*s*h)
		local b=d/s*v1-(p1-p0)/2
		local c1=(1-d/h)*b+a
		local c2=(1+d/h)*b-a
		local co=e^(-(h+d)*s*x)
		local si=e^((h-d)*s*x)
		return c1*co+c2*si+p1+(x-2*d/s)*v1,
			si*(h-d)*s*c2-co*(d+h)*s*c1+v1
	end
end
	
local function targposvel(p1,v1,x)
	return p1+x*v1,v1
end

local self={}

function self:accelerate(a)
	local time=tick()
	local p,v=posvel(d,s,p0,v0,p1,v1,time-t0)
	local tp,tv=targposvel(p1,v1,time-t0)
	p0,v0=p,v+a
	p1,v1=tp,tv
	t0=time
	return setmetatable(self)
end
