no izip in python3
parent
fd17ddaf65
commit
c84567514b
14
mymath.py
14
mymath.py
|
@ -6,16 +6,16 @@ import math, random, itertools
|
||||||
#generic distance metric stuff
|
#generic distance metric stuff
|
||||||
|
|
||||||
def manhattan_distance(p1, p2):
|
def manhattan_distance(p1, p2):
|
||||||
return sum(abs(x - y) for x, y in itertools.izip(p1, p2))
|
return sum(abs(x - y) for x, y in itertools.zip(p1, p2))
|
||||||
|
|
||||||
def euclidean_distance(p1, p2):
|
def euclidean_distance(p1, p2):
|
||||||
return math.sqrt(sum((x - y) ** 2 for x, y in itertools.izip(p1, p2)))
|
return math.sqrt(sum((x - y) ** 2 for x, y in itertools.zip(p1, p2)))
|
||||||
|
|
||||||
def squared_euclidean_distance(p1, p2):
|
def squared_euclidean_distance(p1, p2):
|
||||||
return sum((x - y) ** 2 for x, y in itertools.izip(p1, p2))
|
return sum((x - y) ** 2 for x, y in itertools.zip(p1, p2))
|
||||||
|
|
||||||
def chebyshev_distance(p1, p2):
|
def chebyshev_distance(p1, p2):
|
||||||
return max(abs(x - y) for x, y in itertools.izip(p1, p2))
|
return max(abs(x - y) for x, y in itertools.zip(p1, p2))
|
||||||
|
|
||||||
def reciprical_distance(p1, p2):
|
def reciprical_distance(p1, p2):
|
||||||
d = manhattan_distance(p1, p2)
|
d = manhattan_distance(p1, p2)
|
||||||
|
@ -37,16 +37,16 @@ def equal(p1, p2):
|
||||||
return manhattan_distance(p1, p2) == 0.0
|
return manhattan_distance(p1, p2) == 0.0
|
||||||
|
|
||||||
def add(p1, p2):
|
def add(p1, p2):
|
||||||
return tuple(x + y for x, y in itertools.izip(p1, p2))
|
return tuple(x + y for x, y in itertools.zip(p1, p2))
|
||||||
|
|
||||||
def sub(p1, p2):
|
def sub(p1, p2):
|
||||||
return tuple(x - y for x, y in itertools.izip(p1, p2))
|
return tuple(x - y for x, y in itertools.zip(p1, p2))
|
||||||
|
|
||||||
def scale(p, s):
|
def scale(p, s):
|
||||||
return tuple(x * s for x in p)
|
return tuple(x * s for x in p)
|
||||||
|
|
||||||
def dot(p1, p2):
|
def dot(p1, p2):
|
||||||
return sum(x * y for x, y in itertools.izip(p1, p2))
|
return sum(x * y for x, y in itertools.zip(p1, p2))
|
||||||
|
|
||||||
def length(p):
|
def length(p):
|
||||||
return math.sqrt(dot(p, p))
|
return math.sqrt(dot(p, p))
|
||||||
|
|
14
router.py
14
router.py
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
import sys, time
|
import sys, time
|
||||||
from array import array
|
from array import array
|
||||||
from itertools import islice, izip, groupby
|
from itertools import islice, zip, groupby
|
||||||
from random import shuffle
|
from random import shuffle
|
||||||
from mymath import *
|
from mymath import *
|
||||||
from layer import *
|
from layer import *
|
||||||
|
@ -159,7 +159,7 @@ class Pcb():
|
||||||
for net in self.netlist:
|
for net in self.netlist:
|
||||||
num_terminals += len(net.terminals)
|
num_terminals += len(net.terminals)
|
||||||
for path in net.paths:
|
for path in net.paths:
|
||||||
for a, b in izip(path, islice(path, 1, None)):
|
for a, b in zip(path, islice(path, 1, None)):
|
||||||
if a[2] != b[2]:
|
if a[2] != b[2]:
|
||||||
num_vias += 1
|
num_vias += 1
|
||||||
print >> sys.stderr, "Number of Terminals:", num_terminals
|
print >> sys.stderr, "Number of Terminals:", num_terminals
|
||||||
|
@ -187,7 +187,7 @@ class Net():
|
||||||
for path in paths:
|
for path in paths:
|
||||||
opt_path = []
|
opt_path = []
|
||||||
d = (0, 0, 0)
|
d = (0, 0, 0)
|
||||||
for a, b in izip(path, islice(path, 1, None)):
|
for a, b in zip(path, islice(path, 1, None)):
|
||||||
p0 = self.pcb.grid_to_space_point(a)
|
p0 = self.pcb.grid_to_space_point(a)
|
||||||
p1 = self.pcb.grid_to_space_point(b)
|
p1 = self.pcb.grid_to_space_point(b)
|
||||||
d1 = norm_3d(sub_3d(p1, p0))
|
d1 = norm_3d(sub_3d(p1, p0))
|
||||||
|
@ -203,7 +203,7 @@ class Net():
|
||||||
|
|
||||||
def add_paths_collision_lines(self):
|
def add_paths_collision_lines(self):
|
||||||
for path in self.paths:
|
for path in self.paths:
|
||||||
for a, b in izip(path, islice(path, 1, None)):
|
for a, b in zip(path, islice(path, 1, None)):
|
||||||
p0 = self.pcb.grid_to_space_point(a)
|
p0 = self.pcb.grid_to_space_point(a)
|
||||||
p1 = self.pcb.grid_to_space_point(b)
|
p1 = self.pcb.grid_to_space_point(b)
|
||||||
if a[2] != b[2]:
|
if a[2] != b[2]:
|
||||||
|
@ -213,7 +213,7 @@ class Net():
|
||||||
|
|
||||||
def sub_paths_collision_lines(self):
|
def sub_paths_collision_lines(self):
|
||||||
for path in self.paths:
|
for path in self.paths:
|
||||||
for a, b in izip(path, islice(path, 1, None)):
|
for a, b in zip(path, islice(path, 1, None)):
|
||||||
p0 = self.pcb.grid_to_space_point(a)
|
p0 = self.pcb.grid_to_space_point(a)
|
||||||
p1 = self.pcb.grid_to_space_point(b)
|
p1 = self.pcb.grid_to_space_point(b)
|
||||||
if a[2] != b[2]:
|
if a[2] != b[2]:
|
||||||
|
@ -228,7 +228,7 @@ class Net():
|
||||||
self.pcb.layers.add_line((x, y, 0), (x, y, self.pcb.depth - 1), r, g)
|
self.pcb.layers.add_line((x, y, 0), (x, y, self.pcb.depth - 1), r, g)
|
||||||
else:
|
else:
|
||||||
for z in xrange(self.pcb.depth):
|
for z in xrange(self.pcb.depth):
|
||||||
for a, b in izip(s, islice(s, 1, None)):
|
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)
|
self.pcb.layers.add_line((x + a[0], y + a[1], z), (x + b[0], y + b[1], z), r, g)
|
||||||
|
|
||||||
def sub_terminal_collision_lines(self):
|
def sub_terminal_collision_lines(self):
|
||||||
|
@ -238,7 +238,7 @@ class Net():
|
||||||
self.pcb.layers.sub_line((x, y, 0), (x, y, self.pcb.depth - 1), r, g)
|
self.pcb.layers.sub_line((x, y, 0), (x, y, self.pcb.depth - 1), r, g)
|
||||||
else:
|
else:
|
||||||
for z in xrange(self.pcb.depth):
|
for z in xrange(self.pcb.depth):
|
||||||
for a, b in izip(s, islice(s, 1, None)):
|
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)
|
self.pcb.layers.sub_line((x + a[0], y + a[1], z), (x + b[0], y + b[1], z), r, g)
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
|
|
4
view.py
4
view.py
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
import os, sys, argparse, select, tkinter, aggdraw
|
import os, sys, argparse, select, tkinter, aggdraw
|
||||||
from ast import literal_eval
|
from ast import literal_eval
|
||||||
from itertools import izip, islice, chain
|
from itertools import islice, chain
|
||||||
from PIL import Image, ImageTk
|
from PIL import Image, ImageTk
|
||||||
from mymath import *
|
from mymath import *
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ def split_paths(paths):
|
||||||
new_paths = []
|
new_paths = []
|
||||||
for path in paths:
|
for path in paths:
|
||||||
new_path = []
|
new_path = []
|
||||||
for a, b in izip(path, islice(path, 1, None)):
|
for a, b in zip(path, islice(path, 1, None)):
|
||||||
_, _, za = a
|
_, _, za = a
|
||||||
_, _, zb = b
|
_, _, zb = b
|
||||||
if za != zb:
|
if za != zb:
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
import os, sys, argparse, select
|
import os, sys, argparse, select
|
||||||
from ast import literal_eval
|
from ast import literal_eval
|
||||||
from itertools import izip, islice, chain
|
from itertools import zip, islice, chain
|
||||||
from mymath import *
|
from mymath import *
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
@ -21,7 +21,7 @@ def split_paths(paths):
|
||||||
new_paths = []
|
new_paths = []
|
||||||
for path in paths:
|
for path in paths:
|
||||||
new_path = []
|
new_path = []
|
||||||
for a, b in izip(path, islice(path, 1, None)):
|
for a, b in zip(path, islice(path, 1, None)):
|
||||||
_, _, za = a
|
_, _, za = a
|
||||||
_, _, zb = b
|
_, _, zb = b
|
||||||
if za != zb:
|
if za != zb:
|
||||||
|
|
Loading…
Reference in New Issue