-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_math.gsc
74 lines (64 loc) · 2.07 KB
/
_math.gsc
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
/**
* Converts the value in the range of [min_src,max_src] into the range of
* [min_dest,max_dest]. The function does clamp the output value if the source
* value is below the minimum or above the maximum.
*
* @param value The value to convert from the source to the destination range.
* @param min_src_value The minimum source value.
* @param max_src_value The maximum source value.
* @param min_dest_value The minimum value of the calculated value.
* @param max_dest_value The maximum value of the calculated value.
*
* @return The source value converted from the source range into the destination range.
*/
convertToRange(value, min_src_value, max_src_value, min_dest_value, max_dest_value)
{
if (value >= min_src_value && value <= max_src_value)
{
max_src = ( max_src_value - min_src_value );
max_dest = ( max_dest_value - min_dest_value );
value -= min_src_value;
result = ( ( value * max_dest ) / max_src );
return result + min_dest_value;
}
else if (value > max_src_value)
{
return max_dest_value;
}
else
{
return min_dest_value;
}
}
/**
* Generates an array with the specified number of integers in a random order.
* @param start The starting number.
* @param count The number of integers to generate.
* @return The array with random integers.
*/
generateRandomOrder(start, count)
{
ordered = []; // 1,2,3,etc.
unordered = []; // 3,6,1,etc.
// Fills the ordered array with the desired integral values
for (i = 0; i < count; i++)
{
ordered[ordered.size] = (start + i);
}
// Randomizes the order of the ordered into the unordered array
for (i = 0; i < count; i++)
{
// Take a random position
index = randomIntRange(0, ordered.size);
// Copy to the new position
unordered[i] = ordered[index];
// Shift
for (j = index + 1; j < ordered.size; j++)
{
ordered[j - 1] = ordered[j];
}
// Remove
ordered[ordered.size - 1] = undefined;
}
return unordered;
}