local module = {}

local vector = Vector3.new
local floor = math.floor
local noise = math.noise
local ceil = math.ceil
local abs = math.abs
local max = math.max
local min = math.min
local xor = bit32.bxor
local rot = bit32.rrotate
local mod = math.fmod
local function cheman(vec)
	return max(abs(vec.Y),abs(vec.X)+abs(vec.Z))
end
local function man(vec)
	return abs(vec.X)+abs(vec.Y)+abs(vec.Z)
end
local function che(vec)
	return max(abs(vec.X),abs(vec.Y),abs(vec.Z))
end
local function mag(vec)
	return vec.Magnitude
end
local function squircle(vec)
	return vec.X^4 + vec.Y^4 + vec.Z^4
end
local function off(x,y,z)
	local rx = noise(x*123.456,y*345.612,z*561.234)
	local ry = noise(x*345.612,z*123.456,y*561.234)
	local rz = noise(z*123.456,x*561.234,y*345.612)
	local res = vector(rx,ry,rz).Unit * 0.5
	return res,res + vector(x,y,z)
end
local pa = vector(0,0,0)
local pb = vector(1,0,0)
local pc = vector(0,1,0)
local pd = vector(0,0,1)
local pe = vector(1,1,0)
local pf = vector(0,1,1)
local pg = vector(1,0,1)
local ph = vector(1,1,1)
local function vor(x,y,z,fun)
	local fx = floor(x)
	local fy = floor(y)
	local fz = floor(z)
	local cx = ceil(x)
	local cy = ceil(y)
	local cz = ceil(z)
	local center = vector(x,y,z)-vector(fx,fy,fz)
	local av,aa = off(fx,fy,fz)
	local bv,ba = off(cx,fy,fz)
	local cv,ca = off(fx,cy,fz)
	local dv,da = off(fx,fy,cz)
	local ev,ea = off(cx,cy,fz)
	local fv,fa = off(fx,cy,cz)
	local gv,ga = off(cx,fy,cz)
	local hv,ha = off(cx,cy,cz)
	local a = fun(av+pa-center)
	local b = fun(bv+pb-center)
	local c = fun(cv+pc-center)
	local d = fun(dv+pd-center)
	local e = fun(ev+pe-center)
	local f = fun(fv+pf-center)
	local g = fun(gv+pg-center)
	local h = fun(hv+ph-center)
	local v = a
	local vv = aa
	if b < v then v = b vv = ba end
	if c < v then v = c vv = ca end
	if d < v then v = d vv = da end
	if e < v then v = e vv = ea end
	if f < v then v = f vv = fa end
	if g < v then v = g vv = ga end
	if h < v then v = h vv = ha end
	return 1-(v*2),vv
end

module.vor = vor
module.man = man
module.mag = mag
module.che = che
module.cheman = cheman

return module