summaryrefslogtreecommitdiff
path: root/inc/functions.hpp
blob: ef6d55577ced8edb566b05b16fdc66c4f8b05e3e (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
#ifndef functions_h
#define functions_h

#include <cstdlib>
#include <cmath>

#include "rectangle.hpp"

static double Distance(Rectangle A, Rectangle B){
        return sqrt(pow(A.x-B.x,2) + pow(A.y-B.y,2));
}

static int map(int x, int inMin, int inMax, int outMin, int outMax){
        return (x-inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}

static float getRandom(float x){
        return (-x + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(x-(-x)))));
}

static bool roll(float x){
        float y = (float)(rand()%101)/100;
        if(x >= y)
                return true;
        else
                return false;
}
#endif