Skip to content

Commit

Permalink
Fix broken pens_updown_to_papr method (fix by @victoradan)
Browse files Browse the repository at this point in the history
See https://github.com/drepetto/chiplotle/blob/13ac28a7645a018a4bc62980cb174627ca6b5b54/chiplotle/tools/hpgltools/pens_updown_to_papr.py

I lifted the code directly from there as the test looked to have been
originally broken, there is an open pull request to fix this issue on
the mainline at drepetto#5
  • Loading branch information
willprice committed Aug 20, 2018
1 parent 732735c commit 0c0527f
Showing 1 changed file with 14 additions and 49 deletions.
63 changes: 14 additions & 49 deletions chiplotle/tools/hpgltools/pens_updown_to_papr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import copy

from chiplotle.hpgl.commands import PA, PR, PU, PD
from chiplotle.geometry.core.coordinate import Coordinate


def pens_updown_to_papr(lst):
'''Converts all PU((x1, y1, x2, y2) and PD(x1, y1, x2, y2) found in `lst`
Expand All @@ -11,63 +13,26 @@ def pens_updown_to_papr(lst):
raise TypeError('`lst` argument must be a list or tuple.')

result = [ ]
last_move = None

pen_down = False
pen_up = True

last_penplot = None
for e in lst:
if isinstance(e, (PU, PD)):

if len(e.xy) > 0:
if last_move is None:
if last_penplot is None:
msg = "*** WARNING: %s with coordinates found without prior PA or PR. PA assumed." % e
print(msg)
last_move = PA( )

new_move = None

if isinstance(last_move, PA):
new_move = PA()
elif isinstance(last_move, PR):
new_move = PR()

new_move.xy = e.xy

up_down_command = None

if isinstance(e, PU):
if pen_down:
up_down_command = PU( )
result.append(up_down_command)
pen_up = True
pen_down = False

elif isinstance(e, PD):
if pen_up:
up_down_command = PD( )
result.append(up_down_command)
pen_down = True
pen_up = False


result.append(new_move)

last_move = new_move
last_penplot = PA( )
last_penplot.xy = e.xy
ec = copy.copy(e)
ec.xy = None
result.append(ec)
result.append(copy.copy(last_penplot))
else:
if isinstance(e, PU):
if pen_down:
result.append(e)
pen_up = True
elif isinstance(e, PD):
if pen_up:
result.append(e)
pen_down = True
result.append(e)
else:
if isinstance(e, PR):
last_move = PR( )
last_penplot = PR( )
elif isinstance(e, PA):
last_move = PA( )
last_penplot = PA( )
result.append(e)

return result
Expand Down

0 comments on commit 0c0527f

Please sign in to comment.