Created
September 10, 2012 13:46
-
-
Save masci/3691024 to your computer and use it in GitHub Desktop.
Bounding Box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Point = namedtuple('Point', 'x, y, z') | |
class BoundingBox(object): | |
def __init__(self,bottom,top): | |
self.top = Point._make(top) | |
self.bot = Point._make(bottom) | |
def _point_contained(self, other_point): | |
over_bot = all(map(lambda x: x[0]<=x[1], zip(self.bot,other_point))) | |
under_top = all(map(lambda x: x[0]>=x[1], zip(self.top,other_point))) | |
return over_bot and under_top | |
def contains(self, other): | |
return self._point_contained(other.bot) and \ | |
self._point_contained(other.top) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment