Use new arc drawing code from Jim Wilson that we are also using in

2.0.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2189 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet
2002-05-03 19:33:39 +00:00
parent 9cc064677c
commit c20f422141
+31 -31
View File
@@ -1,5 +1,5 @@
// //
// "$Id: fl_arc.cxx,v 1.4.2.3.2.4 2002/05/03 12:49:36 easysw Exp $" // "$Id: fl_arc.cxx,v 1.4.2.3.2.5 2002/05/03 19:33:39 easysw Exp $"
// //
// Arc functions for the Fast Light Tool Kit (FLTK). // Arc functions for the Fast Light Tool Kit (FLTK).
// //
@@ -33,38 +33,38 @@
void fl_arc(double x, double y, double r, double start, double end) { void fl_arc(double x, double y, double r, double start, double end) {
// draw start point accurately: // draw start point accurately:
double A = start*(M_PI/180);
double X = r*cos(A); double A = start*(M_PI/180); // Initial angle (radians)
double Y = -r*sin(A); double X = r*cos(A); // Initial displacement, (X,Y)
fl_vertex(x+X,y+Y); double Y = -r*sin(A); // from center to initial point
fl_vertex(x+X,y+Y); // Insert initial point
// number of segments per radian: // Maximum arc length to approximate with chord with error <= 0.125
int n; {
double x1 = fl_transform_dx(r,0); double epsilon; {
double y1 = fl_transform_dy(r,0); double r1 = hypot(fl_transform_dx(r,0), // Horizontal "radius"
double r1 = x1*x1+y1*y1; fl_transform_dy(r,0));
x1 = fl_transform_dx(0,r); double r2 = hypot(fl_transform_dx(0,r), // Vertical "radius"
y1 = fl_transform_dy(0,r); fl_transform_dy(0,r));
double r2 = x1*x1+y1*y1;
if (r2 < r1) r1 = r2; if (r2 < r1) r1 = r2; // r1 = minimum "radius"
n = int(sqrt(r1)*.841471); r2 = 1.0 - 0.125/r1; // r2 = cos(epsilon/2)
if (n < 2) n = 2; if (r2 < 0.5) r2 = 0.5; // minimum 3 chords/circle
if (n > 60) n = 60; epsilon = 2*acos(r2); // Maximum arc angle
} }
double epsilon = 1.0/n; A = end*(M_PI/180) - A; // Displacement angle (radians)
double E = end*(M_PI/180); int i = int(ceil(fabs(A)/epsilon)); // Segments in approximation
int i = int((E-A)*n);
if (i < 0) {i = -i; epsilon = -epsilon;} if (i) {
double epsilon2 = epsilon/2; epsilon = A/i; // Arc length for equal-size steps
for (; i>1; i--) { double cos_e = cos(epsilon);// Rotation coefficients
X += epsilon*Y; double sin_e = sin(epsilon);
Y -= epsilon2*X; do {
fl_vertex(x+X,y+Y); double Xnew = cos_e*X + sin_e*Y;
Y -= epsilon2*X; Y = -sin_e*X + cos_e*Y;
fl_vertex(x + (X=Xnew), y + Y);
} while (--i);
} }
// 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.cxx #if 0 // portable version. X-specific one in fl_vertex.cxx
@@ -74,5 +74,5 @@ void fl_circle(double x,double y,double r) {
#endif #endif
// //
// End of "$Id: fl_arc.cxx,v 1.4.2.3.2.4 2002/05/03 12:49:36 easysw Exp $". // End of "$Id: fl_arc.cxx,v 1.4.2.3.2.5 2002/05/03 19:33:39 easysw Exp $".
// //