SourceCode:MathHelper

From Minecraft Parkour Wiki
Jump to navigation Jump to search

Back to SourceCode

 1 #MathHelper class
 2 
 3 
 4 Static variables:
 5     #array of 65536 floats, used as a lookup table for trigonometric calculations
 6     SIN_TABLE = float[65536]
 7     for i in range(65536):
 8         SIN_TABLE[i] = float(Math.sin(2*i*Math.PI/65536))
 9     
10 
11 Static functions:
12     # float -> float
13     def sin(f):
14         return SIN_TABLE(int(f * 10430.378F) & 65535)
15     
16     # float -> float
17     def cos(f):
18         return SIN_TABLE(int(f * 10430.378F + 16384.0F) & 65535)
19     
20     # number -> float
21     def sqrt(x):
22         return float(Math.sqrt(x))
23     
24     # number -> int
25     def floor(x):
26         i = int(x)
27         if x < i: return i-1
28         else: return i
29     
30     # number -> int
31     def ceiling(x):
32         i = int(x)
33         if x > i: return i+1
34         else: return i
35     
36     # number^3 -> number
37     def clamp(x, inf, sup):
38         if x < inf: return inf
39         elif x > sup: return sup
40         else: return x