"""
Utility classes and funcitons for template matching framework.
"""

import dem
import numpy as np


class BoundingBox(object):

    def __init__(self, lr, ul):

        self.lrx = lr[0]
        self.lry = lr[1]
        self.lr = lr

        self.ulx = ul[0]
        self.uly = ul[1]
        self.ul = ul

        self.llx = ul[0]
        self.lly = lr[1]
        self.ll = (self.llx, self.lly)

        self.urx = lr[0]
        self.ury = ul[1]
        self.ur = (self.urx, self.ury)

        self.corners = [self.ul, self.ll, self.ur, self.lr] 

    def contains(self, point):

        intersect_x = point[0] >= self.ulx and point[0] <= self.lrx
        intersect_y = point[1] >= self.lry and point[1] <= self.uly

        return intersect_x and intersect_y

    def intersects(self, bbox):
        
        for corner in bbox.corners:
            if self.contains(corner):
                return True

        for corner in self.corners:
            if bbox.contains(corner):
                return True

        return False

    def intersection(self, bbox):
        pass
       # if not self.intersects(bbox):
       #     raise ValueError("Bounding boxes do not intersect")

       # interior_points = []
       # for corner in bbox.corners:
       #     if self.contains(corner):
       #         interior_points.append(corner)
       # 
       # if len(interior_points) == 1:
       #     dists = [np.linalg.norm(interior_points[0] - x) for x in self.corners]
       #     idx = np.where(dists == np.min(dists))
       #     interior_points.append(self.corners[idx])

       # return BoundingBox(new_lr, new_ul)


@@ -1030,596 +1030,4 @@
 se%0A%0A
-    def intersection(self, bbox):%0A        pass%0A       # if not self.intersects(bbox):%0A       #     raise ValueError(%22Bounding boxes do not intersect%22)%0A%0A       # interior_points = %5B%5D%0A       # for corner in bbox.corners:%0A       #     if self.contains(corner):%0A       #         interior_points.append(corner)%0A       # %0A       # if len(interior_points) == 1:%0A       #     dists = %5Bnp.linalg.norm(interior_points%5B0%5D - x) for x in self.corners%5D%0A       #     idx = np.where(dists == np.min(dists))%0A       #     interior_points.append(self.corners%5Bidx%5D)%0A%0A       # return BoundingBox(new_lr, new_ul)%0A%0A

Delete unused intersection method