1 /***************************************************************************
4 * Copyright (C) 2011 Ryan Bourgeois <bluedragonx@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 **************************************************************************/
22 /* Some bastardized trig functions. These calculations flip the
23 * Y axis since that axis on touchpads is opposite that of the
36 /* Determine the direction of a vector. This uses the slope of the
37 * vector to approximate the angle, as such it is only accurate at
38 * increments of 45 degrees. This is sufficient for our uses.
40 * The returned value is 0 <= a < 8 such that the circle is split
41 * into 45 degree sections. Each whole number lies 45 degrees apart
42 * and so whole numbers are exact. All fractional parts are
45 * TR_NONE will be returned if the magnitude of the vector is zero.
47 double trig_direction(double dx, double dy);
49 /* Generalize a direction. Returns TR_NONE, TR_DIR_UP, TR_DIR_RT,
50 * TR_DIR_DN, or TR_DIR_LT.
52 int trig_generalize(double dir);
56 double trig_angles_add(double a1, double a2);
58 /* Subtract two angles.
60 double trig_angles_sub(double a1, double a2);
62 /* Calculate the acute angle between two angles.
64 double trig_angles_acute(double a1, double a2);
66 /* Average a collection of angles.
68 double trig_angles_avg(double* angles, int len);
70 /* Compare two angles. Returns 0 if a1 == a2. Returns < 0 if a1 < a2.
71 * Returns > 0 if a1 > a2.
73 int trig_angles_cmp(double a1, double a2);