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


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;
