def parseEdgeArrayIntoTree(nodes, array): root = TriangleNode(nodes[0]).makeRoot() stack = [root] copy = array[:] while stack: parent = stack.pop(0) index = parent.node.index for i, e in enumerate(copy[:]): child = None if e[0] == index: child = TriangleNode(nodes[e[1]]) copy.remove(e) elif e[1] == index: child = TriangleNode(nodes[e[0]]) copy.remove(e) if child == None: continue edges = [] for v1 in parent.node.getVertices(): for v2 in child.node.getVertices(): if vertex_close_enough(v1, v2): edges.append(v1) assert (len(edges) == 2) parent.addChild(child, edges) stack.append(child) return root
def parseEdgeArrayIntoTree(nodes, array): root = TriangleNode(nodes[0]).makeRoot() stack = [root] copy = array[:] while stack: parent = stack.pop(0) index = parent.node.index for i,e in enumerate(copy[:]): child = None if e[0] == index: child = TriangleNode(nodes[e[1]]) copy.remove(e) elif e[1] == index: child = TriangleNode(nodes[e[0]]) copy.remove(e) if child == None: continue edges = [] for v1 in parent.node.getVertices(): for v2 in child.node.getVertices(): if vertex_close_enough(v1,v2): edges.append(v1) assert(len(edges)==2) parent.addChild(child,edges) stack.append(child) return root
def parseArrayIntoTree(nodes, array): root = TriangleNode(nodes[array.index(-1)]).makeRoot() stack = [root] while stack: parent = stack.pop(0) idxs = [i for i, x in enumerate(array) if x == parent.node.index] children = [TriangleNode(nodes[i]) for i in idxs] for child in children: edges = [] for v1 in parent.node.getVertices(): for v2 in child.node.getVertices(): if vertex_close_enough(v1, v2): edges.append(v1) assert (len(edges) == 2) parent.addChild(child, edges) stack.extend(children) return root
def parseArrayIntoTree(nodes, array): root = TriangleNode(nodes[array.index(-1)]).makeRoot() stack = [root] while stack: parent = stack.pop(0) idxs = [i for i,x in enumerate(array) if x == parent.node.index] children = [ TriangleNode(nodes[i]) for i in idxs] for child in children: edges = [] for v1 in parent.node.getVertices(): for v2 in child.node.getVertices(): if vertex_close_enough(v1,v2): edges.append(v1) assert(len(edges)==2) parent.addChild(child,edges) stack.extend(children) return root