internal void Reverse ()
{
ClearCache ();
// revert coordinates
for (int i=0, max = CoordsCount / 2; i < max;) {
int ix = i++;
int iy = i++;
int rix = CoordsCount - i;
int riy = rix + 1;
float tmpx = Coords [ix];
float tmpy = Coords [iy];
Coords [ix] = Coords [rix];
Coords [iy] = Coords [riy];
Coords [rix] = tmpx;
Coords [riy] = tmpy;
}
// revert types
sbyte [] newTypes = new sbyte [TypesCount];
int oldIdx = 0;
int newIdx = TypesCount - 1;
int copyStart;
int copyEnd;
sbyte mask1 = 0;
sbyte mask2 = 0;
sbyte closeMask = 0;
bool closedFigure = false;
while (oldIdx < TypesCount) {
// start copying after moveto
copyStart = ++oldIdx;
// continue to the next figure start
while ((Types [oldIdx] != SEG_MOVETO) && (oldIdx < TypesCount))
oldIdx++;
copyEnd = oldIdx - 1;
// check whenever current figure is closed
if ((Types [oldIdx - 1] & SEG_CLOSE) != 0) {
closedFigure = true;
// close figure
newTypes [newIdx--] = (sbyte)(SEG_CLOSE | mask1);
mask1 = 0;
mask2 = 0;
// end copy one cell earlier
copyEnd--;
closeMask = (sbyte)(Types [oldIdx - 1] & (sbyte)SEG_MARKER);
}
else {
mask2 = mask1;
mask1 = 0;
}
// copy reverted "inner" types
for(int i = copyStart; i <= copyEnd; i++) {
newTypes [newIdx--] = (sbyte)((Types [i] & SEG_MASK) | mask2);
mask2 = mask1;
mask1 = (sbyte)(Types [i] & (sbyte)SEG_MARKER);
}
// copy moveto
newTypes [newIdx--] = SEG_MOVETO;
// pass close mask to the nex figure
if (closedFigure) {
mask1 = closeMask;
closedFigure = false;
}
}
_types = newTypes;
}