chiark / gitweb /
f3ec99effdc3c063108fd2b5d9c4d5df4e5f2d51
[cura.git] / Cura / fabmetheus_utilities / geometry / geometry_utilities / evaluate_fundamentals / measure.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 import euclidean
12 import math
13
14
15 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
16 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
17 __date__ = '$Date: 2008/02/05 $'
18 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
19
20
21 def _getAccessibleAttribute(attributeName):
22         'Get the accessible attribute.'
23         if attributeName in globalAccessibleAttributeDictionary:
24                 return globalAccessibleAttributeDictionary[attributeName]
25         return None
26
27 def getBoundingBoxByPaths(elementNode):
28         'Get bounding box of the transformed paths of the xmlObject of the elementNode.'
29         transformedPaths = elementNode.xmlObject.getTransformedPaths()
30         maximum = euclidean.getMaximumByVector3Paths(transformedPaths)
31         minimum = euclidean.getMinimumByVector3Paths(transformedPaths)
32         return [minimum, maximum]
33
34 def getCenterByPaths(elementNode):
35         'Get center of the transformed paths of the xmlObject of the elementNode.'
36         transformedPaths = elementNode.xmlObject.getTransformedPaths()
37         return 0.5 * (euclidean.getMaximumByVector3Paths(transformedPaths) + euclidean.getMinimumByVector3Paths(transformedPaths))
38
39 def getExtentByPaths(elementNode):
40         'Get extent of the transformed paths of the xmlObject of the elementNode.'
41         transformedPaths = elementNode.xmlObject.getTransformedPaths()
42         return euclidean.getMaximumByVector3Paths(transformedPaths) - euclidean.getMinimumByVector3Paths(transformedPaths)
43
44 def getInradiusByPaths(elementNode):
45         'Get inradius of the transformed paths of the xmlObject of the elementNode.'
46         return 0.5 * getExtentByPaths(elementNode)
47
48 def getMinimumByPaths(elementNode):
49         'Get minimum of the transformed paths of the xmlObject of the elementNode.'
50         return euclidean.getMinimumByVector3Paths(elementNode.xmlObject.getTransformedPaths())
51
52 def getMaximumByPaths(elementNode):
53         'Get maximum of the transformed paths of the xmlObject of the elementNode.'
54         return euclidean.getMaximumByVector3Paths(elementNode.xmlObject.getTransformedPaths())
55  
56
57 globalAccessibleAttributeDictionary = {
58         'getBoundingBoxByPaths' : getBoundingBoxByPaths,
59         'getCenterByPaths' : getCenterByPaths,
60         'getExtentByPaths' : getExtentByPaths,
61         'getInradiusByPaths' : getInradiusByPaths,
62         'getMaximumByPaths' : getMaximumByPaths,
63         'getMinimumByPaths' : getMinimumByPaths}