-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathUtilities.h
More file actions
78 lines (62 loc) · 1.26 KB
/
MathUtilities.h
File metadata and controls
78 lines (62 loc) · 1.26 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once
#ifndef _MATH_UTILITIES_H_
#define _MATH_UTILITIES_H_
#include <time.h>
#include <cstdlib>
namespace Math
{
const float PI = 3.141592653f;
inline int RandInRange( int min, int max )
{
return min + rand() % ( max - min + 1 );
}
inline float RandInRange( float min, float max )
{
return min + ( max - min ) * ( rand() / (float) RAND_MAX );
}
inline double RandInRange( double min, double max )
{
return min + ( max - min ) * ( rand() / (double) RAND_MAX );
}
inline float ConvertToRad( float degrees )
{
return degrees * ( PI / 180 );
}
inline float ConvertToDegrees( float radians )
{
return radians * ( 180 / PI );
}
inline float CalculateSquaredDistance( float x1, float y1, float x2, float y2 )
{
float xdiff = x2 - x1;
float ydiff = y2 - y1;
return ( xdiff * xdiff ) + ( ydiff * ydiff );
}
template< typename T >
T Clamp( T x, T min, T max )
{
assert( max >= min );
return min( max( x, min), max);
}
template< typename T >
T Sign( T x )
{
return ( x < 0 ) ? static_cast< T >( -1 ) : ( x > 0) ? static_cast< T >( 1 ) : 0;
}
struct Rectangle
{
Rectangle()
: left( 0 )
, top( 0 )
, right( 0 )
, bottom( 0 )
{}
// DATA
//
int left;
int right;
int top;
int bottom;
};
}
#endif