-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.h
65 lines (46 loc) · 1.5 KB
/
utils.h
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
#ifndef UTILS_H
#define UTILS_H
#include <stdlib.h>
#include <math.h>
#include <sstream>
#include <string>
#include <iostream>
#include <vector>
using namespace std;
//----------------------------------------------------------------------------
// some random number functions.
//----------------------------------------------------------------------------
//returns a random integer between x and y
inline int RandInt(int x,int y) {return rand()%(y-x+1)+x;}
//returns a random float between zero and 1
inline double RandFloat() {return (rand())/(RAND_MAX+1.0);}
//returns a random bool
inline bool RandBool()
{
if (RandInt(0,1)) return true;
else return false;
}
//returns a random float in the range -1 < n < 1
inline double RandomClamped() {return RandFloat() - RandFloat();}
//-----------------------------------------------------------------------
//
// some handy little functions
//-----------------------------------------------------------------------
//converts an integer to a std::string
string itos(int arg);
//converts an float to a std::string
string ftos (float arg);
// clamps the first argument between the second two
void Clamp(double &arg, double min, double max);
/////////////////////////////////////////////////////////////////////
//
// Point structure
//
/////////////////////////////////////////////////////////////////////
struct SPoint
{
float x, y;
SPoint(){}
SPoint(float a, float b):x(a),y(b){}
};
#endif