local F=(game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\087\111\114\108\100\069\110\103\105\110\101")local t=require(F:WaitForChild("\079\098\106\101\099\116"))local l=require(F:WaitForChild("\116"))local B=l.tuple(l.Vector3,l.Vector3,l.optional(l.CFrame),l.optional(l.string))local A=t:Extend("\082\101\103\105\111\110")function A.constructor(U,F,t,l,A)assert(B(F,t,l,A))U._vec0=F U._vec1=t U._cframe=l or CFrame and CFrame.new(0,0,0)U._name=A or""end function A.GetName(F)return F._name end function A.GetPoint0(F)return F._vec0 end function A.GetPoint1(F)return F._vec1 end function A.ContainsPoint(t,F)assert(l.Vector3(F))local B,A=t._cframe,t._name local U=B:PointToObjectSpace(t._vec0)local v=B:PointToObjectSpace(t._vec1)local W=B:PointToObjectSpace(F)local j,b,w=W.X,W.Y,W.Z local z,Z,q=U.X,U.Y,U.Z local g,N,S=v.X,v.Y,v.Z local L=j>(z<g and z or g)local G=w>(q<S and q or S)local O=b>(Z<N and Z or N)local Y=j<(z>g and z or g)local D=w<(q>S and q or S)local V=b<(Z>N and Z or N)return L and(G and(Y and(D and(O and V)))),A end return A
local WorldEngine = game:GetService("ReplicatedStorage"):WaitForChild("WorldEngine")
local Object = require(WorldEngine:WaitForChild("Object"))
local t = require(WorldEngine:WaitForChild("t"))

local REGION_CONSTRUCTOR_ARGS = t.tuple(t.Vector3, t.Vector3, t.optional(t.CFrame), t.optional(t.string))

local Region = Object:Extend("Region")
function Region:constructor(vec0, vec1, cf, name)
	assert(REGION_CONSTRUCTOR_ARGS(vec0, vec1, cf, name))
	self._vec0 = vec0
	self._vec1 = vec1
	self._cframe = cf or (CFrame and CFrame.new(0, 0, 0))
	self._name = name or ""
end

function Region:GetName()
	return self._name
end

function Region:GetPoint0()
	return self._vec0
end

function Region:GetPoint1()
	return self._vec1
end

-- luacov: disable
-- this cannot be tested by Lemur... :(
function Region:ContainsPoint(point)
	assert(t.Vector3(point))

	local cframe, name = self._cframe, self._name
	local vec0 = cframe:PointToObjectSpace(self._vec0)
	local vec1 = cframe:PointToObjectSpace(self._vec1)

	local pPos = cframe:PointToObjectSpace(point)

	local px, py, pz = pPos.X, pPos.Y, pPos.Z -- point pos
	local v0x, v0y, v0z = vec0.X, vec0.Y, vec0.Z -- point0
	local v1x, v1y, v1z = vec1.X, vec1.Y, vec1.Z -- point1

	local boundsX = px > (v0x < v1x and v0x or v1x) --min(v0x, v1x);
	local boundsZ = pz > (v0z < v1z and v0z or v1z) --min(v0z, v1z);
	local boundsY = py > (v0y < v1y and v0y or v1y) --min(v0y, v1y);

	local boundsX1 = px < (v0x > v1x and v0x or v1x) --max(v0x, v1x);
	local boundsZ1 = pz < (v0z > v1z and v0z or v1z) --max(v0z, v1z);
	local boundsY1 = py < (v0y > v1y and v0y or v1y) --max(v0y, v1y);

	-- inRegion, regionName
	return (boundsX and boundsZ and boundsX1 and boundsZ1 and boundsY and boundsY1), name
end
-- luacov: enable

return Region
