Exemple #1
0
    if args['--plot']:
      directions = ('N', 'E', 'S', 'W')
      for index, side in enumerate(piece.sides):
        length = piece.side_lengths[index]
        side_type = piece.side_types[index]
        x, y = piece.mean_side_points[index]
        label = '%s: %0.0f (%s)' % (directions[index], length, side_type)
        ax1.text(x, y, label, horizontalalignment='center',
                 verticalalignment='center')
    piece_data['side_types'] = piece.side_types
  except:
    print 'could not find side types for "%s"' % filepath

  # Define the bounding box around each non-flat side.
  try:
    piece.find_bounding_boxes()
    if args['--plot']:
      colors = ('r', 'g', 'b', 'cyan')
      for index, bbox in enumerate(piece.bounding_boxes):
        if not bbox:
          # Flat sides will not have a defined bounding box.
          continue
        ax1.plot(
          [bbox[0][0], bbox[1][0], bbox[1][0], bbox[0][0], bbox[0][0]],
          [bbox[0][1], bbox[0][1], bbox[1][1], bbox[1][1], bbox[0][1]],
          color=colors[index], linestyle='--')
  except:
    print 'could not find bounding boxes for "%s"' % filepath

  # Save the figure.
  filename = os.path.basename(filepath)