title: Fixing the code for Line Clipping Algorithm
body: <p><a href="http://www.scribd.com/doc/272183353/Schaum-s-Outline-Computer-Graphics" rel="nofollow noreferrer">Midpoint subdivision algorithm</a> [page-93(104)]works on the basis of dividing a line into smaller segments and tests each segment to find whether they are within the visible boundary of the clipping region or not.</p>
  
  <p>In the Binary search algorithm, we find the middle element and then either choose right hand side or left hand side.</p>
  
  <p>But, here, as the following image shows, after first segmentation, we find that both of the subsections are actually disputed. So, both of them are candidates for further subdivisions. So, we can not proceed like Binary Search.</p>
  
  <p><img src="https://i.stack.imgur.com/22X3H.png" alt="enter image description here"></p>
  
  <p>I am using iterative method. But, the following code doesn't work:</p>
  
  <pre><code>    Line2d GetClippedLine()
      {
          Line2d clippingCandidate = this-&gt;line;
  
          std::vector&lt;Line2d&gt; lines = clippingCandidate.GetMidpointSubLines();
  
          while(lines[0] != lines[1])
          {
              lines = clippingCandidate.GetMidpointSubLines();
  
              Line2d one = lines[0];
              Line2d two = lines[1]; 
  
              if(one.IsClippingCandidate(rectangle))
              {
                  clippingCandidate = one;
              }
              if(two.IsClippingCandidate(rectangle))
              {           
                  clippingCandidate = two;
              }
  
              if(one.IsVisible(rectangle))
              {
                  Coordinates2d::Draw(one, Yellow);
              }
              if(two.IsVisible(rectangle))
              {
                  Coordinates2d::Draw(two, Yellow);
              }
  
              clippingCandidate.Show();
              //std::cout&lt;&lt;"++";
              //two.Show();
              std::cout&lt;&lt;"\n";
          }
  
          return clippingCandidate;
      }
  </code></pre>