Update: see my C# GDI+ code that does what you want. You can easily write the same in C++: the GraphicsPath class is merely a thin wrapper over the corresponding gdiplus.dll functions.
static class GraphicsPathExt
{
[DllImport( @"gdiplus.dll" )]
static extern int GdipWindingModeOutline( HandleRef path, IntPtr matrix, float flatness );
static HandleRef getPathHandle( GraphicsPath p )
{
return new HandleRef( p, (IntPtr)p.GetType().GetField( "nativePath", BindingFlags.NonPublic | BindingFlags.Instance ).GetValue( p ) );
}
public static void FlattenPath( this GraphicsPath p )
{
HandleRef h = getPathHandle( p );
int status = GdipWindingModeOutline( h, IntPtr.Zero, 0.25F );
// TODO: see http://msdn.microsoft.com/en-us/library/ms534175(VS.85).aspx and throw a correct exception.
if( 0 != status )
throw new ApplicationException( "GDI+ error " + status.ToString() );
}
}
class Program
{
static void Main( string[] args )
{
PointF[] fig1 =
{
new PointF(-50, 0),
new PointF(0, 50),
new PointF(50, 0),
};
PointF[] fig2 =
{
new PointF(-50, 25),
new PointF(50, 25),
new PointF(0, -25),
};
GraphicsPath path1 = new GraphicsPath();
path1.AddLines( fig1 );
path1.CloseAllFigures();
GraphicsPath path2 = new GraphicsPath();
path2.AddLines( fig2 );
path2.CloseAllFigures();
GraphicsPath combined = new GraphicsPath();
combined.AddPath( path1, true );
combined.AddPath( path2, true );
combined.FlattenPath();
foreach (var p in combined.PathPoints)
{
Console.WriteLine( "<{0}, {1}>", p.X, p.Y );
}
}
}