local k={}function k.PointCloud(k,a)local P,z=k[1],k[1]:Dot(a)for S=2,#k,1 do local B=k[S]:Dot(a)if B>z then P=k[S]z=B end end return P end function k.Cylinder(k,a)local P,z=unpack(k)a=P:VectorToObjectSpace(a)local S=math.min(z.y,z.z)local B,M=a:Dot(RIGHT),Vector3.new(z.x,0,0)local R,Q,N if B==0 then N=a.Unit*S else M=B>0 and M or-M R,Q=rayPlane(ZERO,a,M,RIGHT)N=M+(R-M).Unit*S end return P:PointToWorldSpace(N)end function k.Ellipsoid(k,a)local P,z=unpack(k)return P:PointToWorldSpace(z*(z*P:VectorToObjectSpace(a)).Unit)end return k


local Supports = {}

function Supports.PointCloud(set, direction)
	local max, maxDot = set[1], set[1]:Dot(direction)
	for i = 2, #set do
		local dot = set[i]:Dot(direction)
		if (dot > maxDot) then
			max = set[i]
			maxDot = dot
		end
	end
	return max
end

function Supports.Cylinder(set, direction)
	local cf, size2 = unpack(set)
	direction = cf:VectorToObjectSpace(direction)
	local radius = math.min(size2.y, size2.z)
	local dotT, cPoint = direction:Dot(RIGHT), Vector3.new(size2.x, 0, 0)
	local h, t, final
	
	if (dotT == 0) then
		final = direction.Unit * radius
	else
		cPoint = dotT > 0 and cPoint or -cPoint
		h, t = rayPlane(ZERO, direction, cPoint, RIGHT)
		final = cPoint + (h - cPoint).Unit * radius
	end
	
	return cf:PointToWorldSpace(final)
end

function Supports.Ellipsoid(set, direction)
	local cf, size2 = unpack(set)
	return cf:PointToWorldSpace(size2 * (size2 * cf:VectorToObjectSpace(direction)).Unit)
end

return Supports
