do_complex.c revision 264fa531
1/* $Xorg: do_complex.c,v 1.3 2000/08/17 19:54:09 cpqbld Exp $ */ 2/***************************************************************************** 3Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. 4 5 All Rights Reserved 6 7Permission to use, copy, modify, and distribute this software and its 8documentation for any purpose and without fee is hereby granted, 9provided that the above copyright notice appear in all copies and that 10both that copyright notice and this permission notice appear in 11supporting documentation, and that the name of Digital not be 12used in advertising or publicity pertaining to distribution of the 13software without specific, written prior permission. 14 15DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 16ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 17DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 18ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 19WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 20ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 21SOFTWARE. 22 23******************************************************************************/ 24/* $XFree86: xc/programs/x11perf/do_complex.c,v 1.8 2001/07/25 15:05:16 dawes Exp $ */ 25 26#include "x11perf.h" 27 28#define NUM_POINTS 4 /* 4 points to an arrowhead */ 29#define NUM_ANGLES 3 /* But mostly it looks like a triangle */ 30static XPoint *points; 31static GC pgc; 32 33#include <math.h> 34#if defined(QNX4) || defined(__CYGWIN__) || defined(__UNIXOS2__) 35#define PI 3.14159265358979323846 36#else 37#define PI M_PI 38#endif /* QNX4 */ 39 40int 41InitComplexPoly(XParms xp, Parms p, int reps) 42{ 43 int i, j, numPoints; 44 int x, y; 45 int size, iradius; 46 double phi, phiinc, radius, delta, phi2; 47 XPoint *curPoint; 48 49 pgc = xp->fggc; 50 51 size = p->special; 52 phi = 0.0; 53 delta = 2.0 * PI / ((double) NUM_ANGLES); 54 if (xp->version == VERSION1_2) { 55 radius = ((double) size) * sqrt(3.0)/2.0; 56 phiinc = delta/10.0; 57 } else { 58 /* Version 1.2's radius computation was completely bogus, and resulted 59 in triangles with sides about 50% longer than advertised. Since 60 in version 1.3 triangles are scaled to cover size^2 pixels, we do 61 the same computation here. The arrowheads are a little larger than 62 simple triangles, because they lose 1/3 of their area due to the 63 notch cut out from them, so radius has to be sqrt(3/2) larger than 64 for simple triangles. 65 */ 66 radius = ((double) size) * sqrt(sqrt(4.0/3.0)); 67 phiinc = 1.75*PI / ((double) p->objects); 68 } 69 iradius = (int) radius + 1; 70 71 numPoints = (p->objects) * NUM_POINTS; 72 points = (XPoint *)malloc(numPoints * sizeof(XPoint)); 73 curPoint = points; 74 x = iradius; 75 y = iradius; 76 for (i = 0; i != p->objects; i++) { 77 for (j = 0; j != NUM_ANGLES; j++) { 78 phi2 = phi + ((double) j) * delta; 79 curPoint->x = (int) ((double)x + (radius * cos(phi2)) + 0.5); 80 curPoint->y = (int) ((double)y + (radius * sin(phi2)) + 0.5); 81 curPoint++; 82 } 83 curPoint->x = x; 84 curPoint->y = y; 85 curPoint++; 86 87 phi += phiinc; 88 y += 2 * iradius; 89 if (y + iradius >= HEIGHT) { 90 y = iradius; 91 x += 2 * iradius; 92 if (x + iradius >= WIDTH) { 93 x = iradius; 94 } 95 } 96 } 97 return reps; 98} 99 100void 101DoComplexPoly(XParms xp, Parms p, int reps) 102{ 103 int i, j; 104 XPoint *curPoint; 105 106 for (i = 0; i != reps; i++) { 107 curPoint = points; 108 for (j = 0; j != p->objects; j++) { 109 XFillPolygon(xp->d, xp->w, pgc, curPoint, NUM_POINTS, Complex, 110 CoordModeOrigin); 111 curPoint += NUM_POINTS; 112 } 113 if (pgc == xp->bggc) 114 pgc = xp->fggc; 115 else 116 pgc = xp->bggc; 117 CheckAbort (); 118 } 119} 120 121void 122EndComplexPoly(XParms xp, Parms p) 123{ 124 free(points); 125} 126 127int 128InitGeneralPoly(XParms xp, Parms p, int reps) 129{ 130 int i, j, numPoints; 131 int nsides; 132 int x, y; 133 int size, iradius; 134 double phi, phiinc, inner_radius, outer_radius, delta, phi2; 135 XPoint *curPoint; 136 137 pgc = xp->fggc; 138 size = p->special; 139 nsides = (long) p->font; 140 phi = 0.0; 141 delta = 2.0 * PI / ((double) nsides); 142 phiinc = delta / 10.0; 143 144 inner_radius = size / sqrt (nsides * tan (PI / nsides)); 145 outer_radius = inner_radius / cos (PI / (2 * nsides)); 146 numPoints = p->objects * nsides; 147 points = (XPoint *) malloc (numPoints * sizeof (XPoint)); 148 curPoint = points; 149 iradius = outer_radius + 1; 150 x = iradius; 151 y = iradius; 152 for (i = 0; i < p->objects; i++) { 153 phi2 = phi; 154 for (j = 0; j < nsides; j++) { 155 curPoint->x = x + (outer_radius * cos(phi2) + 0.5); 156 curPoint->y = y + (outer_radius * sin(phi2) + 0.5); 157 curPoint++; 158 phi2 += delta; 159 } 160 phi += phiinc; 161 y += 2 * iradius; 162 if (y + iradius >= HEIGHT) { 163 y = iradius; 164 x += 2 * iradius; 165 if (x + iradius >= WIDTH) { 166 x = iradius; 167 } 168 } 169 } 170 return reps; 171} 172 173void 174DoGeneralPoly(XParms xp, Parms p, int reps) 175{ 176 int i, j; 177 int nsides; 178 int mode; 179 XPoint *curPoint; 180 181 nsides = (long) p->font; 182 mode = (long) p->bfont; 183 for (i = 0; i != reps; i++) { 184 curPoint = points; 185 for (j = 0; j != p->objects; j++) { 186 XFillPolygon(xp->d, xp->w, pgc, curPoint, nsides, mode, 187 CoordModeOrigin); 188 curPoint += nsides; 189 } 190 if (pgc == xp->bggc) 191 pgc = xp->fggc; 192 else 193 pgc = xp->bggc; 194 CheckAbort (); 195 } 196} 197