⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.c

📁 [Game.Programming].Academic - Graphics Gems (6 books source code)
💻 C
字号:
/* TEST FILE FOR kc.multi.c, NOT FOR BOOK */#include <stdio.h>typedef struct {    double x, y;} Point2;int srandom(int seed);void MultiJitter(Point2 points[], int m, int n);main(int argc, char *argv[]) {    Point2 *points;    int m, n, i, x, y;    int **counts, *x_bins, *y_bins;    if (argc != 4) {	fprintf(stderr, "Usage: multi-jitter <m> <n> <seed>.\n");	exit(1);    }    m = atoi(argv[1]);    n = atoi(argv[2]);    srandom(atoi(argv[3]));    points = (Point2 *) malloc(m*n*sizeof(Point2));    counts = (int **) malloc(m*sizeof(int *));    for (i = 0; i < m; i++)	counts[i] = (int *) malloc(n*sizeof(int));    x_bins = (int *) malloc(m*n*sizeof(int));    y_bins = (int *) malloc(m*n*sizeof(int));    MultiJitter(points, m, n);    /*     * Test jittered condition     */    for (x = 0; x < m; x++) {	for (y = 0; y < n; y++) {	    counts[x][y] = 0;	}    }    for (i = 0; i < m*n; i++) {	x = points[i].x / (1.0/m);	y = points[i].y / (1.0/n);	counts[x][y]++;    }    for (x = 0; x < m; x++) {	for (y = 0; y < n; y++) {	    if (counts[x][y] != 1) {		fprintf(stderr, "Jittered condition not satisfied.\n");		goto done1;	    }	}    }    done1:;    /*     * Test n-rooks condition     */    for (x = 0; x < m*n; x++)	x_bins[x] = 0;    for (y = 0; y < m*n; y++)	y_bins[y] = 0;    for (i = 0; i < m*n; i++) {	x = points[i].x / (1.0/(m*n));	y = points[i].y / (1.0/(m*n));	x_bins[x]++;	y_bins[y]++;    }    for (x = 0; x < m*n; x++) {	if (x_bins[x] != 1) {	    fprintf(stderr, "n-rooks condition not satisfied in x.\n");	    goto done2;	}    }    done2:;    for (y = 0; y < m*n; y++) {	if (y_bins[y] != 1) {	    fprintf(stderr, "n-rooks condition not satisfied in y.\n");	    goto done3;	}    }    done3:;    for (i = 0; i < m*n; i++)	fprintf(stderr, "(%f, %f)\n", points[i].x, points[i].y);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -