chiark / gitweb /
xf86-input-mtrack (0.3.1-1) unstable; urgency=medium
[xf86-input-mtrack.git] / include / trig.h
1 /***************************************************************************
2  *
3  * Multitouch X driver
4  * Copyright (C) 2011 Ryan Bourgeois <bluedragonx@gmail.com>
5  *
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.
10  *
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.
15  *
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
19  *
20  **************************************************************************/
21
22 /* Some bastardized trig functions. These calculations flip the
23  * Y axis since that axis on touchpads is opposite that of the
24  * Cartesian system.
25  */
26
27 #ifndef MT_TRIG_H
28 #define MT_TRIG_H
29
30 #define TR_NONE -1
31 #define TR_DIR_UP 0
32 #define TR_DIR_RT 2
33 #define TR_DIR_DN 4
34 #define TR_DIR_LT 6
35
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.
39  *
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
43  * aproximations.
44  *
45  * TR_NONE will be returned if the magnitude of the vector is zero.
46  */
47 double trig_direction(double dx, double dy);
48
49 /* Generalize a direction.  Returns TR_NONE, TR_DIR_UP, TR_DIR_RT,
50  * TR_DIR_DN, or TR_DIR_LT.
51  */
52 int trig_generalize(double dir);
53
54 /* Add two angles.
55  */
56 double trig_angles_add(double a1, double a2);
57
58 /* Subtract two angles.
59  */
60 double trig_angles_sub(double a1, double a2);
61
62 /* Calculate the acute angle between two angles.
63  */
64 double trig_angles_acute(double a1, double a2);
65
66 /* Average a collection of angles.
67  */
68 double trig_angles_avg(double* angles, int len);
69
70 /* Compare two angles. Returns 0 if a1 == a2. Returns < 0 if a1 < a2.
71  * Returns > 0 if a1 > a2.
72  */
73 int trig_angles_cmp(double a1, double a2);
74
75 #endif
76