|
38 | 38 | #endif |
39 | 39 | #endif |
40 | 40 |
|
| 41 | +#define M_PI 3.14159265358979323846 |
| 42 | +#define M_PI_4 0.785398163397448309616 |
| 43 | +#define M_PI_2 1.57079632679489661923 |
| 44 | + |
41 | 45 | /* ------------ RendererAgg methods ------------- */ |
42 | 46 |
|
43 | 47 |
|
@@ -377,23 +381,38 @@ RendererAgg::draw_ellipse(const Py::Tuple& args) { |
377 | 381 | GCAgg gc = GCAgg(args[0], dpi); |
378 | 382 | facepair_t face = _get_rgba_face(args[1], gc.alpha); |
379 | 383 |
|
380 | | - |
381 | 384 | double x = Py::Float( args[2] ); |
382 | 385 | double y = Py::Float( args[3] ); |
383 | 386 | double w = Py::Float( args[4] ); |
384 | 387 | double h = Py::Float( args[5] ); |
385 | 388 | double rot = Py::Float( args[6] ); |
| 389 | + |
| 390 | + double r; // rot in radians |
386 | 391 |
|
387 | 392 | set_clipbox_rasterizer(gc.cliprect); |
388 | 393 |
|
389 | 394 | // Approximate the ellipse with 4 bezier paths |
390 | 395 | agg::path_storage path; |
391 | | - path.move_to(x, height-(y+h)); |
392 | | - path.arc_to(w, h, 0.0, false, true, x+w, height-y); |
393 | | - path.arc_to(w, h, 0.0, false, true, x, height-(y-h)); |
394 | | - path.arc_to(w, h, 0.0, false, true, x-w, height-y); |
395 | | - path.arc_to(w, h, 0.0, false, true, x, height-(y+h)); |
396 | | - path.close_polygon(); |
| 396 | + if (rot == 0.0) // simple case |
| 397 | + { |
| 398 | + path.move_to(x, height-(y+h)); |
| 399 | + path.arc_to(w, h, 0.0, false, true, x+w, height-y); |
| 400 | + path.arc_to(w, h, 0.0, false, true, x, height-(y-h)); |
| 401 | + path.arc_to(w, h, 0.0, false, true, x-w, height-y); |
| 402 | + path.arc_to(w, h, 0.0, false, true, x, height-(y+h)); |
| 403 | + path.close_polygon(); |
| 404 | + } |
| 405 | + else // rotate by hand :( |
| 406 | + { |
| 407 | + // deg to rad |
| 408 | + r = rot * (M_PI/180.0); |
| 409 | + path.move_to( x+(cos(r)*w), height-(y+(sin(r)*w))); |
| 410 | + path.arc_to(w, h, -r, false, true, x+(cos(r+M_PI_2*3)*h), height-(y+(sin(r+M_PI_2*3)*h))); |
| 411 | + path.arc_to(w, h, -r, false, true, x+(cos(r+M_PI)*w), height-(y+(sin(r+M_PI)*w))); |
| 412 | + path.arc_to(w, h, -r, false, true, x+(cos(r+M_PI_2)*h), height-(y+(sin(r+M_PI_2)*h))); |
| 413 | + path.arc_to(w, h, -r, false, true, x+(cos(r)*w), height-(y+(sin(r)*w))); |
| 414 | + path.close_polygon(); |
| 415 | + } |
397 | 416 |
|
398 | 417 | _fill_and_stroke(path, gc, face); |
399 | 418 | return Py::Object(); |
|
0 commit comments