Beispiel #1
0
        public void invert_polygon(int start)
        {
            // Skip all non-vertices at the beginning
            while (start < vertices.total_vertices() &&
                   !ShapePath.is_vertex(vertices.command(start)))
            {
                ++start;
            }

            // Skip all insignificant move_to
            while (start + 1 < vertices.total_vertices() &&
                   ShapePath.is_move_to(vertices.command(start)) &&
                   ShapePath.is_move_to(vertices.command(start + 1)))
            {
                ++start;
            }

            // Find the last vertex
            int end = start + 1;

            while (end < vertices.total_vertices() &&
                   !ShapePath.is_next_poly(vertices.command(end)))
            {
                ++end;
            }

            invert_polygon(start, end);
        }
Beispiel #2
0
        // 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
        //--------------------------------------------------------------------
        public int arrange_polygon_orientation(int start, ShapePath.FlagsAndCommand orientation)
        {
            if (orientation == ShapePath.FlagsAndCommand.FlagNone)
            {
                return(start);
            }

            // Skip all non-vertices at the beginning
            while (start < vertices.total_vertices() &&
                   !ShapePath.is_vertex(vertices.command(start)))
            {
                ++start;
            }

            // Skip all insignificant move_to
            while (start + 1 < vertices.total_vertices() &&
                   ShapePath.is_move_to(vertices.command(start)) &&
                   ShapePath.is_move_to(vertices.command(start + 1)))
            {
                ++start;
            }

            // Find the last vertex
            int end = start + 1;

            while (end < vertices.total_vertices() &&
                   !ShapePath.is_next_poly(vertices.command(end)))
            {
                ++end;
            }

            if (end - start > 2)
            {
                if (perceive_polygon_orientation(start, end) != orientation)
                {
                    // Invert polygon, set orientation flag, and skip all end_poly
                    invert_polygon(start, end);
                    ShapePath.FlagsAndCommand PathAndFlags;
                    while (end < vertices.total_vertices() &&
                           ShapePath.is_end_poly(PathAndFlags = vertices.command(end)))
                    {
                        vertices.modify_command(end++, PathAndFlags | orientation);                        // Path.set_orientation(cmd, orientation));
                    }
                }
            }
            return(end);
        }