Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point:
- """ Point class for representing and manipulating x,y coordinates. """
- def __init__(self, initX, initY):
- self.x = initX
- self.y = initY
- def getX(self):
- return self.x
- def getY(self):
- return self.y
- def __str__(self):
- return "x=" + str(self.x) + ", y=" + str(self.y)
- class Rectangle:
- def __init__(self, initP, initW, initH):
- self.widht = initW
- self.height = initH
- self.location = initP
- def __str__(self):
- return str(self.location) + ' w=' + str(self.widht) + ' h=' + str(self.height)
- def getWidht(self):
- return self.widht
- def getHeight(self):
- return self.height
- def perimeter(self):
- return 2 * self.widht + 2 * self.height
- def transpose(self):
- self.height, self.widht = self.widht, self.height
- def contains(self, other):
- return self.location.x <= other.x < self.location.x + self.widht and self.location.y <= other.y < self.location.y + self.height
- def diagonal(self):
- return (self.width ** 2 + self.height ** 2) ** 0.5
- def colides(rect2):
- if self.x < rect2.x + rect2.width \
- and self.x + rect1.width > rect2.x \
- and self.y < rect2.y + rect2.height \
- and self.y + self.height > rect2.y
- return True
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement