summaryrefslogtreecommitdiffstats
path: root/src/common/ufo-math.h
blob: 70084ce936a95260bd84d7465d658707c01817a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright (C) 2015-2017 Karlsruhe Institute of Technology
 *
 * This file is part of Ufo.
 *
 * This library is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef UFO_MATH_H
#define UFO_MATH_H

#include <glib.h>

#define UFO_MATH_EPSILON 1e-7
#define UFO_MATH_ARE_ALMOST_EQUAL(a, b) (ABS ((a) - (b)) < UFO_MATH_EPSILON)

typedef struct {
    gdouble x, y, z;
} UfoPoint;

UfoPoint        *ufo_point_new                  (gdouble      x,
                                                 gdouble      y,
                                                 gdouble      z);
void             ufo_point_free                 (UfoPoint    *point);
void             ufo_point_mul_scalar           (UfoPoint    *point,
                                                 gdouble      value);
void             ufo_point_add                  (UfoPoint    *point,
                                                 UfoPoint    *other);
void             ufo_point_subtract             (UfoPoint    *point,
                                                 UfoPoint    *other);
gdouble          ufo_point_dot_product          (UfoPoint    *point,
                                                 UfoPoint    *other);
void             ufo_point_rotate_x             (UfoPoint    *point,
                                                 gdouble      angle);
void             ufo_point_rotate_y             (UfoPoint    *point,
                                                 gdouble      angle);
void             ufo_point_rotate_z             (UfoPoint    *point,
                                                 gdouble      angle);
gdouble          ufo_array_maximum              (gdouble     *array,
                                                 gint         num_values);
gdouble          ufo_array_minimum              (gdouble     *array,
                                                 gint         num_values);
gdouble          ufo_clip_value                 (gdouble value,
                                                 gdouble minimum,
                                                 gdouble maximum);

#endif