Optimisation du code de sortie grâce à Zezeombye
This commit is contained in:
parent
d4bb13184d
commit
db4850e0f4
|
@ -129,8 +129,8 @@ def generate_code(lines, args):
|
|||
for (xa, yb), (x, y) in lines:
|
||||
x, y = x + int(args.offset[0]), y + int(args.offset[1])
|
||||
a, b = xa - x + int(args.offset[0]), yb - y + int(args.offset[1])
|
||||
str_x += "{}{:+}{}, ".format(x, a, "T" if a else "")
|
||||
str_y += "{}{:+}{}, ".format(y, b, "T" if b else "")
|
||||
str_x += "{}, ".format(get_coord(x, a))
|
||||
str_y += "{}, ".format(get_coord(y, b))
|
||||
|
||||
str_x = str_x[:-2] + "}"
|
||||
str_y = str_y[:-2] + "}"
|
||||
|
@ -138,6 +138,26 @@ def generate_code(lines, args):
|
|||
return code
|
||||
|
||||
|
||||
# From Zezeombye's BIDE
|
||||
def get_coord(start, end):
|
||||
result = "";
|
||||
if start != 0:
|
||||
result += str(start)
|
||||
delta = end - start
|
||||
if delta != 0:
|
||||
if delta > 0 and start != 0:
|
||||
result += "+";
|
||||
if delta < 0:
|
||||
result += "-";
|
||||
if delta != 1 and delta != -1:
|
||||
result += str(abs(delta))
|
||||
result += "T";
|
||||
if len(result) == 0:
|
||||
result = "0"
|
||||
return result;
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
start = time()
|
||||
|
||||
|
|
Loading…
Reference in New Issue