unsigned vertex(double* x, double* y)
 {
     unsigned cmd = m_src->vertex(x, y);
     if(is_vertex(cmd))  ++m_points;
     if(is_move_to(cmd)) ++m_contours;
     return cmd;
 }
 //------------------------------------------------------------------------
 void vcgen_contour::add_vertex(double x, double y, unsigned cmd)
 {
     m_status = initial;
     if(is_move_to(cmd))
     {
         m_src_vertices.modify_last(vertex_dist(x, y));
     }
     else
     {
         if(is_vertex(cmd))
         {
             m_src_vertices.add(vertex_dist(x, y));
         }
         else
         {
             if(is_end_poly(cmd))
             {
                 m_closed = get_close_flag(cmd);
                 if(m_orientation == path_flags_none) 
                 {
                     m_orientation = get_orientation(cmd);
                 }
             }
         }
     }
 }
void vcgen_stroke::add_vertex(FX_FLOAT x, FX_FLOAT y, unsigned cmd)
{
    m_status = initial;
    if(is_move_to(cmd)) {
        m_src_vertices.modify_last(vertex_dist_cmd(x, y, cmd));
    } else {
        if(is_vertex(cmd)) {
            m_src_vertices.add(vertex_dist_cmd(x, y, cmd));
        } else {
            m_closed = get_close_flag(cmd);
        }
    }
}
 //------------------------------------------------------------------------
 void vcgen_bspline::add_vertex(double x, double y, unsigned cmd)
 {
     m_status = initial;
     if(is_move_to(cmd))
     {
         m_src_vertices.modify_last(point_d(x, y));
     }
     else
     {
         if(is_vertex(cmd))
         {
             m_src_vertices.add(point_d(x, y));
         }
         else
         {
             m_closed = get_close_flag(cmd);
         }
     }
 }
 //------------------------------------------------------------------------
 void vcgen_smooth_poly1::add_vertex(double x, double y, unsigned cmd)
 {
     m_status = initial;
     if(is_move_to(cmd))
     {
         m_src_vertices.modify_last(vertex_dist(x, y));
     }
     else
     {
         if(is_vertex(cmd))
         {
             m_src_vertices.add(vertex_dist(x, y));
         }
         else
         {
             m_closed = get_close_flag(cmd);
         }
     }
 }
Exemple #6
0
 //------------------------------------------------------------------------
 void vcgen_markers_term::add_vertex(double x, double y, unsigned cmd)
 {
     if(is_move_to(cmd))
     {
         if(m_markers.size() & 1)
         {
             // Initial state, the first coordinate was added.
             // If two of more calls of start_vertex() occures
             // we just modify the last one.
             m_markers.modify_last(coord_type(x, y));
         }
         else
         {
             m_markers.add(coord_type(x, y));
         }
     }
     else
     {
         if(is_vertex(cmd))
         {
             if(m_markers.size() & 1)
             {
                 // Initial state, the first coordinate was added.
                 // Add three more points, 0,1,1,0
                 m_markers.add(coord_type(x, y));
                 m_markers.add(m_markers[m_markers.size() - 1]);
                 m_markers.add(m_markers[m_markers.size() - 3]);
             }
             else
             {
                 if(m_markers.size())
                 {
                     // Replace two last points: 0,1,1,0 -> 0,1,2,1
                     m_markers[m_markers.size() - 1] = m_markers[m_markers.size() - 2];
                     m_markers[m_markers.size() - 2] = coord_type(x, y);
                 }
             }
         }
     }
 }
Exemple #7
0
    double path_length(VertexSource& vs, unsigned path_id = 0)
    {
        double len = 0.0;
        double start_x = 0.0;
        double start_y = 0.0;
        double x1 = 0.0;
        double y1 = 0.0;
        double x2 = 0.0;
        double y2 = 0.0;
        bool first = true;

        unsigned cmd;
        vs.rewind(path_id);
        while(!is_stop(cmd = vs.vertex(&x2, &y2)))
        {
            if(is_vertex(cmd))
            {
                if(first || is_move_to(cmd))
                {
                    start_x = x2;
                    start_y = y2;
                }
                else
                {
                    len += calc_distance(x1, y1, x2, y2);
                }
                x1 = x2;
                y1 = y2;
                first = false;
            }
            else
            {
                if(is_close(cmd) && !first)
                {
                    len += calc_distance(x1, y1, start_x, start_y);
                }
            }
        }
        return len;
    }
    unsigned conv_adaptor_vpgen<VertexSource, VPGen>::vertex(double* x, double* y)
    {
        unsigned cmd = path_cmd_stop;
        for(;;)
        {
            cmd = m_vpgen.vertex(x, y);
            if(!is_stop(cmd)) break;

            if(m_poly_flags && !m_vpgen.auto_unclose())
            {
                *x = 0.0;
                *y = 0.0;
                cmd = m_poly_flags;
                m_poly_flags = 0;
                break;
            }

            if(m_vertices < 0)
            {
                if(m_vertices < -1) 
                {
                    m_vertices = 0;
                    return path_cmd_stop;
                }
                m_vpgen.move_to(m_start_x, m_start_y);
                m_vertices = 1;
                continue;
            }

            double tx, ty;
            cmd = m_source->vertex(&tx, &ty);
            if(is_vertex(cmd))
            {
                if(is_move_to(cmd)) 
                {
                    if(m_vpgen.auto_close() && m_vertices > 2)
                    {
                        m_vpgen.line_to(m_start_x, m_start_y);
                        m_poly_flags = path_cmd_end_poly | path_flags_close;
                        m_start_x    = tx;
                        m_start_y    = ty;
                        m_vertices   = -1;
                        continue;
                    }
                    m_vpgen.move_to(tx, ty);
                    m_start_x  = tx;
                    m_start_y  = ty;
                    m_vertices = 1;
                }
                else 
                {
                    m_vpgen.line_to(tx, ty);
                    ++m_vertices;
                }
            }
            else
            {
                if(is_end_poly(cmd))
                {
                    m_poly_flags = cmd;
                    if(is_closed(cmd) || m_vpgen.auto_close())
                    {
                        if(m_vpgen.auto_close()) m_poly_flags |= path_flags_close;
                        if(m_vertices > 2)
                        {
                            m_vpgen.line_to(m_start_x, m_start_y);
                        }
                        m_vertices = 0;
                    }
                }
                else
                {
                    // path_cmd_stop
                    if(m_vpgen.auto_close() && m_vertices > 2)
                    {
                        m_vpgen.line_to(m_start_x, m_start_y);
                        m_poly_flags = path_cmd_end_poly | path_flags_close;
                        m_vertices   = -2;
                        continue;
                    }
                    break;
                }
            }
        }
        return cmd;
    }