xrange is range in py3

main
jebba 2022-01-15 01:08:43 -07:00
parent b12c5aef98
commit 8c96fe3c7a
6 changed files with 33 additions and 33 deletions

View File

@ -7,7 +7,7 @@ class Layer():
def __init__(self, dimensions, scale):
self.width, self.height = dimensions
self.scale = scale
self.buckets = [[] for x in xrange(self.width * self.height)]
self.buckets = [[] for x in range(self.width * self.height)]
self.test = 0
def aabb(self, line):
@ -33,14 +33,14 @@ class Layer():
def all_buckets(self, aabb):
x1, y1, x2, y2 = aabb
for y in xrange(y1, y2):
for x in xrange(x1, x2):
for y in range(y1, y2):
for x in range(x1, x2):
yield self.buckets[y * self.width + x]
def all_not_empty_buckets(self, aabb):
x1, y1, x2, y2 = aabb
for y in xrange(y1, y2):
for x in xrange(x1, x2):
for y in range(y1, y2):
for x in range(x1, x2):
bucket = self.buckets[y * self.width + x]
if bucket:
yield bucket
@ -58,7 +58,7 @@ class Layer():
def sub_line(self, line):
for bucket in self.all_not_empty_buckets(self.aabb(line)):
for i in xrange(len(bucket) - 1, -1, -1):
for i in range(len(bucket) - 1, -1, -1):
if bucket[i][1] == line:
del bucket[i]
@ -78,11 +78,11 @@ class Layer():
class Layers():
def __init__(self, dimensions, scale):
width, height, self.depth = dimensions
self.layers = [Layer((width, height), scale) for z in xrange(self.depth)]
self.layers = [Layer((width, height), scale) for z in range(self.depth)]
def all_layers(self, z1, z2):
if z1 != z2:
for z in xrange(self.depth):
for z in range(self.depth):
yield self.layers[z]
else:
yield self.layers[int(z1)]

View File

@ -297,7 +297,7 @@ def thicken_path_2d(points, radius, capstyle, joinstyle):
elif capstyle == 3:
#round cap
rvx, rvy = rv
for i in xrange(resolution + 1):
for i in range(resolution + 1):
angle = (i * math.pi) / resolution
s = math.sin(angle)
c = math.cos(angle)
@ -325,7 +325,7 @@ def thicken_path_2d(points, radius, capstyle, joinstyle):
rvx, rvy = scale_2d(l1_npv, radius)
theta = math.acos(dot_2d(l1_npv, l2_npv))
segs = int((theta / math.pi) * resolution) + 1
for i in xrange(segs + 1):
for i in range(segs + 1):
angle = (i * theta) / segs
s = math.sin(angle)
c = math.cos(angle)

10
pcb.py
View File

@ -30,14 +30,14 @@ def main():
path_range_x_even_layer = flood_range_x_even_layer + 0
path_range_y_odd_layer = flood_range_y_odd_layer + 0
routing_flood_vectors = [[(x, y, 0) for x in xrange(-flood_range_x_even_layer, flood_range_x_even_layer + 1) for y in xrange(-flood_range, flood_range + 1) \
routing_flood_vectors = [[(x, y, 0) for x in range(-flood_range_x_even_layer, flood_range_x_even_layer + 1) for y in range(-flood_range, flood_range + 1) \
if length_2d((x, y)) > 0.1 and length_2d((x, y)) <= flood_range] + [(0, 0, -1), (0, 0, 1)], \
[(x, y, 0) for x in xrange(-flood_range, flood_range + 1) for y in xrange(-flood_range_y_odd_layer, flood_range_y_odd_layer + 1) \
[(x, y, 0) for x in range(-flood_range, flood_range + 1) for y in range(-flood_range_y_odd_layer, flood_range_y_odd_layer + 1) \
if length_2d((x, y)) > 0.1 and length_2d((x, y)) <= flood_range] + [(0, 0, -1), (0, 0, 1)]]
routing_path_vectors = [[(x, y, 0) for x in xrange(-path_range_x_even_layer, path_range_x_even_layer + 1) for y in xrange(-path_range, path_range + 1) \
routing_path_vectors = [[(x, y, 0) for x in range(-path_range_x_even_layer, path_range_x_even_layer + 1) for y in range(-path_range, path_range + 1) \
if length_2d((x, y)) > 0.1 and length_2d((x, y)) <= path_range] + [(0, 0, -1), (0, 0, 1)], \
[(x, y, 0) for x in xrange(-path_range, path_range + 1) for y in xrange(-path_range_y_odd_layer, path_range_y_odd_layer + 1) \
[(x, y, 0) for x in range(-path_range, path_range + 1) for y in range(-path_range_y_odd_layer, path_range_y_odd_layer + 1) \
if length_2d((x, y)) > 0.1 and length_2d((x, y)) <= path_range] + [(0, 0, -1), (0, 0, 1)]]
dfunc = [manhattan_distance, squared_euclidean_distance, euclidean_distance, \
@ -55,7 +55,7 @@ def main():
pcb.print_pcb()
best_cost = None
best_pcb = None
for i in xrange(args.s[0]):
for i in range(args.s[0]):
if not pcb.route(args.t[0]):
pcb.shuffle_netlist()
continue

View File

@ -28,7 +28,7 @@ class Pcb():
self.width *= resolution
self.height *= resolution
self.stride = self.width * self.height
self.nodes = array('i', [0 for x in xrange(self.stride * self.depth)])
self.nodes = array('i', [0 for x in range(self.stride * self.depth)])
self.netlist = []
self.deform = {}
@ -98,7 +98,7 @@ class Pcb():
break
def unmark_distances(self):
self.nodes = array('i', [0 for x in xrange(self.stride * self.depth)])
self.nodes = array('i', [0 for x in range(self.stride * self.depth)])
def add_track(self, track):
radius, via, gap, net = track
@ -179,7 +179,7 @@ class Net():
self.paths = []
self.remove()
for term in self.terminals:
for z in xrange(pcb.depth):
for z in range(pcb.depth):
pcb.deform[(int(term[2][0] + 0.5), int(term[2][1] + 0.5), z)] = (term[2][0], term[2][1], float(z))
def optimise_paths(self, paths):
@ -227,7 +227,7 @@ class Net():
if not s:
self.pcb.layers.add_line((x, y, 0), (x, y, self.pcb.depth - 1), r, g)
else:
for z in xrange(self.pcb.depth):
for z in range(self.pcb.depth):
for a, b in zip(s, islice(s, 1, None)):
self.pcb.layers.add_line((x + a[0], y + a[1], z), (x + b[0], y + b[1], z), r, g)
@ -237,7 +237,7 @@ class Net():
if not s:
self.pcb.layers.sub_line((x, y, 0), (x, y, self.pcb.depth - 1), r, g)
else:
for z in xrange(self.pcb.depth):
for z in range(self.pcb.depth):
for a, b in zip(s, islice(s, 1, None)):
self.pcb.layers.sub_line((x + a[0], y + a[1], z), (x + b[0], y + b[1], z), r, g)
@ -252,9 +252,9 @@ class Net():
self.paths = []
self.sub_terminal_collision_lines()
visited = set()
for index in xrange(1, len(self.terminals)):
visited |= set([(int(self.terminals[index - 1][2][0]+0.5), int(self.terminals[index - 1][2][1]+0.5), z) for z in xrange(self.pcb.depth)])
ends = [(int(self.terminals[index][2][0]+0.5), int(self.terminals[index][2][1]+0.5), z) for z in xrange(self.pcb.depth)]
for index in range(1, len(self.terminals)):
visited |= set([(int(self.terminals[index - 1][2][0]+0.5), int(self.terminals[index - 1][2][1]+0.5), z) for z in range(self.pcb.depth)])
ends = [(int(self.terminals[index][2][0]+0.5), int(self.terminals[index][2][1]+0.5), z) for z in range(self.pcb.depth)]
self.pcb.mark_distances(self.pcb.routing_flood_vectors, self.radius, self.via, self.gap, visited, ends)
ends = [(self.pcb.get_node(node), node) for node in ends]
ends.sort()

10
view.py
View File

@ -40,11 +40,11 @@ def scale_and_split_tracks(tracks, scale):
track[1] *= scale
track[2] *= scale
track[4] = split_paths(track[4])
for i in xrange(len(track[3])):
for i in range(len(track[3])):
r, g, (x, y, z), s = track[3][i]
track[3][i] = r * scale, g * scale, ((x + MARGIN) * scale, (y + MARGIN) * scale, z), [(cx * scale, cy * scale) for cx, cy in s]
for path in track[4]:
for i in xrange(len(path)):
for i in range(len(path)):
x, y, z = path[i]
path[i] = (x + MARGIN) * scale, (y + MARGIN) * scale, z
@ -93,7 +93,7 @@ def doframe(dimensions, root, canvas, poll):
if args.o[0] == 0:
colors = ['red', 'green', 'blue', 'yellow', 'fuchsia', 'aqua']
for depth in xrange(pcb_depth - 1, -1, -1):
for depth in range(pcb_depth - 1, -1, -1):
brush = aggdraw.Brush(colors[depth % len(colors)], opacity = 128)
for track in tracks:
radius, via, gap, terminals, paths = track
@ -118,7 +118,7 @@ def doframe(dimensions, root, canvas, poll):
points = list(chain.from_iterable([(cx + x, cy + y) for cx, cy in s]))
ctx.polygon(points, white_brush)
else:
for depth in xrange(pcb_depth):
for depth in range(pcb_depth):
for track in tracks:
radius, via, gap, terminals, paths = track
for path in paths:
@ -142,7 +142,7 @@ def doframe(dimensions, root, canvas, poll):
if r == 0:
points = list(chain.from_iterable([(cx + x, cy + y) for cx, cy in s]))
ctx.polygon(points, white_brush)
for depth in xrange(pcb_depth):
for depth in range(pcb_depth):
for track in tracks:
radius, via, gap, terminals, paths = track
for path in paths:

View File

@ -43,11 +43,11 @@ def scale_and_split_tracks(tracks, scale):
track[1] *= scale
track[2] *= scale
track[4] = split_paths(track[4])
for i in xrange(len(track[3])):
for i in range(len(track[3])):
r, g, (x, y, z), s = track[3][i]
track[3][i] = r * scale, g * scale, ((x + MARGIN) * scale, (y + MARGIN) * scale, z), [(cx * scale, cy * scale) for cx, cy in s]
for path in track[4]:
for i in xrange(len(path)):
for i in range(len(path)):
x, y, z = path[i]
path[i] = (x + MARGIN) * scale, (y + MARGIN) * scale, z
@ -94,7 +94,7 @@ def doframe(frame_num, dimensions, poll, fig, ax):
if args.o[0] == 0:
colors = ['red', 'green', 'blue', 'yellow', 'fuchsia', 'aqua']
for depth in xrange(pcb_depth - 1, -1, -1):
for depth in range(pcb_depth - 1, -1, -1):
brush = colors[depth % len(colors)]
for track in tracks:
radius, via, gap, terminals, paths = track
@ -124,7 +124,7 @@ def doframe(frame_num, dimensions, poll, fig, ax):
poly = plt.Polygon(points, facecolor = 'white', edgecolor = 'none')
ax.add_patch(poly)
else:
for depth in xrange(pcb_depth):
for depth in range(pcb_depth):
for track in tracks:
radius, via, gap, terminals, paths = track
for path in paths:
@ -153,7 +153,7 @@ def doframe(frame_num, dimensions, poll, fig, ax):
points = [(cx + x, cy + y) for cx, cy in s]
poly = plt.Polygon(points, facecolor = 'white', edgecolor = 'none')
ax.add_patch(poly)
for depth in xrange(pcb_depth):
for depth in range(pcb_depth):
for track in tracks:
radius, via, gap, terminals, paths = track
for path in paths: