asc2svg

asc2svg was intended to be an ASCII diagrams to SVG, like `ditaa` and Svgbob
Log | Files | Refs

commit 83800593ad89e8a0adf4080ebd11b75e8a5cc475
parent 67ce825fc1562ffda30c6796f81dda62aa9b57a8
Author: vh <vetle.haflan@gmail.com>
Date:   Thu, 22 Nov 2018 01:39:34 +0100

Refactor  into local variable for rectangle()

Diffstat:
Ma2svg.py | 16+++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/a2svg.py b/a2svg.py @@ -7,9 +7,6 @@ x_scaling = 0.5 class Figure: def __init__(self, ascii_text): self._elements = [] - self._process_queue = [] # You might want to refactor this away. - # OR make it more useful in the - # process_all method self._ascii_text = [line.strip('\n') for line in ascii_text] self._height = len(ascii_text) self._width = max([len(line) for line in ascii_text]) @@ -206,6 +203,7 @@ class Figure: def rectangle(self, y_start, x_start): # Temporary list of processed chars. Must dismiss if this is not a rectangle processed = [[y_start, x_start]] + process_later = [] if x_start + 1 >= self._width: return None @@ -225,7 +223,7 @@ class Figure: processed.append([y, x_start]) break # If not, the '+' might be a connection to a line on the left - self._process_queue.append([y, x_start]) + process_later.append([y, x_start]) y += 1 else: break @@ -246,7 +244,7 @@ class Figure: for y_test in range(y_start+1, y_stop): cell = self._figarray[y_test][x] if cell == '+': - self._process_queue.append([y_test, x]) + process_later.append([y_test, x]) elif cell != '|': x_stop = None break @@ -259,9 +257,9 @@ class Figure: if lower_cell != '-' and lower_cell != '+': break if upper_cell == '+': - self._process_queue.append([y_start, x]) + process_later.append([y_start, x]) if lower_cell == '+': - self._process_queue.append([y_stop, x]) + process_later.append([y_stop, x]) x += 1 if not x_stop: @@ -273,7 +271,7 @@ class Figure: # TODO : Make Pythonic. (That goes for a lot of this code, though) for y in range(y_start, y_stop): for x in range(x_start, x_stop+1): - if [y, x] not in self._process_queue: + if [y, x] not in process_later: self._processed[y][x] = True new_rect = Rectangle((x_start, y_start), (x_stop, y_stop)) @@ -286,7 +284,7 @@ class Figure: # If not, we can register the bottom line as processed else: for x in range(x_start, x_stop+1): - if [y_stop, x] not in self._process_queue: + if [y_stop, x] not in process_later: self._processed[y_stop][x] = True return rect_list