def calc_nets(self, segments): """ Return a set of Nets from segments """ points = {} # (x,y) -> NetPoint def get_point(p): if p not in points: points[p] = NetPoint("%da%d" % p, *p) return points[p] # turn the (x, y) points into unique NetPoint objects segments = set((get_point(p1), get_point(p2)) for p1, p2 in segments) nets = [] # Iterate over the segments, removing segments when added to a net while segments: seg = segments.pop() # pick a point newnet = Net("") newnet.connect(seg) found = True while found: found = set() for seg in segments: # iterate over segments if newnet.connected(seg): # segment touching the net newnet.connect(seg) # add the segment found.add(seg) for seg in found: segments.remove(seg) nets.append(newnet) return nets
def calc_nets(self, segments): """ Return a set of Nets from segments """ points = {} # (x,y) -> NetPoint def get_point(p): if p not in points: points[p] = NetPoint('%da%d' % p, *p) return points[p] # turn the (x, y) points into unique NetPoint objects segments = set((get_point(p1), get_point(p2)) for p1, p2 in segments) nets = [] # Iterate over the segments, removing segments when added to a net while segments: seg = segments.pop() # pick a point newnet = Net('') newnet.connect(seg) found = True while found: found = set() for seg in segments: # iterate over segments if newnet.connected(seg): # segment touching the net newnet.connect(seg) # add the segment found.add(seg) for seg in found: segments.remove(seg) nets.append(newnet) return nets
def calc_nets(self, segments): """ Return a set of Nets from segments """ points = {} # (x, y) -> NetPoint def get_point(point): """ Return a new or existing NetPoint for an (x,y) point """ point = (make_length(point[0]), make_length(point[1])) if point not in points: points[point] = NetPoint('%da%d' % point, point[0], point[1]) return points[point] # turn the (x, y) points into unique NetPoint objects segments = set((get_point(p1), get_point(p2)) for p1, p2 in segments) nets = [] # Iterate over the segments, removing segments when added to a net while segments: seg = segments.pop() # pick a point newnet = Net('') newnet.connect(seg) found = True while found: found = set() for seg in segments: # iterate over segments if newnet.connected(seg): # segment touching the net newnet.connect(seg) # add the segment found.add(seg) for seg in found: segments.remove(seg) nets.append(newnet) return nets