local D={}local n do local D=(CFrame.new()).pointToObjectSpace function n(n,X,b)local J=D(n,b)local r,G,e=X.x/2,X.y/2,X.z/2 local y,N,W=J.x,J.y,J.z return y*y<r*r and(N*N<G*G and W*W<e*e)end end local X do local D=(CFrame.new()).pointToObjectSpace function X(n,X,b,J)local r=D(n,b)local G,e,y=X.x/2,X.y/2,X.z/2 local N,W,F=r.x,r.y,r.z local p=N>G and N-G or N<-G and N+G or 0 local B=W>e and W-e or W<-e and W+e or 0 local A=F>y and F-y or F<-y and F+y or 0 return(p*p+B*B)+A*A<J*J end end
--[[
By AxisAngle, (Trey Reynolds)
Documentation
http://www.roblox.com/item.aspx?id=227509468

Region constructors:
	Region Region.new(CFrame RegionCFrame, Vector3 RegionSize)
		>Returns a new Region object

	Region Region.FromPart(Instance Part)
		>Returns a new Region objects


Region methods:
	table Region:Cast([Instance or table Ignore])
		>Returns all parts in the Region, ignoring the Ignore

	bool Region:CastPart(Instance Part)
		>Returns true if Part is within Region, false otherwise

	table Region:CastParts(table Parts)
		>Returns a table of all parts within the region

	bool Region:CastPoint(Vector3 Point)
		>Returns true if Point intersects Region, false otherwise

	bool Region:CastSphere(Vector3 SphereCenter, number SphereRadius)
		>Returns true if Sphere intersects Region, false otherwise

	bool Region:CastBox(CFrame BoxCFrame, Vector3 BoxSize)
		>Returns true if Box intersects Region, false otherwise



Region properties: (Regions are mutable)
	CFrame	CFrame
	Vector3	Size
	Region3	Region3



Region functions:
	Region3 Region.Region3BoundingBox(CFrame BoxCFrame, Vector3 BoxSize)
		>Returns the enclosing boundingbox of Box

	table Region.FindAllPartsInRegion3(Region3 Region3, [Instance or table Ignore])
		>Returns all parts within a Region3 of any size

	bool Region.BoxPointCollision(CFrame BoxCFrame, Vector3 BoxSize, Vector3 Point)
		>Returns true if the Point is intersecting the Box, false otherwise

	bool Region.BoxSphereCollision(CFrame BoxCFrame, Vector3 BoxSize, Vector3 SphereCenter, number SphereRadius)
		>Returns true if the Sphere is intersecting the Box, false otherwise

	bool Region.BoxCollision(CFrame Box0CFrame, Vector3 Box0Size, CFrame Box1CFrame, Vector3 Box1Size, [bool AssumeTrue])
		>Returns true if the boxes are intersecting, false otherwise
		If AssumeTrue is left blank, it does the full check to see if Box0 is intersecting Box1
		If AssumeTrue is true, it skips the heavy check and assumes that any part that could possibly be in the Region is
		If AssumeTrue is false, it skips the heavy check and assumes that any part that could possible be outside the Region is
	
	bool Region.CastPoint(Vector3 Point, [Instance or table Ignore])
		>Returns true if the point intersects a part, false otherwise
]]

local Region = {}

local BoxPointCollision
do
	local VecDiv = CFrame.new().pointToObjectSpace --Right Division, yo.
	function BoxPointCollision(CFrame, Size, Point)
		local Relative = VecDiv(CFrame, Point)
		local sx, sy, sz = Size.x / 2, Size.y / 2, Size.z / 2
		local rx, ry, rz = Relative.x, Relative.y, Relative.z
		return rx * rx < sx * sx and ry * ry < sy * sy and rz * rz < sz * sz
	end
end

local BoxSphereCollision
do
	local VecDiv = CFrame.new().pointToObjectSpace --Right Division, yo.
	function BoxSphereCollision(CFrame, Size, Center, Radius)
		local Relative = VecDiv(CFrame, Center)
		local sx, sy, sz = Size.x / 2, Size.y / 2, Size.z / 2
		local rx, ry, rz = Relative.x, Relative.y, Relative.z
		local dx = rx > sx and rx - sx --Faster than if statement
			or rx < -sx and rx + sx
			or 0
		local dy = ry > sy and ry - sy or ry < -sy and ry + sy or 0
		local dz = rz > sz and rz - sz or rz < -sz and rz + sz or 0
		return dx * dx + dy * dy + dz * dz < Radius * Radius
	end
end
