local K=import("\046\046\047\097\115\115\105\103\110")local T=import("\046\046\047\116\121\112\101\075\101\121")local y=import("\046\046\047\102\117\110\099\116\105\111\110\115\047\116\121\112\101\111\102")local o=import("\046\047\086\101\099\116\111\114\050")local q={}setmetatable(q,{__tostring=function()return"\082\101\099\116"end})local A={}local H={}H[T]="\082\101\099\116"function H.__index(T,K)local y=(getmetatable(T)).internal if y[K]~=nil then return y[K]end if A[K]~=nil then return A[K]end error(string.format("\037\115 \105\115 \110\111\116 \097 \118\097\108\105\100 \109\101\109\098\101\114 \111\102 \082\101\099\116",tostring(K)),2)end function H.__eq(T,K)return T.Min==K.Min and T.Max==K.Max end function q.new(...)if select("\035",...)==4 then local K,T,y,A=...if type(K)~="\110\117\109\098\101\114"or type(T)~="\110\117\109\098\101\114"or type(y)~="\110\117\109\098\101\114"or type(A)~="\110\117\109\098\101\114"then error("\082\101\099\116\046\110\101\119\040\109\105\110\088\044 \109\105\110\089\044 \109\097\120\088\044 \109\097\120\089\041 \116\097\107\101\115 \105\110 \052 \110\117\109\098\101\114\115",2)end return q.new(o.new(K,T),o.new(y,A))end local T,A=...if y(T)~="\086\101\099\116\111\114\050"or y(A)~="\086\101\099\116\111\114\050"then error("\082\101\099\116\046\110\101\119\040\109\105\110\044 \109\097\120\041 \116\097\107\101\115 \105\110 \050 \086\101\099\116\111\114\050\115",2)end local R={Min=T,Max=A;Width=A.X-T.X,Height=A.Y-T.Y}local U=newproxy(true)K(getmetatable(U),H);(getmetatable(U)).internal=R return U end return q
local assign = import("../assign")
local typeKey = import("../typeKey")
local typeof = import("../functions/typeof")
local Vector2 = import("./Vector2")

local Rect = {}

setmetatable(Rect, {
	__tostring = function()
		return "Rect"
	end,
})

local prototype = {}

local metatable = {}
metatable[typeKey] = "Rect"

function metatable:__index(key)
	local internal = getmetatable(self).internal

	if internal[key] ~= nil then
		return internal[key]
	end

	if prototype[key] ~= nil then
		return prototype[key]
	end

	error(string.format("%s is not a valid member of Rect", tostring(key)), 2)
end

function metatable:__eq(other)
	return self.Min == other.Min and self.Max == other.Max
end

function Rect.new(...)
	if select("#", ...) == 4 then
		local minX, minY, maxX, maxY = ...
		if type(minX) ~= "number" or type(minY) ~= "number" or
			type(maxX) ~= "number" or type(maxY) ~= "number" then
			error("Rect.new(minX, minY, maxX, maxY) takes in 4 numbers", 2)
		end

		return Rect.new(
			Vector2.new(minX, minY),
			Vector2.new(maxX, maxY)
		)
	end

	local min, max = ...

	if typeof(min) ~= "Vector2" or typeof(max) ~= "Vector2" then
		error("Rect.new(min, max) takes in 2 Vector2s", 2)
	end

	local internalInstance = {
		Min = min,
		Max = max,
		Width = max.X - min.X,
		Height = max.Y - min.Y,
	}
	local instance = newproxy(true)

	assign(getmetatable(instance), metatable)
	getmetatable(instance).internal = internalInstance

	return instance
end

return Rect
