changeset 65:16bd13cd58bc

add bounding box functions
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 12:46:20 -0800
parents 2adeb95cf4d5
children 9f1324a59cc1
files tvii/bb.py
diffstat 1 files changed, 41 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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()