diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 2002-05-07 00:17:07 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 2002-05-07 00:17:07 +0000 |
| commit | d37c6483ab6efe4109da327993ac918df6aae759 (patch) | |
| tree | 3ae74385329a5fb76117958bcde73ec301b6f7c0 /src/fl_arc.cxx | |
| parent | c2aa513a5a76620abefee63d328a541a472bdf51 (diff) | |
Get rid of a potential divide-by-zero in new arc code.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2200 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/fl_arc.cxx')
| -rw-r--r-- | src/fl_arc.cxx | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/fl_arc.cxx b/src/fl_arc.cxx index a4895f68e..7f381cd69 100644 --- a/src/fl_arc.cxx +++ b/src/fl_arc.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_arc.cxx,v 1.4.2.3.2.5 2002/05/03 19:33:39 easysw Exp $" +// "$Id: fl_arc.cxx,v 1.4.2.3.2.6 2002/05/07 00:17:07 easysw Exp $" // // Arc functions for the Fast Light Tool Kit (FLTK). // @@ -34,10 +34,10 @@ void fl_arc(double x, double y, double r, double start, double end) { // draw start point accurately: - double A = start*(M_PI/180); // Initial angle (radians) - double X = r*cos(A); // Initial displacement, (X,Y) - double Y = -r*sin(A); // from center to initial point - fl_vertex(x+X,y+Y); // Insert initial point + double A = start*(M_PI/180); // Initial angle (radians) + double X = r*cos(A); // Initial displacement, (X,Y) + double Y = -r*sin(A); // from center to initial point + fl_vertex(x+X,y+Y); // Insert initial point // Maximum arc length to approximate with chord with error <= 0.125 @@ -47,17 +47,17 @@ void fl_arc(double x, double y, double r, double start, double end) { double r2 = hypot(fl_transform_dx(0,r), // Vertical "radius" fl_transform_dy(0,r)); - if (r2 < r1) r1 = r2; // r1 = minimum "radius" - r2 = 1.0 - 0.125/r1; // r2 = cos(epsilon/2) - if (r2 < 0.5) r2 = 0.5; // minimum 3 chords/circle - epsilon = 2*acos(r2); // Maximum arc angle + if (r1 > r2) r1 = r2; // r1 = minimum "radius" + if (r1 < 2.) r1 = 2.; // radius for circa 9 chords/circle + + epsilon = 2*acos(1.0 - 0.125/r1); // Maximum arc angle } A = end*(M_PI/180) - A; // Displacement angle (radians) int i = int(ceil(fabs(A)/epsilon)); // Segments in approximation if (i) { - epsilon = A/i; // Arc length for equal-size steps - double cos_e = cos(epsilon);// Rotation coefficients + epsilon = A/i; // Arc length for equal-size steps + double cos_e = cos(epsilon); // Rotation coefficients double sin_e = sin(epsilon); do { double Xnew = cos_e*X + sin_e*Y; @@ -74,5 +74,5 @@ void fl_circle(double x,double y,double r) { #endif // -// End of "$Id: fl_arc.cxx,v 1.4.2.3.2.5 2002/05/03 19:33:39 easysw Exp $". +// End of "$Id: fl_arc.cxx,v 1.4.2.3.2.6 2002/05/07 00:17:07 easysw Exp $". // |
