chiark / gitweb /
Add uppercase STL and HEX to file dialog filters for linux/MacOS
[cura.git] / Cura / cura_sf / fabmetheus_utilities / geometry / geometry_utilities / evaluate_fundamentals / _math.py
1 """
2 Boolean geometry utilities.
3
4 """
5
6 from __future__ import absolute_import
7 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
8 import __init__
9
10 from fabmetheus_utilities import euclidean
11 import math
12
13
14 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
15 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
16 __date__ = '$Date: 2008/02/05 $'
17 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
18
19
20 globalNativeFunctions = 'acos asin atan atan2 ceil cos cosh degrees e exp fabs floor fmod frexp hypot'.split()
21 globalNativeFunctions += 'ldexp log log10 modf pi pow radians sin sinh sqrt tan tanh trunc'.split()
22 globalNativeFunctionSet = set(globalNativeFunctions)
23 #Constants from: http://www.physlink.com/reference/MathConstants.cfm
24 #Tau is from: http://tauday.com/
25 #If anyone wants to add stuff, more constants are at: http://en.wikipedia.org/wiki/Mathematical_constant
26 globalMathConstantDictionary = {
27         'euler' : 0.5772156649015328606065120,
28         'golden' : euclidean.globalGoldenRatio,
29         'goldenAngle' : euclidean.globalGoldenAngle,
30         'goldenRatio' : euclidean.globalGoldenRatio,
31         'tau' : euclidean.globalTau}
32
33
34 def _getAccessibleAttribute(attributeName):
35         'Get the accessible attribute.'
36         if attributeName in globalMathConstantDictionary:
37                 return globalMathConstantDictionary[attributeName]
38         if attributeName in globalNativeFunctionSet:
39                 return math.__dict__[attributeName]
40         if attributeName in globalAccessibleAttributeDictionary:
41                 return globalAccessibleAttributeDictionary[attributeName]
42         return None
43
44
45 def getAbs(value):
46         'Get the abs.'
47         return abs(value)
48
49 def getBoolean(value):
50         'Get the boolean.'
51         return bool(value)
52
53 def getDivmod(x, y):
54         'Get the divmod.'
55         return divmod(x, y)
56
57 def getFloat(value):
58         'Get the float.'
59         return float(value)
60
61 def getHex(value):
62         'Get the hex.'
63         return hex(value)
64
65 def getInt(value):
66         'Get the int.'
67         return int(value)
68
69 def getLong(value):
70         'Get the long.'
71         return long(value)
72
73 def getMax(first, second):
74         'Get the max.'
75         return max(first, second)
76
77 def getMin(first, second):
78         'Get the min.'
79         return min(first, second)
80
81 def getRound(value):
82         'Get the round.'
83         return round(value)
84
85 def getString(value):
86         'Get the string.'
87         return str(value)
88
89
90 globalAccessibleAttributeDictionary = {
91         'abs' : getAbs,
92         'boolean' : getBoolean,
93         'divmod' : getDivmod,
94         'float' : getFloat,
95         'hex' : getHex,
96         'int' : getInt,
97         'long' : getLong,
98         'max' : getMax,
99         'min' : getMin,
100         'round' : getRound,
101         'string' : getString}