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 / euclid.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.vector3 import Vector3
11 from fabmetheus_utilities.vector3index import Vector3Index
12 from fabmetheus_utilities import euclidean
13 import math
14
15
16 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
17 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
18 __date__ = '$Date: 2008/02/05 $'
19 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
20
21
22 def _getAccessibleAttribute(attributeName):
23         'Get the accessible attribute.'
24         if attributeName in globalAccessibleAttributeDictionary:
25                 return globalAccessibleAttributeDictionary[attributeName]
26         return None
27
28 def getComplex(x=0.0, y=0.0):
29         'Get the complex.'
30         return complex(x, y)
31
32 def getCylindrical(azimuthDegrees, radius=1.0, z=0.0):
33         'Get the cylindrical vector3 by degrees.'
34         return getCylindricalByRadians(math.radians(azimuthDegrees), radius, z)
35
36 def getCylindricalByRadians(azimuthRadians, radius=1.0, z=0.0):
37         'Get the cylindrical vector3 by radians.'
38         polar = radius * euclidean.getWiddershinsUnitPolar(azimuthRadians)
39         return Vector3(polar.real, polar.imag, z)
40
41 def getNestedVectorTestExample(x=0.0, y=0.0, z=0.0):
42         'Get the NestedVectorTestExample.'
43         return NestedVectorTestExample(Vector3(x, y, z))
44
45 def getPolar(angleDegrees, radius=1.0):
46         'Get the complex polar by degrees.'
47         return radius * euclidean.getWiddershinsUnitPolar(math.radians(angleDegrees))
48
49 def getPolarByRadians(angleRadians, radius=1.0):
50         'Get the complex polar by radians.'
51         return radius * euclidean.getWiddershinsUnitPolar(angleRadians)
52
53 def getSpherical(azimuthDegrees, elevationDegrees, radius=1.0):
54         'Get the spherical vector3 unit by degrees.'
55         return getSphericalByRadians(math.radians(azimuthDegrees), math.radians(elevationDegrees), radius)
56
57 def getSphericalByRadians(azimuthRadians, elevationRadians, radius=1.0):
58         'Get the spherical vector3 unit by radians.'
59         elevationComplex = euclidean.getWiddershinsUnitPolar(elevationRadians)
60         azimuthComplex = euclidean.getWiddershinsUnitPolar(azimuthRadians) * elevationComplex.real
61         return Vector3(azimuthComplex.real, azimuthComplex.imag, elevationComplex.imag) * radius
62
63 def getVector3(x=0.0, y=0.0, z=0.0):
64         'Get the vector3.'
65         return Vector3(x, y, z)
66
67 def getVector3Index(index=0, x=0.0, y=0.0, z=0.0):
68         'Get the vector3.'
69         return Vector3Index(index, x, y, z)
70
71
72 class NestedVectorTestExample:
73         'Class to test local attribute.'
74         def __init__(self, vector3):
75                 'Get the accessible attribute.'
76                 self.vector3 = vector3
77
78         def _getAccessibleAttribute(self, attributeName):
79                 "Get the accessible attribute."
80                 if attributeName == 'vector3':
81                         return getattr(self, attributeName, None)
82                 return None
83
84
85 globalAccessibleAttributeDictionary = {
86         'complex' : getComplex,
87         'getCylindrical' : getCylindrical,
88         'getCylindricalByRadians' : getCylindricalByRadians,
89         'getPolar' : getPolar,
90         'getPolarByRadians' : getPolarByRadians,
91         'getSpherical' : getSpherical,
92         'getSphericalByRadians' : getSphericalByRadians,
93         'NestedVectorTestExample' : getNestedVectorTestExample,
94         'Vector3' : getVector3,
95         'Vector3Index' : getVector3Index}