in reply to Re^2: Combine line segments to form a single line
in thread Combine line segments to form a single line

Thanks Rolf, that is very similar to the approach I was attempting myself. Unfortunately it only works when the line segments represent a complete cycle - see my comment below.
  • Comment on Re^3: Combine line segments to form a single line

Replies are listed 'Best First'.
Re^4: Combine line segments to form a single line
by LanX (Saint) on Jan 13, 2014 at 14:51 UTC
    > 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)