title: Add square to polygon composed of squares
body: <p>I have a collection of 1*1 polygons, each of which is defined by its boundary (a set of four points) and I use the function <strong>area()</strong> below in my code example to create these. I wish to combine such adjacent squares into a single polygon, with this polygon also defined in terms of its boundary points. </p>
  
  <p>I wish to do this in a brute force fashion where I begin by adding two adjacent 1*1 squares to create a larger polygon using the function <strong>join()</strong> below and continue in this fashion in order to grow the polygon. So the first argument of join is the polygon so far and the second argument is an adjecent 1*1 square which I wish to add to the polygon. The return value is the boundary of the new polygon, <strong>current</strong> joined with the new 1*1.</p>
  
  <p>Here's what I've come with so far:</p>
  
  <pre><code>def join(current, new):
      """ current is the polygon, new the 1*1 square being added to it"""
      return get_non_touching_part_of_boundary(current, new)  + get_non_touching_part_of_boundary(new, current)
  
  def get_non_touching_part_of_boundary(this, other):
      for i,point in enumerate(this):
          if point not in other and this[i-1] in other:
              break # start of non touching boundary from a clockwise perspective
      non_touching_part_of_boundary = []
      for point in this[i:] + this[:i]:
          if not point in other:
              non_touching_part_of_boundary.append(point)
      return non_touching_part_of_boundary    
  
  def area(point):
      """ boundary defined in a clockwise fashion """
      return [point,(point[0],point[1]+1),(point[0]+1,point[1]+1),(point[0]+1,point[1])]
  
  a = area((0,1))            # a assigned a 1*1 polygon
  a = join(a, area((0,2)))   # a assigned a 2*1 polygon
  a = join(a, area((1,2)))    
  a = join(a, area((2,2)))    
  a = join(a, area((2,1)))    
  a = join(a, area((2,0)))    
  
  print(a)
  </code></pre>
  
  <p>This gives me the following polygon shape (with the numbers representing the order in which which its composing squares are added):</p>
  
  <pre><code>234
  1 5
    6
  </code></pre>
  
  <p>The printed output of the code above gives:</p>
  
  <pre><code>[(2, 2), (1, 2), (1, 1), (0, 1), (0, 3), (3, 3), (3, 0), (2, 0)]
  </code></pre>
  
  <p>this is the minimum number of points required to defined the boundary of the polygon. </p>
  
  <p>But if I add one more square to this shape via <strong>a = join(a, area((1,0)))</strong> and thereby creating a hole, my algorithm falls to pieces:</p>
  
  <pre><code>234
  1 5
   76
  </code></pre>
  
  <p>Here's another polygon that my algorithm can't handle:</p>
  
  <pre><code>123
   64
    5
  </code></pre>
  
  <p>Can anyone help me? I'd like the holes in the polygon to be listed in a separate list.</p>
  
  <p>Thank!</p>