def analyze(self): """Performs contiguous area expansion and discovery in the layers.""" for layer in self.layers: plotter = AreaPlotter(layer.grid, self.build_config) plotter.expand_fixed_size_areas() # plot cells of d(5x5) format plotter.discover_areas() # find contiguous areas layer.grid = plotter.grid # update
def trace_outline(self): """ Moves the cursor to the northwest corner, then clockwise to each other corner, before returning to the starting position. """ buildconfig = BuildConfig('dig') grid = self.layers[0].grid plotter = AreaPlotter(grid, buildconfig) plotter.expand_fixed_size_areas() # plot cells of d(5x5) format ks = Keystroker(grid, buildconfig) keys = [] # move to each corner beginning with NW, going clockwise, and wait # at each one lastpos = self.start for cornerdir in [ Direction(d) for d in ['nw', 'ne', 'se', 'sw', 'nw'] ]: (x, y) = cornerdir.delta() newpos = (max(0, x) * (grid.width - 1), max(0, y) * (grid.height - 1)) keys += ks.move(lastpos, newpos, allowjumps=False) + ['%'] lastpos = newpos keys += ks.move(lastpos, self.start, allowjumps=False) # trim any pauses off the ends while keys and keys[0] == '%': keys = keys[1:] while keys and keys[-1] == '%': keys = keys[:-1] # if the result is no keys, return a single wait key keys += ['%'] return keys