doc: update copyright line for 2021
[adg.git] / src / cpml / cpml-utils.c
blob871b0c672ec12521ff45dd0a0b93b2388e83d8e8
1 /* CPML - Cairo Path Manipulation Library
2 * Copyright (C) 2007-2021 Nicola Fontana <ntd at entidi.it>
4 * This library 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 of the License, or (at your option) any later version.
9 * This library 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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 /**
22 * SECTION:cpml-utils
23 * @Section_Id:utilities
24 * @title: Utilities
25 * @short_description: Assorted macros and functions
27 * Collection of macros and functions that do not fit inside any other topic.
29 * Since: 1.0
30 **/
33 #include "cpml-internal.h"
34 #include <math.h>
37 /**
38 * cpml_angle:
39 * @angle: an angle in radians
41 * Normalizes @angle, that is returns the equivalent radians value
42 * between the range <constant>M_PI</constant> (inclusive)
43 * and <constant>-M_PI</constant> (exclusive).
45 * Returns: an equivalent value in radians
47 * Since: 1.0
48 **/
49 double
50 cpml_angle(double angle)
52 while (angle > M_PI)
53 angle -= M_PI * 2;
55 while (angle <= -M_PI)
56 angle += M_PI * 2;
58 return angle;
61 /**
62 * cpml_angle_distance:
63 * @angle: first angle in radians
64 * @from: second angle in radians
66 * Computes the distance between the two given angles. The returned
67 * distance is always positive and is never greater than M_PI.
69 * Returns: the distance in radians
71 * Since: 1.0
72 **/
73 double
74 cpml_angle_distance(double angle, double from)
76 double delta = cpml_angle(from - angle);
77 return fabs(delta);