mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-02-03 18:10:28 +01:00
Add device_float_get_direction
With some upcoming changes we need this function for device float coordinates as well. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
db9cfc9c5c
commit
187c38f660
1 changed files with 26 additions and 11 deletions
|
|
@ -701,28 +701,28 @@ enum directions {
|
|||
};
|
||||
|
||||
static inline uint32_t
|
||||
normalized_get_direction(struct normalized_coords norm)
|
||||
xy_get_direction(double x, double y)
|
||||
{
|
||||
uint32_t dir = UNDEFINED_DIRECTION;
|
||||
int d1, d2;
|
||||
double r;
|
||||
|
||||
if (fabs(norm.x) < 2.0 && fabs(norm.y) < 2.0) {
|
||||
if (norm.x > 0.0 && norm.y > 0.0)
|
||||
if (fabs(x) < 2.0 && fabs(y) < 2.0) {
|
||||
if (x > 0.0 && y > 0.0)
|
||||
dir = S | SE | E;
|
||||
else if (norm.x > 0.0 && norm.y < 0.0)
|
||||
else if (x > 0.0 && y < 0.0)
|
||||
dir = N | NE | E;
|
||||
else if (norm.x < 0.0 && norm.y > 0.0)
|
||||
else if (x < 0.0 && y > 0.0)
|
||||
dir = S | SW | W;
|
||||
else if (norm.x < 0.0 && norm.y < 0.0)
|
||||
else if (x < 0.0 && y < 0.0)
|
||||
dir = N | NW | W;
|
||||
else if (norm.x > 0.0)
|
||||
else if (x > 0.0)
|
||||
dir = NE | E | SE;
|
||||
else if (norm.x < 0.0)
|
||||
else if (x < 0.0)
|
||||
dir = NW | W | SW;
|
||||
else if (norm.y > 0.0)
|
||||
else if (y > 0.0)
|
||||
dir = SE | S | SW;
|
||||
else if (norm.y < 0.0)
|
||||
else if (y < 0.0)
|
||||
dir = NE | N | NW;
|
||||
} else {
|
||||
/* Calculate r within the interval [0 to 8)
|
||||
|
|
@ -731,7 +731,7 @@ normalized_get_direction(struct normalized_coords norm)
|
|||
* d_f = r / 2π ([0 .. 1))
|
||||
* d_8 = 8 * d_f
|
||||
*/
|
||||
r = atan2(norm.y, norm.x);
|
||||
r = atan2(y, x);
|
||||
r = fmod(r + 2.5*M_PI, 2*M_PI);
|
||||
r *= 4*M_1_PI;
|
||||
|
||||
|
|
@ -745,4 +745,19 @@ normalized_get_direction(struct normalized_coords norm)
|
|||
return dir;
|
||||
}
|
||||
|
||||
static inline uint32_t
|
||||
normalized_get_direction(struct normalized_coords norm)
|
||||
{
|
||||
return xy_get_direction(norm.x, norm.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the direction for the given set of coordinates.
|
||||
* assumption: coordinates are normalized to one axis resolution.
|
||||
*/
|
||||
static inline uint32_t
|
||||
device_float_get_direction(struct device_float_coords coords)
|
||||
{
|
||||
return xy_get_direction(coords.x, coords.y);
|
||||
}
|
||||
#endif /* LIBINPUT_PRIVATE_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue