liblashgame

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

circleline.c (1313B)


      1 // test circle line intersect
      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 i;
     11 	int warmup_count = 100;
     12 	int test_count = 10000;
     13 	int test_control_count = 0;
     14 	clock_t time_test_total = 0;
     15 	clock_t time_test_begin = 0;
     16 	
     17 	if (argc < 6) {
     18 		printf("Usage: %s circle_x circle_y circle_radius line_m line_c\n", argv[0]);
     19 		return 1;
     20 	}
     21 	
     22 	lash_game_coords_float_t c_c;
     23 	lash_game_line_t l;
     24 	float c_r;
     25 	lash_game_coords_float_t i1, i2;
     26 	char ic;
     27 	
     28 	c_c.x = atof(argv[1]);
     29 	c_c.y = atof(argv[2]);
     30 	c_r = atof(argv[3]);
     31 	l.m = atof(argv[4]);
     32 	l.c = atof(argv[5]);
     33 	
     34 	for (i = 0; i < warmup_count; i++)
     35 		ic = lash_collisionCheckCircleLine(c_c, c_r, l, &i1, &i2);
     36 	
     37 	for (i = 0; i < test_count; i++) {
     38 		time_test_begin = clock();
     39 		ic = lash_collisionCheckCircleLine(c_c, c_r, l, &i1, &i2);
     40 		time_test_total += clock() - time_test_begin;
     41 		test_control_count ++;
     42 	}
     43 	
     44 	printf("Intersection count: %d\n", ic);
     45 	if (ic > 0) {
     46 		printf("Intersection 1: x%f,y%f\n", i1.x, i1.y);
     47 		if (ic == 2) {
     48 			printf("Intersection 2: x%f,y%f\n", i2.x, i2.y);
     49 		}
     50 	}
     51 	
     52 	printf("Average execution time: %2.0f (%10.7f secs)\n", (float)(time_test_total / test_count), (time_test_total / (float)test_count) / (float)CLOCKS_PER_SEC);
     53 	
     54 	return 0;
     55 }