-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMisc.cpp
50 lines (38 loc) · 811 Bytes
/
Misc.cpp
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
#ifndef LINEARCHEXT_MISC_CPP
#define LINEARCHEXT_MISC_CPP
#include <cmath>
#include <stdexcept>
#include "Misc.hpp"
namespace LinearchExt{
double Min(double a, double b){
if (a<b)
return a;
return b;
}
double Max(double a, double b){
if (a>b)
return a;
return b;
}
double Abs(double x){
return x < 0 ? -x : x;
}
double Lerp(double a, double b, double t){
return a + (b-a) * t;
}
double MoveTowards(double a, double b, double maxDelta){
if (b==a)
return a;
double absDelta = Abs(b-a);
return a + (b-a)/absDelta * Min(maxDelta, absDelta);
}
template <typename B, typename D> bool TestDerivation(){
try {
DerivationTester<B, D> t;
}catch(std::exception x){
return false;
}
return true;
}
}
#endif //MAIN_CPP