# HG changeset patch # User Jeff Hammel # Date 1513543580 28800 # Node ID 16bd13cd58bc63e295ea9f181d53f79da857739f # Parent 2adeb95cf4d593160db6a980d813d6c3d995ed3b add bounding box functions diff -r 2adeb95cf4d5 -r 16bd13cd58bc tvii/bb.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tvii/bb.py Sun Dec 17 12:46:20 2017 -0800 @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +bounding box +""" + +import argparse +import sys +from .transpose import transpose + +def bounding_box(*points): + + return [(min(col), max(col)) + for col in transpose(points)] + + +def overlap(bb1, bb2): + """determines if two bounding boxes overlap""" + # Note: this concludes they are linearly separably, + # but the converse is not true + + for (min1, max1), (min2, max2) in zip(bb1, bb2): + if min1 <= min2 <= max1: + continue + if min2 <= max1 <= max2: + continue + return False + return True + # TODO: this currently returns True and False; + # it would be much more useful to return the intersection + +def main(args=sys.argv[1:]): + """CLI""" + + # parse command line + parser = argparse.ArgumentParser(description=__doc__) + options = parser.parse_args(args) + +if __name__ == '__main__': + main()