int main(int argc, char *argv[]) { #ifndef HAVE_LIBTTF fprintf(stderr, "gd was not compiled with HAVE_LIBTTF defined.\n"); fprintf(stderr, "Install the FreeType library, including the\n"); fprintf(stderr, "header files. Then edit the gd Makefile, type\n"); fprintf(stderr, "make clean, and type make again.\n"); return 1; #else gdImagePtr im; int black; int white; int brect[8]; int x, y; char *err; #ifdef JISX0208 char *s = "Hello. こんにちは Qyjpqg,"; /* String to draw. */ #else char *s = "Hello. Qyjpqg,"; /* String to draw. */ #endif double sz = 40.; double angle = DEG2RAD(-90); #ifdef JISX0208 char *f = "/usr/openwin/lib/locale/ja/X11/fonts/TT/HG-MinchoL.ttf"; /* UNICODE */ /* char *f = "/usr/local/lib/fonts/truetype/DynaFont/dfpop1.ttf"; */ /* SJIS */ #else char *f = "/usr/local/lib/fonts/truetype/misc/times.ttf"; /* TrueType font */ #endif /* obtain brect so that we can size the image */ err = gdImageStringTTF((gdImagePtr)NULL,&brect[0],0,f,sz,angle,0,0,s); if (err) {fprintf(stderr,err); return 1;} /* create an image just big enough for the string */ x = MAXX(brect) - MINX(brect) + 6; y = MAXY(brect) - MINY(brect) + 6; im = gdImageCreate(x,y); /* Background color (first allocated) */ white = gdImageColorResolve(im, 255, 255, 255); black = gdImageColorResolve(im, 0, 0, 0); /* render the string, offset origin to center string*/ x = 0 - MINX(brect) + 3; y = 0 - MINY(brect) + 3; err = gdImageStringTTF(im,&brect[0],black,f,sz,angle,x,y,s); if (err) {fprintf(stderr,err); return 1;} /* Write img to stdout */ gdImagePng(im, stdout); /* Destroy it */ gdImageDestroy(im); return 0; #endif /* HAVE_TTF */ }
bool KDTree::rayintersectsbox(FSBoundingBox *box) { double pmin, pmax, tmin, tmax; double dtemp; // Get the parametric distance along each direction from the min point to // the min and max box planes. If the min dist is grater than the max // dist, we have to swap them. Keep a running total of the max min and the // min max. The ray intersects the box iff tmin <= tmax and tmax >= 0.0. // Otherwise, the ray misses the box or points away from the box (with the // starting point outside). tmin = (box->xmin - rayxstart)/dx; tmax = (box->xmax - rayxstart)/dx; if ( tmin > tmax ) { dtemp = tmin; tmin = tmax; tmax = dtemp; } pmin = (box->ymin - rayystart)/dy; pmax = (box->ymax - rayystart)/dy; if ( pmin > pmax ) { dtemp = pmin; pmin = pmax; pmax = dtemp; } tmin = MAXX(pmin,tmin); tmax = MINN(pmax,tmax); if ( tmin > tmax ) return false; pmin = (box->zmin - rayzstart)/dz; pmax = (box->zmax - rayzstart)/dz; if ( pmin > pmax ) { dtemp = pmin; pmin = pmax; pmax = dtemp; } tmin = MAXX(pmin,tmin); tmax = MINN(pmax,tmax); if ( (tmax < 0.0) || (tmin > tmax) ) return false; return true; }
int InsidePolygon(GLfloat x, GLfloat y, int N, GLfloat* polygon) { int counter = 0; int i; GLfloat xinters; //Point p1,p2; GLfloat x1, y1, x2, y2; x1 = polygon[0]; y1 = polygon[1]; for (i=1;i<=N;i++) { x2 = polygon[2*(i % N)]; y2 = polygon[2*(i % N)+1]; if (y > MINN(y1,y2)) { if (y <= MAXX(y1,y2)) { if (x <= MAXX(x1,x2)) { if ( fabs(y1 - y2) > 1e-8 ) { xinters = (y-y1)*(x2-x1)/(y2-y1)+x1; if ( fabs(x1 - x2)<1e-8 || x <= xinters) counter++; } } } } x1 = x2; y1 = y2; } return (counter %2 != 0); /* if (counter % 2 == 0) return(OUTSIDE); else return(INSIDE);*/ }
/* * FTP LOGIN function. Issues a "USER <username> and then "PASS <password>" * to login to the remote host and checks that command succeeded. */ int ftp_login(int sock, char *username, char *password) { char *recvbuf; char *sendbuf; char *header; header = read_sock(sock); printf("\tserver runs:\t%s", header); free(header); sendbuf = Malloc((MAXX(strlen(username), strlen(password)) + 7) * sizeof(char)); sprintf(sendbuf, "USER %s\n", username); write_sock(sock, sendbuf); recvbuf = read_sock(sock); if(atoi(recvbuf) != 331) { free(recvbuf); return 0; } sprintf(sendbuf, "PASS %s\n", password); write_sock(sock, sendbuf); recvbuf = read_sock(sock); if(atoi(recvbuf) != 230) { free(recvbuf); return 0; } free(sendbuf); return 1; }
int main (int argc, char *argv[]) { gdImagePtr im; int blue; int blueAlpha; int white; int brect[8]; int x, y, sx, sy; char *err; FILE *out; #ifdef JISX0208 char *s = "Hello. ‚±‚ñ‚É‚¿‚Í Qyjpqg,"; /* String to draw. */ #else char *s = "Hello. ã�“ã‚“ã�«ã�¡ã�¯ Qyjpqg,"; /* String to draw. */ #endif double sz = 40.; #if 0 double angle = 0.; #else double angle = DEG2RAD (90); #endif char *f; if (argc == 2) { f = argv[1]; } else { /* 2.02: usage message. Defaulting to Times wasn't working well for the many people with no /usr/share/fonts/truetype. */ fprintf(stderr, "Usage: gdtestft fontfilename\n" "If fontfilename is not a full or relative path, GDFONTPATH is searched for\n" "it. If GDFONTPATH is not set, /usr/share/fonts/truetype is searched.\n"); return 1; } /* obtain brect so that we can size the image */ err = gdImageStringFT ((gdImagePtr) NULL, &brect[0], 0, f, sz, angle, 0, 0, s); if (err) { fprintf(stderr, "%s\n", err); return 1; } /* create an image just big enough for the string (x3) */ sx = MAXX (brect) - MINX (brect) + 6; sy = MAXY (brect) - MINY (brect) + 6; #if 0 /* Would be palette color 8-bit (which of course is still allowed, but not impressive when used with a JPEG background and antialiasing and alpha channel and so on!) */ im = gdImageCreate (sx * 3, sy); #else /* gd 2.0: true color images can use freetype too, and they can do antialiasing against arbitrary complex backgrounds. */ im = gdImageCreateTrueColor (sx * 3, sy); #endif /* Background color. gd 2.0: fill the image with it; truecolor images have a black background otherwise. */ white = gdImageColorResolve (im, 255, 255, 255); /* Load a pretty background and resample it to cover the entire image */ { FILE *in = fopen ("eleanor.jpg", "rb"); gdImagePtr imb = NULL; if (in) { #ifdef HAVE_LIBJPEG imb = gdImageCreateFromJpeg (in); #else fprintf(stderr, "No JPEG library support.\n"); #endif fclose(in); if (!imb) { fprintf(stderr, "gdImageCreateFromJpeg failed\n"); return 1; } if (!im->trueColor) { /* If destination is not truecolor, convert the JPEG to a reasonably high-quality palette version. This is not as good as creating a truecolor output file, of course. Leave many colors for text smoothing. */ #if 1 gdImageTrueColorToPalette (imb, 0, 128); #endif } /* Resample background image to cover new image exactly */ gdImageCopyResampled (im, imb, 0, 0, 0, 0, sx * 3, sy, gdImageSX (imb), gdImageSY (imb)); } else { /* Can't get background, so paint a simple one */ /* Truecolor images start out black, so paint it white */ gdImageFilledRectangle (im, 0, 0, sx * 3, sy, white); } } /* TBB 2.0.2: only black was working, and I didn't know it because the test program used black. Funny, huh? Let's do a more interesting color this time. */ blue = gdImageColorResolve (im, 128, 192, 255); /* Almost-transparent blue (alpha blending), with antialiasing */ blueAlpha = gdImageColorResolveAlpha (im, 128, 192, 255, gdAlphaMax / 2); /* render the string, offset origin to center string */ x = 0 - MINX (brect) + 3; y = 0 - MINY (brect) + 3; /* With antialiasing (positive color value) */ err = gdImageStringFT (im, NULL, blue, f, sz, angle, x, y, s); if (err) { fprintf(stderr, "%s\n", err); return 1; } /* Without antialiasing (negative color value) */ err = gdImageStringFT (im, NULL, -blue, f, sz, angle, sx + x, y, s); if (err) { fprintf(stderr, "%s\n", err); return 1; } /* With antialiasing, and 50% alpha blending (truecolor only) */ err = gdImageStringFT (im, NULL, blueAlpha, f, sz, angle, sx * 2 + x, y, s); if (err) { fprintf(stderr, "%s\n", err); return 1; } /* TBB: Write img to test/fttest.jpg or test/fttest.png */ if (im->trueColor) { #ifdef HAVE_LIBJPEG out = fopen ("test/fttest.jpg", "wb"); if (!out) { fprintf(stderr, "Can't create test/fttest.jpg\n"); exit (1); } /* Fairly high JPEG quality setting */ gdImageJpeg (im, out, 90); fclose (out); fprintf(stderr, "Test image written to test/fttest.jpg\n"); #else fprintf(stderr, "Test image not written; No JPEG library support.\n"); #endif } else { #ifdef HAVE_LIBPNG out = fopen ("test/fttest.png", "wb"); if (!out) { fprintf(stderr, "Can't create test/fttest.png\n"); exit (1); } /* 2.0.10: correct ifdef, thanks to Gabriele Verzeletti */ gdImagePng (im, out); fclose (out); fprintf(stderr, "Test image written to test/fttest.png\n"); #else fprintf(stderr, "Test image not written; No PNG library support.\n"); #endif } /* Destroy it */ gdImageDestroy (im); return 0; }