#include "x11perf.h"
#define NUM_POINTS 4
#define NUM_ANGLES 3
static XPoint *points;
static GC pgc;
#include <math.h>
#if defined(QNX4) || defined(__CYGWIN__) || defined(__UNIXOS2__)
#define PI 3.14159265358979323846
#else
#define PI M_PI
#endif
int
InitComplexPoly(XParms xp, Parms p, int reps)
{
int i, j, numPoints;
int x, y;
int size, iradius;
double phi, phiinc, radius, delta, phi2;
XPoint *curPoint;
pgc = xp->fggc;
size = p->special;
phi = 0.0;
delta = 2.0 * PI / ((double) NUM_ANGLES);
if (xp->version == VERSION1_2) {
radius = ((double) size) * sqrt(3.0)/2.0;
phiinc = delta/10.0;
} else {
radius = ((double) size) * sqrt(sqrt(4.0/3.0));
phiinc = 1.75*PI / ((double) p->objects);
}
iradius = (int) radius + 1;
numPoints = (p->objects) * NUM_POINTS;
points = (XPoint *)malloc(numPoints * sizeof(XPoint));
curPoint = points;
x = iradius;
y = iradius;
for (i = 0; i != p->objects; i++) {
for (j = 0; j != NUM_ANGLES; j++) {
phi2 = phi + ((double) j) * delta;
curPoint->x = (int) ((double)x + (radius * cos(phi2)) + 0.5);
curPoint->y = (int) ((double)y + (radius * sin(phi2)) + 0.5);
curPoint++;
}
curPoint->x = x;
curPoint->y = y;
curPoint++;
phi += phiinc;
y += 2 * iradius;
if (y + iradius >= HEIGHT) {
y = iradius;
x += 2 * iradius;
if (x + iradius >= WIDTH) {
x = iradius;
}
}
}
return reps;
}
void
DoComplexPoly(XParms xp, Parms p, int reps)
{
int i, j;
XPoint *curPoint;
for (i = 0; i != reps; i++) {
curPoint = points;
for (j = 0; j != p->objects; j++) {
XFillPolygon(xp->d, xp->w, pgc, curPoint, NUM_POINTS, Complex,
CoordModeOrigin);
curPoint += NUM_POINTS;
}
if (pgc == xp->bggc)
pgc = xp->fggc;
else
pgc = xp->bggc;
CheckAbort ();
}
}
void
EndComplexPoly(XParms xp, Parms p)
{
free(points);
}
int
InitGeneralPoly(XParms xp, Parms p, int reps)
{
int i, j, numPoints;
int nsides;
int x, y;
int size, iradius;
double phi, phiinc, inner_radius, outer_radius, delta, phi2;
XPoint *curPoint;
pgc = xp->fggc;
size = p->special;
nsides = (long) p->font;
phi = 0.0;
delta = 2.0 * PI / ((double) nsides);
phiinc = delta / 10.0;
inner_radius = size / sqrt (nsides * tan (PI / nsides));
outer_radius = inner_radius / cos (PI / (2 * nsides));
numPoints = p->objects * nsides;
points = (XPoint *) malloc (numPoints * sizeof (XPoint));
curPoint = points;
iradius = outer_radius + 1;
x = iradius;
y = iradius;
for (i = 0; i < p->objects; i++) {
phi2 = phi;
for (j = 0; j < nsides; j++) {
curPoint->x = x + (outer_radius * cos(phi2) + 0.5);
curPoint->y = y + (outer_radius * sin(phi2) + 0.5);
curPoint++;
phi2 += delta;
}
phi += phiinc;
y += 2 * iradius;
if (y + iradius >= HEIGHT) {
y = iradius;
x += 2 * iradius;
if (x + iradius >= WIDTH) {
x = iradius;
}
}
}
return reps;
}
void
DoGeneralPoly(XParms xp, Parms p, int reps)
{
int i, j;
int nsides;
int mode;
XPoint *curPoint;
nsides = (long) p->font;
mode = (long) p->bfont;
for (i = 0; i != reps; i++) {
curPoint = points;
for (j = 0; j != p->objects; j++) {
XFillPolygon(xp->d, xp->w, pgc, curPoint, nsides, mode,
CoordModeOrigin);
curPoint += nsides;
}
if (pgc == xp->bggc)
pgc = xp->fggc;
else
pgc = xp->bggc;
CheckAbort ();
}
}