I realized that I should declare I file that I am using from another project.
Contents of the file follow the break.
Here it is:
##
# Rectangle container with collision methods
#
# @author Henry Mclaughlin
#
# This is a generic rectangle container that has some
# collision methods, a couple of boolean methods, and
# properties for many points in itself.
#
# It has the following collision methods:
#
# \li Check overlap
# \li Clamp in
# \li Clamp off
#
# It has the following boolean methods:
#
# \li Union
# \li Intersection
#
# It has properties for the following points:
#
# \li Left, right, top, and bottom edges (single coordinate)
# \li Top-left, top-right, bottom-left, and bottom-right corners
# \li Left, right, top, and bottom edge mid-points
# \li Horizontal center and vertical center (single coordinate)
# \li Center point
# \li Width and height (individually)
# \li Size
#
# When a Rect's corners are modified, it moves without
# changing size.
#
# \note There are a \e lot of methods here that are not
# documented. This is because you are meant to
# use the properties, which \e are documented.
#
# \todo Implement clampIn()
# \todo Implement clampOff()
# \todo Implement boolean functions
# \todo Implement overlapList(), overlapAny(), and overlapAll()
#
class Rect(object):
##
# Constructor
#
# Params are complicated...
#
# \todo Document the parameters
# \todo Proper error messages
#
def __init__(self,x,y=None,w=None,h=None):
super(Rect,self).__init__()
if h != None and w != None:
self._left = float(x)
self._bottom = float(y)
self._width = float(w)
self._height = float(h)
elif y != None:
self._left, self._bottom = x
self._width,self._height = y
elif isinstance(x,Rect):
self._left = x.left
self._bottom = x.bottom
self._width = x.width
self._height = x.height
else:
x = tuple(x)
self._left,self._bottom,self._width,self._height = x
self._left = float(self._left)
self._bottom = float(self._bottom)
self._width = float(self._width)
self._height = float(self._height)
def getLeft(self):
return self._left
def setLeft(self,new_left):
self._left = float(new_left)
##
# The Rect's left edge (single coordinate)
left = property(
getLeft,
setLeft
)
def getRight(self):
return self._left + self._width
def setRight(self,new_right):
self._left = float(new_right) - self._width
##
# The Rect's right edge (single coordinate)
right = property(
getRight,
setRight
)
def getCenterX(self):
return self._left + (self._width / 2.0)
def setCenterX(self,new_centerx):
self._left = float(new_centerx) - (self._width / 2.0)
##
# The Rect's horizontal center (single coordinate)
centerx = property(
getCenterX,
setCenterX
)
def getBottom(self):
return self._bottom
def setBottom(self,new_bottom):
self._bottom = float(new_bottom)
##
# The Rect's bottom edge (single coordinate)
bottom = property(
getBottom,
setBottom
)
def getTop(self):
return self._bottom + self._width
def setTop(self,new_top):
self._bottom = float(new_top) - self._width
##
# The Rect's top edge (single coordinate)
top = property(
getTop,
setTop
)
def getCenterY(self):
return self._bottom + (self._width / 2.0)
def setCenterY(self,new_centery):
self._bottom = float(new_centery) - (self._width / 2.0)
##
# The Rect's vertical center (single coordinate)
centery = property(
getCenterY,
setCenterY
)
def getWidth(self):
return self._width
def setWidth(self,new_width):
self._width = float(new_width)
##
# The Rect's width
width = property(
getWidth,
setWidth
)
def getHeight(self):
return self._height
def setHeight(self,new_height):
self._height = float(new_height)
##
# The Rect's height
height = property(
getHeight,
setHeight
)
def getBottomLeft(self):
return (self.left,self.bottom)
def setBottomLeft(self,new_bottomleft):
self.left,self.bottom = tuple(new_bottomleft)
##
# The Rect's bottom-left corner
bottomleft = property(
getBottomLeft,
setBottomLeft
)
def getBottomRight(self):
return (self.right,self.bottom)
def setBottomRight(self,new_bottomright):
self.right,self.bottom = tuple(new_bottomright)
##
# The Rect's bottom-right corner
bottomright = property(
getBottomRight,
setBottomRight
)
def getTopLeft(self):
return (self.left,self.top)
def setTopLeft(self,new_topleft):
self.left,self.top = tuple(new_topleft)
##
# The Rect's top-left corner
topleft = property(
getTopLeft,
setTopLeft
)
def getTopRight(self):
return (self.right,self.top)
def setTopRight(self,new_topright):
self.right,self.top = tuple(new_topright)
##
# The Rect's top-right corner
topright = property(
getTopRight,
setTopRight
)
def getMidLeft(self):
return (self.left,self.centery)
def setMidLeft(self,new_midleft):
self.left,self.centery = tuple(new_midleft)
##
# The midpoint of the Rect's left edge
midleft = property(
getMidLeft,
setMidLeft
)
def getMidRight(self):
return (self.right,self.centery)
def setMidRight(self,new_midright):
self.right,self.centery = tuple(new_midright)
##
# The midpoint of the Rect's right edge
midright = property(
getMidRight,
setMidRight
)
def getMidBottom(self):
return (self.centerx,self.bottom)
def setMidBottom(self,new_midbottom):
self.centerx,self.bottom = tuple(new_midbottom)
##
# The midpoint of the Rect's bottom edge
midbottom = property(
getMidBottom,
setMidBottom
)
def getMidTop(self):
return (self.centerx,self.top)
def setMidTop(self,new_midtop):
self.centerx,self.top = tuple(new_midtop)
##
# The midpoint of the Rect's top edge
midtop = property(
getMidTop,
setMidTop
)
def getCenter(self):
return (self.centerx,self.centery)
def setCenter(self,new_center):
self.centerx,self.centery = tuple(new_center)
##
# The Rect's center point
center = property(
getCenter,
setCenter
)
def getSize(self):
return (self.width,self.height)
def setSize(self,new_size):
self.width,self.height = tuple(new_size)
##
# The Rect's size
size = property(
getSize,
setSize
)
##
# Check whether the caller overlaps another Rect
#
# @param other The Rect to check for an overlap with
#
# @return Whether the caller overlaps with \e other
#
# \note If \e other is not a Rect, then this method
# will attempt to construct a Rect using \e other
#
def overlap(self,other):
if not isinstance(other,Rect):
other = Rect(other)
coll_x, coll_y = True, True
coll_x = coll_x and self.left <= other.right
coll_x = coll_x and other.left <= self.right
coll_y = coll_y and self.bottom <= other.top
coll_y = coll_y and other.bottom <= self.top
return coll_x and coll_y