I'm implementing export-to-pdf in my triangle drawing app. The image above shows what the pdf output looks like. There are white boundaries everywhere, less than 1 pixel wide.
The triangles can have any color.
I draw each triangle, like this:
CGContextBeginPath(context);
CGContextMoveToPoint(context, x0, y0);
CGContextAddLineToPoint(context, x1, y1);
CGContextAddLineToPoint(context, x2, y2);
CGContextClosePath(context);
CGContextFillPath(context);
It's important that black and white triangles have the same sizes.
Draw a 1 pixel thick stroke around all triangles.
Extrude all triangles by 2 pixels so the triangles overlaps.
Combine touching triangles into a single polygon.
Perhaps PDF has settings for eliminating boundaries. Dunno.
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.
Is there a better way of snapping triangles together?
I'm using GPC – General Polygon Clipper library and it almost works as desired.
I run a UNION operation one triangle at a time. Until all triangles have been UNION'ed into the result.
Below is output from GPC. No white edges can be seen.
I also tried using Angus Johnson's Clipper library, but was unable to built polygons by UNIONing one triangle at a time. It only removed a few of the white edges between triangles. Although Clipper seems more powerful than GPC.
Below is output from Clipper, it shows white edges.