title: how to handle Horizantal in Polyfill Algorithm?
body: <p>I have a shape, it's look alike this:
  <a href="https://i.stack.imgur.com/OxyPa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OxyPa.png" alt="enter image description here"></a><br>
  alright, according to <a href="https://www.youtube.com/watch?v=TNbkX5bYrtE" rel="nofollow noreferrer">polyfill algorithm</a> to fill the color in the area i need to pass scan lines.<br>
  I've provided 6 scan lines.</p>
  
  <p><strong>Scan 1</strong>: start from <code>y=-1</code> like so:
  <a href="https://i.stack.imgur.com/ORQ6u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ORQ6u.png" alt="enter image description here"></a><br>
  you know if the previous vertex/point and next vertex/point are on same side, it will not consider as intersection.</p>
  
  <pre><code>#list of lines that each line contain [(startpoint, endpoint)]
  listLines = [[(4,-1),(4,-2)]]
  </code></pre>
  
  <p><strong>Scan 2</strong>: start from <code>y=-2</code> like so:
  <a href="https://i.stack.imgur.com/a851n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a851n.png" alt="enter image description here"></a><br>
  same thing happen in here since <strong>Point13</strong> and <strong>Point15</strong> are in same sides <strong>Point14</strong> is not consider as intersection, as well as <strong>Point9</strong> (cause <strong>Point10</strong> and <strong>Point8</strong> are in same side).</p>
  
  <pre><code>#list of lines that each line contain [(startpoint, endpoint)]
  listLines = [[(1.7,-2),(6.5,-2)]]
  </code></pre>
  
  <p><strong>Scan 3</strong>: start from <code>y=-3</code> like so:
  <a href="https://i.stack.imgur.com/1aOSC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1aOSC.png" alt="enter image description here"></a><br>
  but here is the confusion part, now i don't get the Horizontal line.</p>
  
  <pre><code>#list of lines that each line contain [(startpoint, endpoint)]
  listLines = [[(2.4,-3),(7,-3)],[(9,-3),(10.5,-3)]]
  </code></pre>
  
  <p><strong>Scan 4</strong>: start from <code>y=-4</code> like so:
  <a href="https://i.stack.imgur.com/4gwig.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4gwig.png" alt="enter image description here"></a><br>
  and also in here i only get the horizontal lines!!</p>
  
  <pre><code>#list of lines that each line contain [(startpoint, endpoint)]
  listLines = [[(2,-4),(3,-4)],[(5,-4),(8,-4)]]
  </code></pre>
  
  <p><strong>Scan 5</strong>: start from <code>y=-5</code> like so:
  <a href="https://i.stack.imgur.com/hATOx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hATOx.png" alt="enter image description here"></a>  </p>
  
  <p>in here everything work perfectly.</p>
  
  <pre><code>#list of lines that each line contain [(startpoint, endpoint)]
  listLines = [[(3.5,-5),(5,-5)],[(6,-5),(9.5,-5)]]
  </code></pre>
  
  <p><strong>Scan 6</strong>: start from <code>y=-6</code> like so:
  <a href="https://i.stack.imgur.com/yKZzm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yKZzm.png" alt="enter image description here"></a><br>
  in here also work perfectly and i get no intersection.</p>
  
  <pre><code>#list of lines that each line contain [(startpoint, endpoint)]
  listLines = []
  </code></pre>
  
  <p>when i look at polyfill algorithm tutorials/articles or examples, nothing mentioned about how to handle Horizontal lines. anyone has any idea how horizontal lines should be handled?</p>
  
  <p><strong>Note:</strong> so from my understanding:<br>
  if next and previous lines are in same side, Don't count any intersection like so:<br>
  <a href="https://i.stack.imgur.com/keFy8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/keFy8.png" alt="enter image description here"></a><br>
  but if next and previous lines are in opposite side like so:<br>
  <a href="https://i.stack.imgur.com/Ex3kh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ex3kh.png" alt="enter image description here"></a><br>
  I have to look at my total number of vertex so far that i collected.</p>
  
  <p>1- If Even, I've to add the first intersection.<br>
  2- If Odd, I've to add the last intersection.</p>
  
  <p>but it wont work if lines are laid on the scan line!!. take a look at this example:
  <a href="https://i.stack.imgur.com/AnSDY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AnSDY.png" alt="enter image description here"></a></p>
  
  <p>so in order to solve this problem, i come up with a solution that i need to run an optimization and rebuild the shape, simply by finding every line equation and for those that having same equation, remove the share vertex, which would make the shape simple so there wont be any extra vertex on any lines. </p>
  
  <p>that's just do strange that they come so far about scan line algorithm but didn't mention anything about overlapping line equations. isn't it?</p>