⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agg_path_storage.cpp

📁 okular
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    {        rel_to_abs(&dx_ctrl1, &dy_ctrl1);        rel_to_abs(&dx_ctrl2, &dy_ctrl2);        rel_to_abs(&dx_to,    &dy_to);        add_vertex(dx_ctrl1, dy_ctrl1, path_cmd_curve4);        add_vertex(dx_ctrl2, dy_ctrl2, path_cmd_curve4);        add_vertex(dx_to,    dy_to,    path_cmd_curve4);    }    //------------------------------------------------------------------------    void path_storage::curve4(double x_ctrl2, double y_ctrl2,                               double x_to,    double y_to)    {        double x0;        double y0;        if(is_vertex(last_vertex(&x0, &y0)))        {            double x_ctrl1;            double y_ctrl1;             unsigned cmd = prev_vertex(&x_ctrl1, &y_ctrl1);            if(is_curve(cmd))            {                x_ctrl1 = x0 + x0 - x_ctrl1;                y_ctrl1 = y0 + y0 - y_ctrl1;            }            else            {                x_ctrl1 = x0;                y_ctrl1 = y0;            }            curve4(x_ctrl1, y_ctrl1, x_ctrl2, y_ctrl2, x_to, y_to);        }    }    //------------------------------------------------------------------------    void path_storage::curve4_rel(double dx_ctrl2, double dy_ctrl2,                                   double dx_to,    double dy_to)    {        rel_to_abs(&dx_ctrl2, &dy_ctrl2);        rel_to_abs(&dx_to,    &dy_to);        curve4(dx_ctrl2, dy_ctrl2, dx_to, dy_to);    }    //------------------------------------------------------------------------    void path_storage::end_poly(unsigned flags)    {        if(m_total_vertices)        {            if(is_vertex(command(m_total_vertices - 1)))            {                add_vertex(0.0, 0.0, path_cmd_end_poly | flags);            }        }    }    //------------------------------------------------------------------------    unsigned path_storage::start_new_path()    {        if(m_total_vertices)        {            if(!is_stop(command(m_total_vertices - 1)))            {                add_vertex(0.0, 0.0, path_cmd_stop);            }        }        return m_total_vertices;    }    //------------------------------------------------------------------------    void path_storage::add_poly(const double* vertices, unsigned num,                                bool solid_path, unsigned end_flags)    {        if(num)        {            if(!solid_path)            {                move_to(vertices[0], vertices[1]);                vertices += 2;                --num;            }            while(num--)            {                line_to(vertices[0], vertices[1]);                vertices += 2;            }            if(end_flags) end_poly(end_flags);        }    }    //------------------------------------------------------------------------    unsigned path_storage::perceive_polygon_orientation(unsigned idx,                                                        double xs, double ys,                                                        unsigned* orientation)    {        unsigned i;        double sum = 0.0;        double x, y, xn, yn;        x = xs;        y = ys;        for(i = idx; i < m_total_vertices; ++i)        {            if(is_next_poly(vertex(i, &xn, &yn))) break;            sum += x * yn - y * xn;            x = xn;            y = yn;        }        if(i > idx) sum += x * ys - y * xs;        *orientation = path_flags_none;        if(sum != 0.0)        {            *orientation = (sum < 0.0) ? path_flags_cw : path_flags_ccw;        }        return i;    }    //------------------------------------------------------------------------    void path_storage::reverse_polygon(unsigned start, unsigned end)    {        unsigned i;        unsigned tmp_cmd = command(start);                // Shift all commands to one position        for(i = start; i < end; i++)        {            modify_command(i, command(i + 1));        }        // Assign starting command to the ending command        modify_command(end, tmp_cmd);        // Reverse the polygon        while(end > start)        {            unsigned start_nb = start >> block_shift;            unsigned end_nb   = end   >> block_shift;            double* start_ptr = m_coord_blocks[start_nb] + ((start & block_mask) << 1);            double* end_ptr   = m_coord_blocks[end_nb]   + ((end   & block_mask) << 1);            double tmp_xy;            tmp_xy       = *start_ptr;            *start_ptr++ = *end_ptr;            *end_ptr++   = tmp_xy;            tmp_xy       = *start_ptr;            *start_ptr   = *end_ptr;            *end_ptr     = tmp_xy;            tmp_cmd = m_cmd_blocks[start_nb][start & block_mask];            m_cmd_blocks[start_nb][start & block_mask] = m_cmd_blocks[end_nb][end & block_mask];            m_cmd_blocks[end_nb][end & block_mask] = (unsigned char)tmp_cmd;            ++start;            --end;        }    }    //------------------------------------------------------------------------    unsigned path_storage::arrange_orientations(unsigned path_id,                                                 path_flags_e new_orientation)    {        unsigned end = m_total_vertices;        if(m_total_vertices && new_orientation != path_flags_none)        {            unsigned start = path_id;            double xs, ys;            unsigned cmd = vertex(start, &xs, &ys);            unsigned inc = 0;            for(;;)            {                unsigned orientation;                end = perceive_polygon_orientation(start + 1, xs, ys,                                                    &orientation);                if(end > start + 2 &&                   orientation &&                    orientation != unsigned(new_orientation))                {                    reverse_polygon(start + inc, end - 1);                }                if(end >= m_total_vertices) break;                cmd = command(end);                if(is_stop(cmd))                 {                    ++end;                    break;                }                if(is_end_poly(cmd))                {                    inc = 1;                    modify_command(end, set_orientation(cmd, new_orientation));                }                else                {                    cmd = vertex(++end, &xs, &ys);                    inc = 0;                }                start = end;            }        }        return end;    }    //------------------------------------------------------------------------    void path_storage::arrange_orientations_all_paths(path_flags_e new_orientation)    {        if(new_orientation != path_flags_none)        {            unsigned start = 0;            while(start < m_total_vertices)            {                start = arrange_orientations(start, new_orientation);            }        }    }    //------------------------------------------------------------------------    void path_storage::flip_x(double x1, double x2)    {        unsigned i;        double x, y;        for(i = 0; i < m_total_vertices; i++)        {            unsigned cmd = vertex(i, &x, &y);            if(is_vertex(cmd))            {                modify_vertex(i, x2 - x + x1, y);            }        }    }    //------------------------------------------------------------------------    void path_storage::flip_y(double y1, double y2)    {        unsigned i;        double x, y;        for(i = 0; i < m_total_vertices; i++)        {            unsigned cmd = vertex(i, &x, &y);            if(is_vertex(cmd))            {                modify_vertex(i, x, y2 - y + y1);            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -