Rev 1892 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1892 | Rev 3959 | ||
---|---|---|---|
Line 36... | Line 36... | ||
36 | 36 | ||
Line 37... | Line 37... | ||
37 | #include "cairoint.h" |
37 | #include "cairoint.h" |
Line -... | Line 38... | ||
- | 38 | ||
- | 39 | #include "cairo-arc-private.h" |
|
38 | 40 | ||
Line 39... | Line 41... | ||
39 | #include "cairo-arc-private.h" |
41 | #define MAX_FULL_CIRCLES 65536 |
Line 40... | Line 42... | ||
40 | 42 | ||
Line 129... | Line 131... | ||
129 | (R * cos(B) + h * sin(B), R * sin(B) - h * cos (B)) |
131 | (R * cos(B) + h * sin(B), R * sin(B) - h * cos (B)) |
130 | (R * cos(B), R * sin(B)) |
132 | (R * cos(B), R * sin(B)) |
Line 131... | Line 133... | ||
131 | 133 | ||
Line 132... | Line 134... | ||
132 | for some value of h. |
134 | for some value of h. |
133 | 135 | ||
134 | "Approximation of circular arcs by cubic poynomials", Michael |
136 | "Approximation of circular arcs by cubic polynomials", Michael |
Line 135... | Line 137... | ||
135 | Goldapp, Computer Aided Geometric Design 8 (1991) 227-238, provides |
137 | Goldapp, Computer Aided Geometric Design 8 (1991) 227-238, provides |
Line 136... | Line 138... | ||
136 | various values of h along with error analysis for each. |
138 | various values of h along with error analysis for each. |
Line 137... | Line 139... | ||
137 | 139 | ||
138 | From that paper, a very practical value of h is: |
140 | From that paper, a very practical value of h is: |
139 | 141 | ||
140 | h = 4/3 * tan(angle/4) |
142 | h = 4/3 * R * tan(angle/4) |
Line 182... | Line 184... | ||
182 | cairo_direction_t dir) |
184 | cairo_direction_t dir) |
183 | { |
185 | { |
184 | if (cairo_status (cr)) |
186 | if (cairo_status (cr)) |
185 | return; |
187 | return; |
Line -... | Line 188... | ||
- | 188 | ||
- | 189 | assert (angle_max >= angle_min); |
|
- | 190 | ||
186 | 191 | if (angle_max - angle_min > 2 * M_PI * MAX_FULL_CIRCLES) { |
|
187 | while (angle_max - angle_min > 4 * M_PI) |
192 | angle_max = fmod (angle_max - angle_min, 2 * M_PI); |
- | 193 | angle_min = fmod (angle_min, 2 * M_PI); |
|
- | 194 | angle_max += angle_min + 2 * M_PI * MAX_FULL_CIRCLES; |
|
Line 188... | Line 195... | ||
188 | angle_max -= 2 * M_PI; |
195 | } |
189 | 196 | ||
190 | /* Recurse if drawing arc larger than pi */ |
197 | /* Recurse if drawing arc larger than pi */ |
191 | if (angle_max - angle_min > M_PI) { |
198 | if (angle_max - angle_min > M_PI) { |
Line 208... | Line 215... | ||
208 | dir); |
215 | dir); |
209 | } |
216 | } |
210 | } else if (angle_max != angle_min) { |
217 | } else if (angle_max != angle_min) { |
211 | cairo_matrix_t ctm; |
218 | cairo_matrix_t ctm; |
212 | int i, segments; |
219 | int i, segments; |
213 | double angle, angle_step; |
220 | double step; |
Line 214... | Line 221... | ||
214 | 221 | ||
215 | cairo_get_matrix (cr, &ctm); |
222 | cairo_get_matrix (cr, &ctm); |
216 | segments = _arc_segments_needed (angle_max - angle_min, |
223 | segments = _arc_segments_needed (angle_max - angle_min, |
217 | radius, &ctm, |
224 | radius, &ctm, |
218 | cairo_get_tolerance (cr)); |
225 | cairo_get_tolerance (cr)); |
- | 226 | step = (angle_max - angle_min) / segments; |
|
Line 219... | Line 227... | ||
219 | angle_step = (angle_max - angle_min) / (double) segments; |
227 | segments -= 1; |
- | 228 | ||
- | 229 | if (dir == CAIRO_DIRECTION_REVERSE) { |
|
220 | 230 | double t; |
|
221 | if (dir == CAIRO_DIRECTION_FORWARD) { |
231 | |
222 | angle = angle_min; |
232 | t = angle_min; |
- | 233 | angle_min = angle_max; |
|
223 | } else { |
234 | angle_max = t; |
224 | angle = angle_max; |
235 | |
Line 225... | Line 236... | ||
225 | angle_step = - angle_step; |
236 | step = -step; |
226 | } |
237 | } |
227 | - | ||
228 | for (i = 0; i < segments; i++, angle += angle_step) { |
- | |
229 | _cairo_arc_segment (cr, xc, yc, |
238 | |
230 | radius, |
239 | for (i = 0; i < segments; i++, angle_min += step) { |
- | 240 | _cairo_arc_segment (cr, xc, yc, radius, |
|
- | 241 | angle_min, angle_min + step); |
|
- | 242 | } |
|
231 | angle, |
243 | |
232 | angle + angle_step); |
244 | _cairo_arc_segment (cr, xc, yc, radius, |
233 | } |
245 | angle_min, angle_max); |
234 | } else { |
246 | } else { |
235 | cairo_line_to (cr, |
247 | cairo_line_to (cr, |
236 | xc + radius * cos (angle_min), |
248 | xc + radius * cos (angle_min), |
Line 237... | Line 249... | ||
237 | yc + radius * sin (angle_min)); |
249 | yc + radius * sin (angle_min)); |
238 | } |
250 | } |
239 | } |
251 | } |
240 | 252 | ||
241 | /** |
253 | /** |
242 | * _cairo_arc_path |
254 | * _cairo_arc_path: |
243 | * @cr: a cairo context |
255 | * @cr: a cairo context |