#define ATAN_TABLE_SIZE 4096
#define SQRT_TABLE_SIZE 4096
-static int *atan_table = NULL;
static int *sqrt_table = NULL;
static int setup_sqrt_table (void)
return (ret);
} /* int utils_sqrt2 */
-static int setup_atan_table (void)
-{
- int i;
- double z;
-
- atan_table = (int *) malloc (ATAN_TABLE_SIZE * sizeof (int));
- if (atan_table == NULL)
- return (-1);
-
- for (i = 0; i < (ATAN_TABLE_SIZE - 1); i++)
- {
- z = ((double) i) / ((double) (ATAN_TABLE_SIZE - 1));
- atan_table[i] = atan ( z / (1.0 - z ) ) * ATAN_TABLE_SIZE * 256;
- }
- atan_table[ATAN_TABLE_SIZE - 1] = M_PI_4 * ATAN_TABLE_SIZE * 256;
-
- return 0;
-} /* int setup_atan_table */
-
-int utils_atan2 (int y, int x)
-{
- if (atan_table == NULL)
- if (setup_atan_table () != 0)
- return (-1);
-
- // return atan2(y,x) * 256*ATAN_TABLE_SIZE;
- if( x > 0 )
- {
- if( y > 0 )
- {
- return atan_table[(int)( ATAN_TABLE_SIZE * y / ( x + y ))];
- }
- else
- {
- return -atan_table[ (int)(ATAN_TABLE_SIZE * (-y) / ( x - y ))];
- }
- }
-
- if( x == 0 )
- {
- if( y > 0 )
- return (int)(256*ATAN_TABLE_SIZE * M_PI_2);
- else
- return -(int)(256*ATAN_TABLE_SIZE * M_PI_2);
- }
-
- if( y < 0 )
- {
- return atan_table[(int)( ATAN_TABLE_SIZE * y / ( x + y ))] - (int)(M_PI*256*ATAN_TABLE_SIZE);
- }
- else
- {
- return -atan_table[ (int)(ATAN_TABLE_SIZE * (-y) / ( x - y ))] + (int)(M_PI*256*ATAN_TABLE_SIZE);
- }
-
-}
-
/*
* vim: set tabstop=8 softtabstop=2 shiftwidth=2 :
*/