From 1fc0544497a6c1c749cee6ef26a450dc1c6aefa5 Mon Sep 17 00:00:00 2001 From: simonxeko Date: Wed, 5 Oct 2016 12:13:32 +0800 Subject: [PATCH] Hotfix g2f trim_ends logic --- fluxclient/fcode/fcode_base.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/fluxclient/fcode/fcode_base.py b/fluxclient/fcode/fcode_base.py index df7a304..f90ed16 100644 --- a/fluxclient/fcode/fcode_base.py +++ b/fluxclient/fcode/fcode_base.py @@ -151,22 +151,17 @@ def trim_ends(cls, path): """ PY_TYPE_MOVE = 3 - if path is None: - return path - - if len(path) == 0: + if path is None or len(path) == 0: return path for layer in [0, -1]: - while True: - if len(path) > 0 and len(path[layer]) >= 2: + while len(path): + if len(path[layer]) >= 2: # define an edge's type at end point - # 0 * 2 + 1 = 1 - # -1 * 2 + 1 = -1 - if path[layer][layer * 2 + 1][3] == PY_TYPE_MOVE: + if path[layer][[0,-1][layer]][3] == PY_TYPE_MOVE: path[layer].pop(layer) else: break - elif len(path) > 0: + else: path.pop(layer) return path \ No newline at end of file