merge the formfield patch from ooo-build
[ooovba.git] / agg / source / agg_arc.cpp
blobdd812a8bbfb44bce0176a478ee5b04a8496f48d0
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
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.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 // Arc vertex generator
18 //----------------------------------------------------------------------------
20 #include <math.h>
21 #include "agg_arc.h"
24 namespace agg
26 //------------------------------------------------------------------------
27 arc::arc(double x, double y,
28 double rx, double ry,
29 double a1, double a2,
30 bool ccw) :
31 m_x(x), m_y(y), m_rx(rx), m_ry(ry), m_scale(1.0)
33 normalize(a1, a2, ccw);
36 //------------------------------------------------------------------------
37 void arc::init(double x, double y,
38 double rx, double ry,
39 double a1, double a2,
40 bool ccw)
42 m_x = x; m_y = y;
43 m_rx = rx; m_ry = ry;
44 normalize(a1, a2, ccw);
47 //------------------------------------------------------------------------
48 void arc::approximation_scale(double s)
50 m_scale = s;
51 if(m_initialized)
53 normalize(m_start, m_end, m_ccw);
57 //------------------------------------------------------------------------
58 void arc::rewind(unsigned)
60 m_path_cmd = path_cmd_move_to;
61 m_angle = m_start;
64 //------------------------------------------------------------------------
65 unsigned arc::vertex(double* x, double* y)
67 if(is_stop(m_path_cmd)) return path_cmd_stop;
68 if((m_angle < m_end) != m_ccw)
70 *x = m_x + cos(m_end) * m_rx;
71 *y = m_y + sin(m_end) * m_ry;
72 m_path_cmd = path_cmd_stop;
73 return path_cmd_line_to;
76 *x = m_x + cos(m_angle) * m_rx;
77 *y = m_y + sin(m_angle) * m_ry;
79 m_angle += m_da;
81 unsigned pf = m_path_cmd;
82 m_path_cmd = path_cmd_line_to;
83 return pf;
86 //------------------------------------------------------------------------
87 void arc::normalize(double a1, double a2, bool ccw)
89 m_da = fabs(1.0 / ((m_rx + m_ry) * 0.5 * m_scale));
90 if(ccw)
92 while(a2 < a1) a2 += pi * 2.0;
94 else
96 while(a1 < a2) a1 += pi * 2.0;
97 m_da = -m_da;
99 m_ccw = ccw;
100 m_start = a1;
101 m_end = a2;
102 m_initialized = true;