local u={}function u.new(q,h)local S=setmetatable({},{__index=u})S.CFrame=q S.Planes={{n=q:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Top));d=-h.y/2};{n=q:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Bottom));d=-h.y/2},{n=q:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Left)),d=-h.x/2},{n=q:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Right));d=-h.x/2};{n=q:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Front));d=-h.z/2},{n=q:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Back)),d=-h.z/2}}return S end function getCorners(u)local q,h=u.Size/2,{}for S=-1,1,2 do for Y=-1,1,2 do for p=-1,1,2 do table.insert(h,(u.CFrame*CFrame.new(q*Vector3.new(S,Y,p))).p)end end end return h end function u.CastPart(q,u)local h=getCorners(u)for u,h in next,h do local S=h-q.CFrame.p local Y=true for u,q in next,q.Planes do if S:Dot(q.n)+q.d>=0 then Y=false break end end if Y then return true end end return false end return u
-- Ego's version

local region = {}

function region.new(cframe, size)
	local self = setmetatable({}, { __index = region })

	self.CFrame = cframe
	self.Planes = {
		{ n = cframe:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Top)), d = -size.y / 2 },
		{ n = cframe:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Bottom)), d = -size.y / 2 },
		{ n = cframe:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Left)), d = -size.x / 2 },
		{ n = cframe:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Right)), d = -size.x / 2 },
		{ n = cframe:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Front)), d = -size.z / 2 },
		{ n = cframe:vectorToWorldSpace(Vector3.FromNormalId(Enum.NormalId.Back)), d = -size.z / 2 },
	}

	return self
end

function getCorners(part)
	local size, corners = part.Size / 2, {}
	for x = -1, 1, 2 do
		for y = -1, 1, 2 do
			for z = -1, 1, 2 do
				table.insert(corners, (part.CFrame * CFrame.new(size * Vector3.new(x, y, z))).p)
			end
		end
	end
	return corners
end

function region:CastPart(part)
	local corners = getCorners(part)
	for _, corner in next, corners do
		local position = corner - self.CFrame.p
		local isInRegion = true
		for _, plane in next, self.Planes do
			if (position:Dot(plane.n) + plane.d) >= 0 then
				isInRegion = false
				break
			end
		end
		if isInRegion then
			return true
		end
	end
	return false
end

return region
