liblashgame

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

anglespan.c (1514B)


      1 // test anglespan compare
      2 
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <time.h>
      6 #include "../lash_game_standard.h"
      7 
      8 int main(int argc, char *argv[]) {
      9 	
     10 	int test_count = 1000;
     11 	clock_t test_clock_total = 0.f;
     12 	
     13 	if (argc < 5) {
     14 		printf("Usage: %s old_rad_min old_rad_max new_rad_min new_rad_max\n\n", argv[0]);
     15 		return 1;
     16 	}
     17 	
     18 	float old_rad_min = atof(argv[1]);
     19 	float old_rad_max = atof(argv[2]);
     20 	float new_rad_min = atof(argv[3]);
     21 	float new_rad_max = atof(argv[4]);
     22 	
     23 	int i;
     24 	char *result_string;
     25 	
     26 	for (i = 0; i < test_count; i++) {
     27 		clock_t begin = clock();
     28 		enum lash_anglespan_compare result = lash_compareAngleSpan(old_rad_min, old_rad_max, new_rad_min, new_rad_max);
     29 		test_clock_total += clock() - begin;
     30 		
     31 		switch(result) {
     32 			case LASH_ANGLESPAN_NONE:
     33 				result_string = "No change";
     34 				break;
     35 			case LASH_ANGLESPAN_MAX:
     36 				result_string = "New max";
     37 				break;
     38 			case LASH_ANGLESPAN_MIN:
     39 				result_string = "New min";
     40 				break;
     41 			case LASH_ANGLESPAN_BOTH:
     42 				result_string = "New min and max";
     43 				break;
     44 			case LASH_ANGLESPAN_SPLIT:
     45 				result_string = "Split";
     46 				break;
     47 			default:
     48 				result_string = "(unknown result)";
     49 		}
     50 		
     51 	}
     52 	printf("Old: min %f / max %f\nNew: min %f / max %f\nAction: %s\n", old_rad_min, old_rad_max, new_rad_min, new_rad_max, result_string);
     53 	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);
     54 	return 0;
     55 }