//----------------------------------------------------------------
// Arrange the orientation of a polygon, all polygons in a path,
// or in all paths. After calling arrange_orientations() or
// arrange_orientations_all_paths(), all the polygons will have
// the same orientation, i.e. path_flags_cw or path_flags_ccw
//--------------------------------------------------------------------
static int ArrangePolygonOrientation(VertexStore myvxs, int start, bool clockwise)
{
//if (orientation == ShapePath.FlagsAndCommand.FlagNone) return start;
// Skip all non-vertices at the beginning
//ShapePath.FlagsAndCommand orientFlags = clockwise ? ShapePath.FlagsAndCommand.FlagCW : ShapePath.FlagsAndCommand.FlagCCW;
int vcount = myvxs.Count;
while (start < vcount &&
!VertexHelper.IsVertextCommand(myvxs.GetCommand(start)))
{
++start;
}
// Skip all insignificant move_to
while (start + 1 < vcount &&
VertexHelper.IsMoveTo(myvxs.GetCommand(start)) &&
VertexHelper.IsMoveTo(myvxs.GetCommand(start + 1)))
{
++start;
}
// Find the last vertex
int end = start + 1;
while (end < vcount && !VertexHelper.IsNextPoly(myvxs.GetCommand(end)))
{
++end;
}
if (end - start > 2)
{
bool isCW;
if ((isCW = IsCW(myvxs, start, end)) != clockwise)
{
// Invert polygon, set orientation flag, and skip all end_poly
InvertPolygon(myvxs, start, end);
VertexCmd flags;
int myvxs_count = myvxs.Count;
var orientFlags = isCW ? (int)EndVertexOrientation.CW : (int)EndVertexOrientation.CCW;
while (end < myvxs_count &&
VertexHelper.IsEndFigure(flags = myvxs.GetCommand(end)))
{
myvxs.ReplaceVertex(end++, orientFlags, 0);
//myvxs.ReplaceCommand(end++, flags | orientFlags);// Path.set_orientation(cmd, orientation));
}
}
}
return(end);
}