diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 1998-10-06 18:21:25 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 1998-10-06 18:21:25 +0000 |
| commit | f9039b2ae21988783feae9b362818e7923e82d14 (patch) | |
| tree | 6d6fe3679d73448758f9794e7d4d4f6b22a4adad /src/fl_arc.cxx | |
| parent | 67e89232f9ba067825a158734a09e0fa21aacbe3 (diff) | |
Initial revision
git-svn-id: file:///fltk/svn/fltk/trunk@2 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/fl_arc.cxx')
| -rw-r--r-- | src/fl_arc.cxx | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/fl_arc.cxx b/src/fl_arc.cxx new file mode 100644 index 000000000..756c2a4bb --- /dev/null +++ b/src/fl_arc.cxx @@ -0,0 +1,50 @@ +// fl_arc.C + +// Utility for drawing arcs and circles. They are added to +// the current fl_begin/fl_vertex/fl_end path. +// Incremental math implementation: + +#include <FL/fl_draw.H> +#include <FL/math.h> + +void fl_arc(double x, double y, double r, double start, double end) { + + // draw start point accurately: + double A = start*(M_PI/180); + double X = r*cos(A); + double Y = -r*sin(A); + fl_vertex(x+X,y+Y); + + // number of segments per radian: + int n; { + double x1 = fl_transform_dx(r,0); + double y1 = fl_transform_dy(r,0); + double r1 = x1*x1+y1*y1; + x1 = fl_transform_dx(0,r); + y1 = fl_transform_dy(0,r); + double r2 = x1*x1+y1*y1; + if (r2 < r1) r1 = r2; + n = int(sqrt(r1)*.841471); + if (n < 2) n = 2; + } + double epsilon = 1.0/n; + double E = end*(M_PI/180); + int i = int((E-A)*n); + if (i < 0) {i = -i; epsilon = -epsilon;} + double epsilon2 = epsilon/2; + for (; i>1; i--) { + X += epsilon*Y; + Y -= epsilon2*X; + fl_vertex(x+X,y+Y); + Y -= epsilon2*X; + } + + // draw the end point accurately: + fl_vertex(x+r*cos(E), y-r*sin(E)); +} + +#if 0 // portable version. X-specific one in fl_vertex.C +void fl_circle(double x,double y,double r) { + _fl_arc(x, y, r, r, 0, 360); +} +#endif |
