1
//----------------------------------------------------------------------------
2
// Anti-Grain Geometry - Version 2.3
3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5
// Permission to copy, use, modify, sell and distribute this software
6
// is granted provided this copyright notice appears in all copies.
7
// This software is provided "as is" without express or implied
8
// warranty, and with no claim as to its suitability for any purpose.
10
//----------------------------------------------------------------------------
11
// Contact: mcseem@antigrain.com
12
// mcseemagg@yahoo.com
13
// http://www.antigrain.com
14
//----------------------------------------------------------------------------
16
// Smooth polygon generator
18
//----------------------------------------------------------------------------
20
#include "agg_vcgen_smooth_poly1.h"
25
//------------------------------------------------------------------------
26
vcgen_smooth_poly1::vcgen_smooth_poly1() :
36
//------------------------------------------------------------------------
37
void vcgen_smooth_poly1::remove_all()
39
m_src_vertices.remove_all();
45
//------------------------------------------------------------------------
46
void vcgen_smooth_poly1::add_vertex(double x, double y, unsigned cmd)
51
m_src_vertices.modify_last(vertex_dist(x, y));
57
m_src_vertices.add(vertex_dist(x, y));
61
m_closed = get_close_flag(cmd);
67
//------------------------------------------------------------------------
68
void vcgen_smooth_poly1::rewind(unsigned)
70
if(m_status == initial)
72
m_src_vertices.close(m_closed != 0);
79
//------------------------------------------------------------------------
80
void vcgen_smooth_poly1::calculate(const vertex_dist& v0,
81
const vertex_dist& v1,
82
const vertex_dist& v2,
83
const vertex_dist& v3)
86
double k1 = v0.dist / (v0.dist + v1.dist);
87
double k2 = v1.dist / (v1.dist + v2.dist);
89
double xm1 = v0.x + (v2.x - v0.x) * k1;
90
double ym1 = v0.y + (v2.y - v0.y) * k1;
91
double xm2 = v1.x + (v3.x - v1.x) * k2;
92
double ym2 = v1.y + (v3.y - v1.y) * k2;
94
m_ctrl1_x = v1.x + m_smooth_value * (v2.x - xm1);
95
m_ctrl1_y = v1.y + m_smooth_value * (v2.y - ym1);
96
m_ctrl2_x = v2.x + m_smooth_value * (v1.x - xm2);
97
m_ctrl2_y = v2.y + m_smooth_value * (v1.y - ym2);
101
//------------------------------------------------------------------------
102
unsigned vcgen_smooth_poly1::vertex(double* x, double* y)
104
unsigned cmd = path_cmd_line_to;
113
if(m_src_vertices.size() < 2)
119
if(m_src_vertices.size() == 2)
121
*x = m_src_vertices[m_src_vertex].x;
122
*y = m_src_vertices[m_src_vertex].y;
124
if(m_src_vertex == 1) return path_cmd_move_to;
125
if(m_src_vertex == 2) return path_cmd_line_to;
130
cmd = path_cmd_move_to;
137
if(m_src_vertex >= m_src_vertices.size())
139
*x = m_src_vertices[0].x;
140
*y = m_src_vertices[0].y;
142
return path_cmd_curve4;
147
if(m_src_vertex >= m_src_vertices.size() - 1)
149
*x = m_src_vertices[m_src_vertices.size() - 1].x;
150
*y = m_src_vertices[m_src_vertices.size() - 1].y;
152
return path_cmd_curve3;
156
calculate(m_src_vertices.prev(m_src_vertex),
157
m_src_vertices.curr(m_src_vertex),
158
m_src_vertices.next(m_src_vertex),
159
m_src_vertices.next(m_src_vertex + 1));
161
*x = m_src_vertices[m_src_vertex].x;
162
*y = m_src_vertices[m_src_vertex].y;
168
return ((m_src_vertex == 1) ?
174
if(m_src_vertex == 1)
177
return path_cmd_move_to;
179
if(m_src_vertex >= m_src_vertices.size() - 1)
182
return path_cmd_curve3;
185
return path_cmd_curve4;
193
return path_cmd_curve3;
199
return path_cmd_curve3;
205
return path_cmd_curve4;
211
return path_cmd_curve4;
215
return path_cmd_end_poly | m_closed;
218
return path_cmd_stop;