title: Combine two segments on the same circle if they overlap or intersect
body: <p>I am try to combine two segments if they overlap or intersect.My question is similar to <a href="https://stackoverflow.com/questions/11775473/check-if-two-segments-on-the-same-circle-overlap-intersect">this</a> and <a href="https://stackoverflow.com/questions/37884021/calculating-the-intersection-between-two-angle-intervals">this</a>. However, what I want is to combine two segments. </p>
  
  <pre><code>public class Segment
  {
      private readonly double _from;
      private readonly double _to;
      public Segment(double from, double to)
      {
          _from = Normalize(from); // 0 &lt;= x &lt; 360
          _to = Normalize(to);
      }
  
      public bool Inside(double target)
      {
          if (_from &lt; _to)
              return _from &lt;= target &amp;&amp; target &lt;= _to;
          return _from &lt;= target || target &lt;= _to;
      }
  }
  </code></pre>
  
  <p>I am trying to write a <code>TryCombine()</code>.</p>
  
  <pre><code>public bool TryCombine(Segment other, out Segment result)
  {
      // if not intersect
      // return false
  
      // else if overlap
      // return true, out larger one
  
      // else if intersect
      // return true, out a new one with merged bound
  }
  </code></pre>
  
  <p>Expected Result</p>
  
  <pre><code>var seg1 = new Segment(0, 100);
  var seg2 = new Segment(50, 150);
  var seg3 = new Segment(110, -100);
  var seg4 = new Segment(10, 50);
  Segment result;
  
  seg1.TryCombine(seg2, result); // True, result = Segment(0, 150)
  seg1.TryCombine(seg3, result); // False
  seg1.TryCombine(seg4, result); // True, result = Segment(0, 100)
  seg2.TryCombine(seg3, result); // True, result = Segment(260, 150)
  </code></pre>