-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathnum.hpp
More file actions
45 lines (36 loc) · 1.34 KB
/
Copy pathnum.hpp
File metadata and controls
45 lines (36 loc) · 1.34 KB
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
/**
* Copyright (C) 2011-2022 Bitcraze AB, 2025 Simon D. Levy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, in version 3.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <math.h>
#include <stdint.h>
#include <string.h>
#include <datatypes.hpp>
class Num {
public:
// Small number epsilon, to prevent dividing by zero
static constexpr float kEpsilon = 1e-6f;
static constexpr float kRad2Deg = 180.0f / M_PI;
static constexpr float kDeg2Rad = M_PI / 180.0f;
static auto ConstrainFloat(const float val, const float maxabs) -> float
{
return val < -maxabs ? -maxabs : val > maxabs ? maxabs : val;
}
static auto ConstrainFloat(float value, const float minVal,
const float maxVal) -> float
{
return fminf(maxVal, fmaxf(minVal,value));
}
};