title: Polygon difference - strange results from Clipperlib
body: <p>I am trying to create iso-area polygons ("donuts") from a set of contours. This is the process:</p>
  
  <ol>
  <li>Generate the contours.</li>
  <li>Sort the contours into a tree structure, such that all contours held within a specific contour are children of that contour.</li>
  <li>For each contour, execute a difference operation with all of its children, using Clipperlib.</li>
  </ol>
  
  <p>The resulting polygon(s) and holes constitute the iso-area "donut". These iso-areas can then be rendered as a contour map, or used for other purposes. Note that if all I wanted to do was render the contours, I could stop after the initial sort and render the contours in order, such that inner-most render on top. I do require the actual areas.</p>
  
  <p>First up - Clipperlib is a fantastic library, and one that I would be very happy to pay good money for - thanks Angus!</p>
  
  <p>My issue is that I seem to get some strange results from the difference operation in certain situations - I suspect this may be user error on my part, so I will illustrate the problem:</p>
  
  <p><img src="https://i.stack.imgur.com/g2T70.jpg" alt="image one"></p>
  
  <p>This image shows two polygons - the subject is outlined in red, and the children are filled in blue. I wish to subtract the children from the subject. Note the small area near the mouse-pointer. What I would expect from this diff is two outer polygons - the small one near the mouse pointer and the large one. I would further expect all of the "islands" to be holes within the second, large, polygon.</p>
  
  <p>What I actually get is two outers (as expected), with children (holes) associated with each:</p>
  
  <p><img src="https://i.stack.imgur.com/RIIH6.jpg" alt="image two"></p>
  
  <p><img src="https://i.stack.imgur.com/0FUdq.jpg" alt="enter image description here"></p>
  
  <p>In the second image, the tiny polygon near the mouse pointer is the "outer", and all of the other filled polygons are "holes" belonging to it. Note that I show the outlines of both solutions in both images - just focus on the filled polygons.</p>
  
  <p>I am executing clipperlib using the red polygon in the first image as the subject, and all of the children as clips. Clip type is ctDifference (I have also tried Xor with the same results - which they should be, given that all children are within the subject).
  I am requesting a PolyTree back, which has two Childs. I am using the c# library, and have also tried v6.</p>
  
  <p>On one level, the results that I need are all there - all of the "holes" are designated such, the problem is that many of these holes are returned as children of the tiny outer area at the top-right of the image. Am I reading the PolyTree incorrectly, using ClipperLib incorrectly, or is this result simply wrong?</p>
  
  <p>On a further note - I noticed that the new ClipperLib (v6) now accepts Z values. I'm wondering now if there may be a better method than I am using for generating these iso-areas from a given collection of un-ordered contour lines?</p>
  
  <p>thanks,
  Matt</p>
  
  <p>EDIT: I have uploaded the raw data for the polygons in a text file.</p>
  
  <p><a href="http://wikisend.com/download/926930/polygons.txt" rel="nofollow noreferrer">here is the link</a></p>
  
  <p>The file has the subject polygon as the first set of vertices, followed by each of the children. Each polygon is represented as X/Y pairs on a single row, with a newline between each polygon.</p>