local p={}function p.inverse_lerp(p,d,L)if p<d then if L<p then return 0 end if L>d then return 1 end L=L-p L=L/(d-p)return L end if p<=d then return 0 end if L<d then return 1 end if L>p then return 0 end return 1.0-(L-d)/(p-d)end function p.turn_vector2(p,d)local L=math.rad(d)local J=math.cos(L)local W=math.sin(L)local F=p.x*J-p.y*W local O=p.x*W+p.y*J return Vector2.new(F,O)end function p.round(p)if p%1>=.5 then return math.ceil(p)end return math.floor(p)end return p
--[[
	Copyright (c) 2020, Artur Zhidkov (TheArturZh)
--]]

local module = {}

--[[
	This function is from ToLua project:
	https://github.com/topameng/tolua/blob/master/Assets/ToLua/Lua/UnityEngine/Mathf.lua
	Copyright (c) 2015 - 2016, 蒙占志(topameng) topameng@gmail.com
--]]
function module.inverse_lerp(from, to, value)
	if from < to then
		if value < from then
			return 0
		end

		if value > to then
			return 1
		end

		value = value - from
		value = value/(to - from)
		return value
	end

	if from <= to then
		return 0
	end

	if value < to then
		return 1
	end

	if value > from then
        return 0
	end

	return 1.0 - ((value - to) / (from - to))
end

--[[
	Important note: vector rotates in opposite direction of the Roblox part rotation
	(negative angle should be used).
]]
function module.turn_vector2(v2, angle)
	local angle_rad = math.rad(angle)

	local cos = math.cos(angle_rad)
	local sin = math.sin(angle_rad)

	local x = v2.x * cos - v2.y * sin
	local y = v2.x * sin + v2.y * cos

	return Vector2.new(x,y)
end

function module.round(x)
	if x%1 >= 0.5 then
		return math.ceil(x)
	end
	return math.floor(x)
end

return module
