local q=import("\046\046\047\097\115\115\105\103\110")local Z=import("\046\046\047\116\121\112\101\075\101\121")local S=import("\046\046\047\102\117\110\099\116\105\111\110\115\047\116\121\112\101\111\102")local B=import("\046\047\086\101\099\116\111\114\050")local C={}setmetatable(C,{__tostring=function()return"\082\101\099\116"end})local Y={}local O={}O[Z]="\082\101\099\116"function O.__index(Z,q)local S=(getmetatable(Z)).internal if S[q]~=nil then return S[q]end if Y[q]~=nil then return Y[q]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(q)),2)end function O.__eq(Z,q)return Z.Min==q.Min and Z.Max==q.Max end function C.new(...)if select("\035",...)==4 then local q,Z,S,Y=...if type(q)~="\110\117\109\098\101\114"or type(Z)~="\110\117\109\098\101\114"or type(S)~="\110\117\109\098\101\114"or type(Y)~="\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 C.new(B.new(q,Z),B.new(S,Y))end local Z,Y=...if S(Z)~="\086\101\099\116\111\114\050"or S(Y)~="\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 D={Min=Z;Max=Y,Width=Y.X-Z.X,Height=Y.Y-Z.Y}local G=newproxy(true)q(getmetatable(G),O);(getmetatable(G)).internal=D return G end return C
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
