> Unfortunately it only works when the line segments represent a complete cycle
Nope!
You just have to handle the case that $next becomes undef and leave the loop.
The problem I rather see is to choose a starting point!
Simplest solution: you choose one arbitrary edge and walk in both directions.
Since %neighbour is symmetric this shouldn't be a problem, just swap the orientation of the start segment.
I'm on mobile and I want you to understand the algorithm...so no code. :)
Cheers Rolf
( addicted to the Perl Programming Language)
|