at each intersection, take a "right turn" jump onto the intersecting segment
add vertices to a new polygon ring
This could probably be done more quickly with some graph datastructures or possibly a sweepline. It will probably be O(n^2) at the fastest though. Also note that this approach throws out stray lines that do not intersect another segment. These could be wrapped as well using the method currently employed in a 2nd sweep.
Q: is this closer to the expected behavior of this tool? How does QGIS' Vector > Geometry Tools > Lines to polygons work?
rough algorithm:
This could probably be done more quickly with some graph datastructures or possibly a sweepline. It will probably be O(n^2) at the fastest though. Also note that this approach throws out stray lines that do not intersect another segment. These could be wrapped as well using the method currently employed in a 2nd sweep.
Q: is this closer to the expected behavior of this tool? How does QGIS' Vector > Geometry Tools >
Lines to polygons
work?