def main(args): checkfile(args.targetfile) checkfile(args.stickyfile) target_list = load_rect_from_path(args.targetfile) sticky_list = load_rect_from_path(args.stickyfile) for rect in target_list: y0 = rect.y y1 = rect.y + rect.height top = y0 - 10 bottom = y1 + 10 for sticky_rect in sticky_list: intersect = rect.intersect(sticky_rect) if intersect.width > 0 and intersect.height > 0: if abs(sticky_rect.y - y0) < abs(top - y0): top = sticky_rect.y if abs((sticky_rect.y + sticky_rect.height) - y1) < abs(bottom - y1): bottom = sticky_rect.y + sticky_rect.height if abs(top - y0) < 10: y0 = top if abs(bottom - y1) < 10: y1 = bottom rect.y = y0 rect.height = y1 - y0 print rect
def main(argv): if len(argv) > 0: checkfile(argv[0]) rects = load_rect_from_path(argv[0]) else: rects = load_rect_from_file(sys.stdin) print rect_area(rects)
def main(args): checkfile(args.file0); checkfile(args.file1); rect_list_one = load_rect_from_path(args.file0) rect_list_second = load_rect_from_path(args.file1) intersections = [] for rect1 in rect_list_one: for rect2 in rect_list_second: rect = rect1.intersect(rect2) if rect.width > 0 and rect.height > 0: intersections.append(rect) if args.print_area: print('%d %d %d' % (rect_area(rect_list_one), rect_area(rect_list_second), rect_area(intersections))) else: for i in intersections: print i