65
|
1 #!/usr/bin/env python
|
|
2 # -*- coding: utf-8 -*-
|
|
3
|
|
4 """
|
|
5 bounding box
|
|
6 """
|
|
7
|
|
8 import argparse
|
|
9 import sys
|
|
10 from .transpose import transpose
|
|
11
|
|
12 def bounding_box(*points):
|
|
13
|
|
14 return [(min(col), max(col))
|
|
15 for col in transpose(points)]
|
|
16
|
|
17
|
|
18 def overlap(bb1, bb2):
|
|
19 """determines if two bounding boxes overlap"""
|
|
20 # Note: this concludes they are linearly separably,
|
|
21 # but the converse is not true
|
|
22
|
|
23 for (min1, max1), (min2, max2) in zip(bb1, bb2):
|
|
24 if min1 <= min2 <= max1:
|
|
25 continue
|
|
26 if min2 <= max1 <= max2:
|
|
27 continue
|
|
28 return False
|
|
29 return True
|
|
30 # TODO: this currently returns True and False;
|
|
31 # it would be much more useful to return the intersection
|
|
32
|
|
33 def main(args=sys.argv[1:]):
|
|
34 """CLI"""
|
|
35
|
|
36 # parse command line
|
|
37 parser = argparse.ArgumentParser(description=__doc__)
|
|
38 options = parser.parse_args(args)
|
|
39
|
|
40 if __name__ == '__main__':
|
|
41 main()
|