title: Algorithm to identify segment chains
body: <p>I have an array of segments:</p>
  
  <pre class="lang-cs prettyprint-override"><code>ISegment[] segments
  </code></pre>
  
  <p>defined by an interface:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public interface ISegment
  {
      Point3D A { get; } // Segment start point
      Point3D B { get; } // Segment end point
  }
  </code></pre>
  
  <p>which can contain instances of:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class Line : ISegment
  {
      public Point3D A { get; } // Line start point
      public Point3D B { get; } // Line end point
      /* ... Other line properties &amp; methods ... */
  }
  </code></pre>
  
  <p>or instances of:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class Arc : ISegment
  {
      public Point3D A { get; } // Arc start point
      public Point3D B { get; } // Arc end point
      /* ... Other arc properties &amp; methods ... */
  }
  </code></pre>
  
  <p>and can be represented by this image:
  <a href="https://i.stack.imgur.com/t4RH7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t4RH7.png" alt="Segments representation"></a></p>
  
  <p>I am searching an elegant algorithm to identify them as segment chains:</p>
  
  <pre class="lang-cs prettyprint-override"><code>ISegment[][] segmentChains
  </code></pre>
  
  <p>where the result would be:</p>
  
  <pre class="lang-none prettyprint-override"><code>[[s1, s2, s3, s4], [s5, s6], [s7], [s8, s9, s10], [s11, s12]]
  </code></pre>
  
  <p>without any order consideration.</p>
  
  <p>Note:</p>
  
  <ul>
  <li>The input 1D array <code>segments</code> can have any order</li>
  <li>The output 2D array <code>segmentChains</code> can have any order</li>
  <li>Arc segment can have the same start and end point</li>
  </ul>
  
  <p>Some help will be welcome!</p>