|
[Plplot-cvs] SF.net SVN: plplot:[11192] trunk/src/plarc.c
From: <hezekiahcarty@us...> - 2010-09-18 19:14
|
Revision: 11192
http://plplot.svn.sourceforge.net/plplot/?rev=11192&view=rev
Author: hezekiahcarty
Date: 2010-09-18 19:14:46 +0000 (Sat, 18 Sep 2010)
Log Message:
-----------
For Steve Schwartz: Apply plarc_approx bugfix
>From Steve's email:
1 When you filled an arc, you did so by OVERWRITING the last point in
the set of arc segments by the origin, so the filled arc stops short of
the last theta.
2 While you check to ensure that there are at least 2 segments so you
can fill the polygon, again since you overwrite the last point you only
end up with a polygon with 2 points which plfill can't fill.
3 When you calculate the number of segments, you don't allow for an arc
drawn backward, and so end up with a negative number of segments, which
then turns into 2 which is still not enough (see (2)).
Modified Paths:
--------------
trunk/src/plarc.c
Modified: trunk/src/plarc.c
===================================================================
--- trunk/src/plarc.c 2010-09-18 18:43:57 UTC (rev 11191)
+++ trunk/src/plarc.c 2010-09-18 19:14:46 UTC (rev 11192)
@@ -21,7 +21,7 @@
#include "plplotP.h"
-#define CIRCLE_SEGMENTS PL_MAXPOLY
+#define CIRCLE_SEGMENTS ( PL_MAXPOLY - 1 )
#define DEG_TO_RAD( x ) ( ( x ) * M_PI / 180.0 )
#define PLARC_POINT_X( x, a, b, theta ) ( ( x ) + ( ( a ) * cos( theta ) ) )
@@ -39,7 +39,7 @@
PLINT i;
PLFLT theta0, theta_step, theta, d_angle;
PLINT segments;
- PLFLT xs[CIRCLE_SEGMENTS], ys[CIRCLE_SEGMENTS];
+ PLFLT xs[CIRCLE_SEGMENTS + 1], ys[CIRCLE_SEGMENTS + 1];
/* The difference between the start and end angles */
d_angle = DEG_TO_RAD( angle2 - angle1 );
@@ -47,7 +47,7 @@
d_angle = M_PI * 2.0;
/* The number of line segments used to approximate the arc */
- segments = d_angle / ( 2.0 * M_PI ) * CIRCLE_SEGMENTS;
+ segments = fabs( d_angle ) / ( 2.0 * M_PI ) * CIRCLE_SEGMENTS;
/* Always use at least 2 arc points, otherwise fills will break. */
if ( segments < 2 )
segments = 2;
@@ -70,8 +70,9 @@
/* Add the center point if we aren't drawing a circle */
if ( fabs( d_angle ) < M_PI * 2.0 )
{
- xs[segments - 1] = x;
- ys[segments - 1] = y;
+ xs[segments] = x;
+ ys[segments] = y;
+ segments++;
}
/* Draw a filled arc */
plfill( segments, xs, ys );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
| Thread | Author | Date |
|---|---|---|
| [Plplot-cvs] SF.net SVN: plplot:[11192] trunk/src/plarc.c | <hezekiahcarty@us...> |