refactor load/save functions
Use streams instead of filename. Move load/write functions if modules where logical.
This commit is contained in:
parent
6bdab7d667
commit
c37cce25ed
5 changed files with 160 additions and 130 deletions
14
voronoi.py
14
voronoi.py
|
|
@ -4,6 +4,7 @@
|
|||
from utils import tour,LOG,LOGN,x,y
|
||||
import triangulation
|
||||
import geometry
|
||||
import graph
|
||||
|
||||
def nodes( triangles ):
|
||||
"""Compute the locations of the centers of all the circumscribed circles of the given triangles"""
|
||||
|
|
@ -68,17 +69,6 @@ def dual( triangles ):
|
|||
return graph
|
||||
|
||||
|
||||
def edges_of( graph ):
|
||||
# edges = set()
|
||||
edges = []
|
||||
for k in graph:
|
||||
for n in graph[k]:
|
||||
if k != n and (k,n) not in edges and (n,k) not in edges:
|
||||
# edges.add( (k,n) )
|
||||
edges.append( (k,n) )
|
||||
return edges
|
||||
|
||||
|
||||
def merge_nodes( graph, n0, n1, n2 ):
|
||||
"""Merge n0 and n1 nodes as n2 within the given graph."""
|
||||
|
||||
|
|
@ -179,7 +169,7 @@ if __name__ == "__main__":
|
|||
delaunay_edges = triangulation.edges_of( triangles )
|
||||
|
||||
voronoi_graph = dual( triangles )
|
||||
voronoi_edges = edges_of( voronoi_graph )
|
||||
voronoi_edges = graph.edges_of( voronoi_graph )
|
||||
print voronoi_edges
|
||||
|
||||
ax = fig.add_subplot(111)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue