Another approach:
m = Graphics[
Table[{Hue[RandomReal[]], Opacity[0.8],
InfiniteLine[RandomReal[{-1, 1}, {2, 2}]]}, {49}],
PlotRange -> {{-1, 1}, {-1, 1}}, Frame -> True]
Discretize it first:
mesh = DiscretizeGraphics[m];
Get internal lines and lines that defined boundaries:
blines =
Line[Tuples[
RegionBounds[
mesh]][[FindShortestTour[Tuples[RegionBounds[mesh]]][[2]]]]];
lines = MeshPrimitives[mesh, 1];
Split lines:
res = Region`Mesh`SplitIntersectingSegments[{lines, blines}];
segments =
DeleteDuplicates[
Sort /@ Flatten[Map[Partition[#, 2, 1] &, res[[2]]], 1]];
coords = res[[1]];
Construct planar graphs:
g = Graph[Range[Length[coords]], UndirectedEdge @@@ segments,
VertexCoordinates -> coords, VertexStyle -> Black,
VertexShapeFunction -> "Point", VertexSize -> Tiny]
Find planar faces (need to filter out the outer face):
faces = DeleteCases[PlanarFaceList[g],
x_ /; NegativelyOrientedPoints[coords[[x[[;; 3]]]]], 1];
Length[faces]
873
Show[{Graphics[
GraphicsComplex[
coords, {Opacity[.7],
Thread[{RandomColor[Length[faces]], Polygon /@ faces}]}],
PlotRange -> {{-1, 1}, {-1, 1}}], m}]
To split other shapes like a disk:
Show[{Graphics[Disk[]], m}]
disk = BoundaryDiscretizeGraphics[Disk[]];
blines = MeshPrimitives[disk, 1];
res = Region`Mesh`SplitIntersectingSegments[{lines, blines}];
segments =
DeleteDuplicates[
Sort /@ Flatten[Map[Partition[#, 2, 1] &, res[[2]]], 1]];
coords = res[[1]];
segments = Select[segments, RegionWithin[disk, Line[coords[[#]]]] &];
g = First[IndexGraph@First[
ConnectedGraphComponents@
Graph[Range[Length[coords]], UndirectedEdge @@@ segments,
VertexCoordinates -> coords, VertexStyle -> Black,
VertexShapeFunction -> "Point", VertexSize -> Tiny]]
facescoords = DeleteCases[PlanarFaceList[g], GraphEmbedding[g];
faces = PlanarFaceList[g];
max x_= Max[Length /;@ NegativelyOrientedPoints[coords[[x[[;;faces];
faces 3]]]]]= Select[PlanarFaceList[g], 1];(Length[#] != max) &];
Show[{Graphics[
GraphicsComplex[
coords, {EdgeForm[Black], Opacity[.7],
Thread[{RandomColor[Length[faces]], Polygon /@ faces}]}],
PlotRange -> {{-1, 1}, {-1, 1}}], m}]]]