liblashgame

Pathfinder and path decision making library for 2D tile game
git clone git://holbrook.no/liblashgame.git
Log | Files | Refs

containedangle.c (2059B)


      1 // test contained angle
      2 
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <stdint.h>
      6 #include <time.h>
      7 #include <math.h>
      8 #include "../lash_game_standard.h"
      9 
     10 int main(int argc, char *argv[]) {
     11 	
     12 	int test_count = 1000;
     13 	clock_t test_clock_total = 0.f;
     14 	
     15 	if (argc < 10) {
     16 		printf("Usage: %s x y magnitude world_width world_height buffer_top buffer_right buffer_bottom buffer_left\n\n", argv[0]);
     17 		return 1;
     18 	}
     19 	//int x = atoi(argv[1]);
     20 	//int y = atoi(argv[2]);
     21 	double x = atof(argv[1]);
     22 	double y = atof(argv[2]);
     23 	double m = atof(argv[3]);
     24 	//int w_container = atoi(argv[4]);
     25 	//int h_container = atoi(argv[5]);
     26 	double w_container = atoi(argv[4]);
     27 	double h_container = atoi(argv[5]);
     28 	int buf_top = atoi(argv[6]);
     29 	int buf_right = atoi(argv[7]);
     30 	int buf_bottom = atoi(argv[8]);
     31 	int buf_left = atoi(argv[9]);
     32 	
     33 	double angle_min = -1.f;
     34 	double angle_max = -1.f;
     35 	//int x_min = -1;
     36 	//int y_min = -1;
     37 	//int x_max = -1;
     38 	//int y_max = -1;
     39 	double x_min = -1.f;
     40 	double y_min = -1.f;
     41 	double x_max = -1.f;
     42 	double y_max = -1.f;
     43 	
     44 	int i;
     45 	
     46 	for (i = 0; i < test_count; i++) {
     47 		clock_t begin = clock();
     48 		lash_getContainedAngle(x, y, m, w_container, h_container, buf_top, buf_right, buf_bottom, buf_left, &angle_min, &angle_max, 1, &x_min, &y_min, &x_max, &y_max);
     49 		clock_t end = clock();
     50 		test_clock_total += end - begin;
     51 	}
     52 	//printf("World size: %d,%d\nPosition: %d,%d\nBuffers: %d,%d,%d,%d\nAngle min: %f (edge at %d,%d)\nAngle max: %.2f (edge at %d,%d)\n", w_container, h_container, x, y, buf_top, buf_right, buf_bottom, buf_left, angle_min, x_min, y_min, angle_max, x_max, y_max);
     53 	printf("World size: %f,%f\nPosition: %f,%f\nBuffers: %d,%d,%d,%d\nAngle min: %f (edge at %f,%f)\nAngle max: %.2f (edge at %f,%f)\n", w_container, h_container, x, y, buf_top, buf_right, buf_bottom, buf_left, angle_min, x_min, y_min, angle_max, x_max, y_max);
     54 	printf("Avg execution time (from %d): %lu ticks @ %li pr sec = %.7f secs\n\n", test_count, (long)test_clock_total, CLOCKS_PER_SEC, ((double)test_clock_total / CLOCKS_PER_SEC) / test_count);
     55 	
     56 	return 0;
     57 }