I have code (in C++) that draws various polygons on a map that uses a cylindrical projection (typically Mercator, sometimes Miller Equidistant if you want to be precise). For simple polygons, curves are drawn between vertices through a set of tiepoints such that the line roughly forms either the great circle segment or rhumb line between the two vertices. The more complex polygons also include arcs which generally don't form part of a great circle or rhumb line. At the time of drawing, the tiepoints that make up the polygons are translated into screen positions and drawn using built-in Windows C++ drawing commands.
For the most part, all my polygons and polylines are drawing fine, but I'm encountering problems when at least one line crosses the 180° meridian. My display is effectively limited to 180° W to 180° E.
One solution I've considered is to unwrap the points that make up the polygon, perform some mathematical wizardry to calculate the screen position for points outside of [-180, 180], and then draw the object twice, once for 180° W and then again for 180° E. Unfortunately this method falls apart if there are 2 consecutive crossings in the same direction. As unlikely as that is to happen in my case, the mere possibility has me worried. It also doesn't work for objects that enclose one of the poles.
Is there an algorithm for splitting a polygon along the 180° meridian while also properly closing it? Bonus points if it also works for polygons that enclose one of the poles. Extra bonus points if it'll also work for polar and/or conic projections (not currently supported, but may be required in a later project).