//-------------------------------------------------------------------- public static void InvertPolygon(VertexStore myvxs, int start) { // Skip all non-vertices at the beginning 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; } InvertPolygon(myvxs, start, end); }
//-----------------------------------------------------bounding_rect_single //template<class VertexSource, class CoordT> static bool GetBoundingRect( VertexStoreSnap vs, out int x1, out int y1, out int x2, out int y2) { double x_d = 0; double y_d = 0; int x = 0; int y = 0; bool first = true; x1 = 1; y1 = 1; x2 = 0; y2 = 0; var vsnapIter = vs.GetVertexSnapIter(); VertexCmd PathAndFlags; while (!VertexHelper.IsEmpty(PathAndFlags = vsnapIter.GetNextVertex(out x_d, out y_d))) { x = (int)x_d; y = (int)y_d; if (VertexHelper.IsVertextCommand(PathAndFlags)) { if (first) { x1 = x; y1 = y; x2 = x; y2 = y; first = false; } else { if (x < x1) { x1 = x; } if (y < y1) { y1 = y; } if (x > x2) { x2 = x; } if (y > y2) { y2 = y; } } } } return(x1 <= x2 && y1 <= y2); }
//---------------------------------------------------------------- // 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); }
public static void FlipY(VertexStore vxs, double y1, double y2) { int i; double x, y; int count = vxs.Count; for (i = 0; i < count; ++i) { VertexCmd flags = vxs.GetVertex(i, out x, out y); if (VertexHelper.IsVertextCommand(flags)) { vxs.ReplaceVertex(i, x, y2 - y + y1); } } }