title: Fit Polygons Together
body: <h1>How to eliminate the boundary between triangles?</h1>
  
  <p><img src="https://i.stack.imgur.com/ds3AH.png" alt="black triangles with white boundaries"></p>
  
  <p>I'm implementing export-to-pdf in my <a href="http://triangledraw.com/" rel="nofollow noreferrer">triangle drawing app</a>. The image above shows what the pdf output looks like. There are white boundaries everywhere, less than 1 pixel wide.</p>
  
  <p>The triangles can have any color.</p>
  
  <hr>
  
  <p>I draw each triangle, like this:</p>
  
  <pre><code>CGContextBeginPath(context);
  CGContextMoveToPoint(context, x0, y0);
  CGContextAddLineToPoint(context, x1, y1);
  CGContextAddLineToPoint(context, x2, y2);
  CGContextClosePath(context);
  CGContextFillPath(context);
  </code></pre>
  
  <p>It's important that black and white triangles have the same sizes.</p>
  
  <hr>
  
  <h2>Approaches</h2>
  
  <h3>Approach 1 - Stroke</h3>
  
  <p>Draw a 1 pixel thick stroke around all triangles.</p>
  
  <h3>Approach 2 - Extrude</h3>
  
  <p>Extrude all triangles by 2 pixels so the triangles overlaps.</p>
  
  <h3>Approach 3 - Combine</h3>
  
  <p>Combine touching triangles into a single polygon.</p>
  
  <h3>Approach 4 - PDF overlap settings</h3>
  
  <p>Perhaps PDF has settings for eliminating boundaries. Dunno.</p>
  
  <h3>Approach 5 - Post processing</h3>
  
  <p>Create a filter that detects boundary pixels and eliminates them. This will not work for me, it needs to be saved to a PDF. Shader code is not supported in PDF on iOS, AFAIK.</p>
  
  <h3>Approach X - A smarter way</h3>
  
  <p>Is there a better way of snapping triangles together?</p>