20 #ifndef AGG_ELLIPSE_INCLUDED 21 #define AGG_ELLIPSE_INCLUDED 23 #include "agg_basics.h" 34 m_x(0.0), m_y(0.0), m_rx(1.0), m_ry(1.0), m_scale(1.0),
35 m_num(4), m_step(0), m_cw(
false) {}
37 ellipse(
double x,
double y,
double rx,
double ry,
38 unsigned num_steps=0,
bool cw=
false) :
39 m_x(x), m_y(y), m_rx(rx), m_ry(ry), m_scale(1.0),
40 m_num(num_steps), m_step(0), m_cw(cw)
42 if(m_num == 0) calc_num_steps();
45 void init(
double x,
double y,
double rx,
double ry,
46 unsigned num_steps=0,
bool cw=
false);
48 void approximation_scale(
double scale);
49 void rewind(
unsigned path_id);
50 unsigned vertex(
double* x,
double* y);
53 void calc_num_steps();
66 inline void ellipse::init(
double x,
double y,
double rx,
double ry,
67 unsigned num_steps,
bool cw)
76 if(m_num == 0) calc_num_steps();
80 inline void ellipse::approximation_scale(
double scale)
87 inline void ellipse::calc_num_steps()
89 double ra = (std::fabs(m_rx) + std::fabs(m_ry)) / 2;
90 double da = std::acos(ra / (ra + 0.125 / m_scale)) * 2;
91 m_num = uround(2*pi / da);
95 inline void ellipse::rewind(
unsigned)
101 inline unsigned ellipse::vertex(
double* x,
double* y)
106 return path_cmd_end_poly | path_flags_close | path_flags_ccw;
108 if(m_step > m_num)
return path_cmd_stop;
109 double angle = double(m_step) / double(m_num) * 2.0 * pi;
110 if(m_cw) angle = 2.0 * pi - angle;
111 *x = m_x + std::cos(angle) * m_rx;
112 *y = m_y + std::sin(angle) * m_ry;
114 return ((m_step == 1) ? path_cmd_move_to : path_cmd_line_to);