backends: Add support for timers to backends.
[gfxprim/pasky.git] / libs / gfx / GP_AngleUtils.c
blob67911b41626d93661ff51e071ab873c77999c694
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2011 Tomas Gavenciak <gavento@ucw.cz> *
20 * Copyright (C) 2012 Cyril Hrubis <metan@ucw.cz> *
21 * Copyright (C) 2012 Jiri Dluhos <jiri.bluebear.dluhos@gmail.com> *
22 * *
23 *****************************************************************************/
25 #include "GP_AngleUtils.h"
27 #include <math.h>
29 double GP_NormalizeAngle(double phi)
31 // clamp angle to <-2*pi, 2*pi>
32 double phi2 = fmod(phi, 2*M_PI);
34 // clamp angle to <0, 2*pi>
35 if (phi2 < 0)
36 phi2 += 2*M_PI;
38 return phi2;
41 int GP_AngleInRange(double angle, double start, double end)
43 if (start < end) {
44 return (angle >= start && angle <= end);
45 } else {
46 return (angle >= start && angle <= 2*M_PI)
47 || (angle >= 0 && angle <= end);