-- cuts part into two based on an axis aligned plane

local function slicePart(part, origin, normal)
	local verts = blockVerts(part.CFrame, part.Size/2);

	if (normal:Dot(POSITIVEDIR) < 0) then
		normal = -normal;
	end

	local distances = {};
	for i = 1, #verts do
		distances[#distances+1] = (verts[i] - origin):Dot(normal);
	end

	local min = math.min(unpack(distances));
	local max = math.max(unpack(distances));

	local v = part.Position - origin;
	local center = (v - v:Dot(normal)*normal) + origin;
	local size = part.Size - part.Size*normal;

	local pos1, size1;
	if (max >= 0.05) then
		pos1 = center + normal*max/2;
		size1 = size + max*normal;
	end

	local pos2, size2;
	if (min <= -0.05) then
		pos2 = center + normal*min/2;
		size2 = size - min*normal;
	end

	return pos1, size1, pos2, size2;
end
