def flip(self): """ flip the Cycle """ self.cycle = self.cycle[::-1] self.vertices = self.vertices[::-1] self.edges = self.edges[::-1] self.p = self.p[:, ::-1] self.area = geu.SignedArea(self.p)
def update(self): """ update """ self.size = len(self.cycle) self.vertices = self.cycle[np.nonzero(np.array(self.cycle) < 0)[0]] self.edges = self.cycle[np.nonzero(np.array(self.cycle) > 0)[0]] self.Nv = len(self.vertices) self.Ne = len(self.edges) for v in self.vertices: try: pt = np.array(self.G.pos[v]).reshape(2, 1) except: pdb.set_trace() try: self.p = np.hstack((self.p, pt)) except: self.p = pt self.area = geu.SignedArea(self.p) self.g = geu.Centroid(self.p)
def __init__(self, G, cycle): # This is to obtained an ordered cycle self.G = G.subgraph(cycle) cycle = nx.algorithms.cycles.cycle_basis(self.G)[0] self.G = G.subgraph(cycle) self.G.pos = {} for c in cycle: self.G.pos[c] = G.pos[c] self.cycle = np.array(cycle) self.size = len(self.cycle) self.vertices = self.cycle[np.nonzero(np.array(self.cycle) < 0)[0]] self.edges = self.cycle[np.nonzero(np.array(self.cycle) > 0)[0]] self.Nv = len(self.vertices) self.Ne = len(self.edges) self.p = np.array([]) for v in self.vertices: try: self.p = np.hstack( (self.p, np.array(self.G.pos[v]).reshape(2, 1))) except: self.p = np.array(self.G.pos[v]).reshape(2, 1) self.area = geu.SignedArea(self.p) self.g = geu.Centroid(self.p)