chiark / gitweb /
0adb453441086857a939a896843cd8d9cdda88d4
[cura.git] / Cura / fabmetheus_utilities / geometry / geometry_tools / path_elements / arc.py
1 """
2 Arc vertexes.
3
4 From:
5 http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
6
7 """
8
9 from __future__ import absolute_import
10 #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.
11 import __init__
12
13 from fabmetheus_utilities.geometry.creation import lineation
14 from fabmetheus_utilities.geometry.geometry_utilities import evaluate
15 from fabmetheus_utilities.vector3 import Vector3
16 from fabmetheus_utilities import euclidean
17 from fabmetheus_utilities import svg_reader
18 import math
19
20
21 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
22 __credits__ = 'Art of Illusion <http://www.artofillusion.org/>'
23 __date__ = '$Date: 2008/02/05 $'
24 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
25
26
27 def getArcPath(elementNode):
28         "Get the arc path.rx ry x-axis-rotation large-arc-flag sweep-flag"
29         begin = elementNode.getPreviousVertex(Vector3())
30         end = evaluate.getVector3FromElementNode(elementNode)
31         largeArcFlag = evaluate.getEvaluatedBoolean(True, elementNode, 'largeArcFlag')
32         radius = lineation.getComplexByPrefix(elementNode, 'radius', complex(1.0, 1.0))
33         sweepFlag = evaluate.getEvaluatedBoolean(True, elementNode, 'sweepFlag')
34         xAxisRotation = math.radians(evaluate.getEvaluatedFloat(0.0, elementNode, 'xAxisRotation'))
35         arcComplexes = svg_reader.getArcComplexes(begin.dropAxis(), end.dropAxis(), largeArcFlag, radius, sweepFlag, xAxisRotation)
36         path = []
37         if len(arcComplexes) < 1:
38                 return []
39         incrementZ = (end.z - begin.z) / float(len(arcComplexes))
40         z = begin.z
41         for pointIndex in xrange(len(arcComplexes)):
42                 pointComplex = arcComplexes[pointIndex]
43                 z += incrementZ
44                 path.append(Vector3(pointComplex.real, pointComplex.imag, z))
45         if len(path) > 0:
46                 path[-1] = end
47         return path
48
49 def processElementNode(elementNode):
50         "Process the xml element."
51         elementNode.parentNode.xmlObject.vertexes += getArcPath(elementNode)