Advertisement
AdrianMadajewski

python lab

Nov 27th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. class Point:
  2.     """ Point class for representing and manipulating x,y coordinates. """
  3.  
  4.     def __init__(self, initX, initY):
  5.  
  6.         self.x = initX
  7.         self.y = initY
  8.  
  9.     def getX(self):
  10.         return self.x
  11.  
  12.     def getY(self):
  13.         return self.y
  14.  
  15.     def __str__(self):
  16.         return "x=" + str(self.x) + ", y=" + str(self.y)
  17.  
  18.    
  19. class Rectangle:
  20.    
  21.     def __init__(self, initP, initW, initH):
  22.         self.widht = initW
  23.         self.height = initH
  24.         self.location = initP
  25.  
  26.     def __str__(self):
  27.         return str(self.location) + ' w=' + str(self.widht) + ' h=' + str(self.height)
  28.    
  29.     def getWidht(self):
  30.         return self.widht
  31.    
  32.     def getHeight(self):
  33.         return self.height
  34.    
  35.     def perimeter(self):
  36.         return 2 * self.widht + 2 * self.height
  37.    
  38.     def transpose(self):
  39.         self.height, self.widht = self.widht, self.height
  40.  
  41.     def contains(self, other):
  42.         return self.location.x <= other.x < self.location.x + self.widht and self.location.y <= other.y < self.location.y + self.height
  43.  
  44.     def diagonal(self):
  45.         return (self.width ** 2 + self.height ** 2) ** 0.5
  46.    
  47.     def colides(rect2):
  48.         if self.x < rect2.x + rect2.width \
  49.            and self.x + rect1.width > rect2.x \
  50.            and self.y < rect2.y + rect2.height \
  51.            and self.y + self.height > rect2.y
  52.             return True
  53.        
  54.         return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement