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 // classes curve3 and curve4
18 //----------------------------------------------------------------------------
21 #include "agg_curves.h"
26 //------------------------------------------------------------------------
27 void curve3::init(double x1
, double y1
,
41 double len
= sqrt(dx1
* dx1
+ dy1
* dy1
) + sqrt(dx2
* dx2
+ dy2
* dy2
);
43 m_num_steps
= int(len
* 0.25 * m_scale
);
50 double subdivide_step
= 1.0 / m_num_steps
;
51 double subdivide_step2
= subdivide_step
* subdivide_step
;
53 double tmpx
= (x1
- x2
* 2.0 + x3
) * subdivide_step2
;
54 double tmpy
= (y1
- y2
* 2.0 + y3
) * subdivide_step2
;
56 m_saved_fx
= m_fx
= x1
;
57 m_saved_fy
= m_fy
= y1
;
59 m_saved_dfx
= m_dfx
= tmpx
+ (x2
- x1
) * (2.0 * subdivide_step
);
60 m_saved_dfy
= m_dfy
= tmpy
+ (y2
- y1
) * (2.0 * subdivide_step
);
71 //------------------------------------------------------------------------
72 void curve3::rewind(unsigned)
89 //------------------------------------------------------------------------
90 unsigned curve3::vertex(double* x
, double* y
)
92 if(m_step
< 0) return path_cmd_stop
;
93 if(m_step
== m_num_steps
)
98 return path_cmd_move_to
;
105 return path_cmd_line_to
;
114 return path_cmd_line_to
;
129 //------------------------------------------------------------------------
130 void curve4::init(double x1
, double y1
,
131 double x2
, double y2
,
132 double x3
, double y3
,
133 double x4
, double y4
)
140 double dx1
= x2
- x1
;
141 double dy1
= y2
- y1
;
142 double dx2
= x3
- x2
;
143 double dy2
= y3
- y2
;
144 double dx3
= x4
- x3
;
145 double dy3
= y4
- y3
;
147 double len
= sqrt(dx1
* dx1
+ dy1
* dy1
) +
148 sqrt(dx2
* dx2
+ dy2
* dy2
) +
149 sqrt(dx3
* dx3
+ dy3
* dy3
);
151 m_num_steps
= int(len
* 0.25 * m_scale
);
158 double subdivide_step
= 1.0 / m_num_steps
;
159 double subdivide_step2
= subdivide_step
* subdivide_step
;
160 double subdivide_step3
= subdivide_step
* subdivide_step
* subdivide_step
;
162 double pre1
= 3.0 * subdivide_step
;
163 double pre2
= 3.0 * subdivide_step2
;
164 double pre4
= 6.0 * subdivide_step2
;
165 double pre5
= 6.0 * subdivide_step3
;
167 double tmp1x
= x1
- x2
* 2.0 + x3
;
168 double tmp1y
= y1
- y2
* 2.0 + y3
;
170 double tmp2x
= (x2
- x3
) * 3.0 - x1
+ x4
;
171 double tmp2y
= (y2
- y3
) * 3.0 - y1
+ y4
;
173 m_saved_fx
= m_fx
= x1
;
174 m_saved_fy
= m_fy
= y1
;
176 m_saved_dfx
= m_dfx
= (x2
- x1
) * pre1
+ tmp1x
* pre2
+ tmp2x
* subdivide_step3
;
177 m_saved_dfy
= m_dfy
= (y2
- y1
) * pre1
+ tmp1y
* pre2
+ tmp2y
* subdivide_step3
;
179 m_saved_ddfx
= m_ddfx
= tmp1x
* pre4
+ tmp2x
* pre5
;
180 m_saved_ddfy
= m_ddfy
= tmp1y
* pre4
+ tmp2y
* pre5
;
182 m_dddfx
= tmp2x
* pre5
;
183 m_dddfy
= tmp2y
* pre5
;
185 m_step
= m_num_steps
;
191 //------------------------------------------------------------------------
192 void curve4::rewind(unsigned)
199 m_step
= m_num_steps
;
204 m_ddfx
= m_saved_ddfx
;
205 m_ddfy
= m_saved_ddfy
;
212 //------------------------------------------------------------------------
213 unsigned curve4::vertex(double* x
, double* y
)
215 if(m_step
< 0) return path_cmd_stop
;
216 if(m_step
== m_num_steps
)
221 return path_cmd_move_to
;
228 return path_cmd_line_to
;
239 return path_cmd_line_to
;