dump to json before optimise
This commit is contained in:
1 parent
169f52be2f
commit
99d43d5691
2 files changed
+53
-3
No files matched your search
+13
-3
@@ -1,7 +1,7 @@
|
||||
from math import sqrt
|
||||
from datetime import datetime as dt
|
||||
from utils import *
|
||||
|
||||
import json
|
||||
|
||||
def get_distance(a, b, sq=False):
|
||||
x1, y1 = a[0], a[1]
|
||||
@@ -33,8 +33,13 @@ def optimise_path(shapes, sq=False):
|
||||
new_order = []
|
||||
new_order.append(shapes.pop(0))
|
||||
l = len(shapes)
|
||||
lp = 0
|
||||
print(lp)
|
||||
while len(new_order) <= l:
|
||||
|
||||
p = round((1-(len(shapes) / l))*100)
|
||||
if not p == lp:
|
||||
print(p)
|
||||
lp = p
|
||||
shortest = float("Inf")
|
||||
last = new_order[-1][-1]
|
||||
|
||||
@@ -54,11 +59,16 @@ def optimise_path(shapes, sq=False):
|
||||
selection = shape
|
||||
|
||||
if reverse:
|
||||
new_order.append([x for x in reversed(selection)])
|
||||
new_order.append(list(reversed(selection)))
|
||||
#new_order.append([x for x in reversed(selection)])
|
||||
|
||||
else:
|
||||
new_order.append(selection)
|
||||
shapes.remove(selection)
|
||||
|
||||
timer(t1, "optimizing ")
|
||||
|
||||
|
||||
|
||||
return new_order
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
from optimise import optimise_path
|
||||
from svg2gcode import get_shapes, shapes_2_gcode
|
||||
from os.path import join
|
||||
from json import dump as jdump, load as jload
|
||||
from utils import *
|
||||
|
||||
# def write(output_file_name, data):
|
||||
# with open(output_file_name, 'w+') as output_file:
|
||||
# output_file.write(data)
|
||||
|
||||
def dump(outfile, data):
|
||||
with open(outfile, 'w+') as o:
|
||||
jdump(data, o)
|
||||
|
||||
|
||||
def read(infile):
|
||||
with open(infile) as i:
|
||||
return jload(i)
|
||||
|
||||
|
||||
file_location = "/bish/project/plots/rofl/svg"
|
||||
svg_file = "round_1.svg"
|
||||
svg_file = "text.svg"
|
||||
shapes_output = f"{svg_file}.json"
|
||||
optimised_output = f"{svg_file}_optimised.json"
|
||||
gcode_output = "dun.gcode"
|
||||
|
||||
auto_scale = False
|
||||
|
||||
# shapes = get_shapes(join(file_location, svg_file), auto_scale)
|
||||
# dump(join(file_location, shapes_output), shapes)
|
||||
|
||||
jshapes = (read(join(file_location, shapes_output)))
|
||||
new_order = optimise_path(jshapes)
|
||||
dump(join(file_location, optimised_output), new_order)
|
||||
|
||||
# jnew_order = read(join(file_location,optimised_output))
|
||||
# commands = shapes_2_gcode(jnew_order)
|
||||
|
||||
# write_gcode(join(file_location, gcode_output), commands)
|
||||
Reference in new issue
Block a user