Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
from __future__ import division
from collections import namedtuple
Coordinate = namedtuple("Coordinate", ["X", "Y", "Z"])
def elementWiseAdd(coord1, coord2): return Coordinate(coord1[0]+coord2[0], coord1[1]+coord2[1], coord1[2]+coord2[2])
def elementWiseSub(coord1, coord2): return Coordinate(coord1[0]-coord2[0], coord1[1]-coord2[1], coord1[2]-coord2[2])
def elementWiseDiv(coord, scale): return Coordinate(coord[0]/scale, coord[1]/scale, coord[2]/scale)
Coordinate.__add__ = elementWiseAdd
Coordinate.__sub__ = elementWiseSub
Coordinate.__div__ = elementWiseDiv
class BoundingBox(object):
def __init__(self, boundingStartPoint, boundingEndPoint, resolution):
self.resolution = resolution
self.startPoint = boundingStartPoint
self.endPoint = boundingEndPoint
dx = boundingEndPoint.X - boundingStartPoint.X
dy = boundingEndPoint.Y - boundingStartPoint.Y
dz = boundingEndPoint.Z - boundingStartPoint.Z
stepsX = int(abs(dx/resolution) + 1)
stepsY = int(abs(dy/resolution) + 1)
stepsZ = int(abs(dz/resolution) + 1)
self.visitedTable = [[[False] * stepsZ] * stepsY] * stepsX
def __coordToIndices(self, coordinate):
delta = coordinate - self.startPoint
import ipdb; ipdb.set_trace()
stepCount = delta + delta
stepCount = delta/self.resolution
#Seems silly but we're not returning a Coordinate so I'm "un-typing" it
return (stepCount[0], stepCount[1], stepCount[2])
def haveVisited(self,coordinate):
ind = self.__coordToIndices(coordinate)
return self.visitedTable[ind[0]][ind[1]][ind[2]]
if __name__ == "__main__":
foo = BoundingBox(Coordinate(0,0,0), Coordinate(1,1,0.5), 0.5)
print foo.haveVisited(Coordinate(0,1,0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment