I'm working with a PathBasedVisionShape. I want to get the coordinates for all of the points on the line. It doesn't matter if the coordinates are relative to the shape object or the container.
I can get the general path from the component using a test button like this:
path = event.source.parent.getComponent('Test Path').shape
print type(path)
Output:
java.awt.geom.GeneralPath
path.currentPoint
accurately gives me the last point in the path relative to the content container: Point2D.Float[995.0, 690.0]
If I get the iterator and cycle through the segments, I see the correct number of iterations:
iterator = path.getPathIterator(None)
iDontTrustWhileLoops = 0
while not iterator.done and iDontTrustWhileLoops < 50:
iDontTrustWhileLoops += 1
iterator.next()
print iDontTrustWhileLoops
Output: 5
According to the documentation for the Path2D iterator, I should be able to get the coordinates by passing a double into the currentSegment method, but the script blew up when I did this.
TypeError: currentSegment(): 1st arg can't be coerced to float[], double[]
A bit of trial and error revealed that a list of length 2 or a tuple of floats works:
coords = (0.0, 0.0) # or [0.0, 0.0]
while not iterator.done:
print iterator.currentSegment(coords)
print coords
iterator.next()
...but the input values are not modifed.
Output:
0
(0.0, 0.0)
1
(0.0, 0.0)
1
(0.0, 0.0)
1
(0.0, 0.0)
1
(0.0, 0.0)
I'm stumped at the moment. Does anybody know how to do this?
Edit:
Here is a screenshot of the test line:
iterator.currentSegment(coords)
returns the type of movement, so:
# iterator.SEG_MOVETO = 0
# iterator.SEG_LINETO = 1
# iterator.SEG_QUADTO = 2
# iterator.SEG_CUBICTO = 3
# iterator.SEG_CLOSE = 4
...according to the outputs in my case, the iterator simply moves to the starting position and then uses LINETO to paint each segment of the line.