2 Boolean geometry utilities.
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.
10 from fabmetheus_utilities.vector3 import Vector3
11 from fabmetheus_utilities import euclidean
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'
21 def _getAccessibleAttribute(attributeName):
22 'Get the accessible attribute.'
23 if attributeName in globalAccessibleAttributeDictionary:
24 return globalAccessibleAttributeDictionary[attributeName]
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]
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))
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)
44 def getInradiusByPaths(elementNode):
45 'Get inradius of the transformed paths of the xmlObject of the elementNode.'
46 return 0.5 * getExtentByPaths(elementNode)
48 def getMinimumByPaths(elementNode):
49 'Get minimum of the transformed paths of the xmlObject of the elementNode.'
50 return euclidean.getMinimumByVector3Paths(elementNode.xmlObject.getTransformedPaths())
52 def getMaximumByPaths(elementNode):
53 'Get maximum of the transformed paths of the xmlObject of the elementNode.'
54 return euclidean.getMaximumByVector3Paths(elementNode.xmlObject.getTransformedPaths())
57 globalAccessibleAttributeDictionary = {
58 'getBoundingBoxByPaths' : getBoundingBoxByPaths,
59 'getCenterByPaths' : getCenterByPaths,
60 'getExtentByPaths' : getExtentByPaths,
61 'getInradiusByPaths' : getInradiusByPaths,
62 'getMaximumByPaths' : getMaximumByPaths,
63 'getMinimumByPaths' : getMinimumByPaths}