Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. class Point(object):
  2. def __init__(self, coords):
  3. self.x = coords[0]
  4. self.y = coords[1]
  5.  
  6. class Rectangle(object):
  7. def __init__(self):
  8. self.topRight = None
  9. self.topLeft = None
  10. self.bottomRight = None
  11. self.bottomLeft = None
  12.  
  13. def inside(self, point):
  14. if point.x > self.topLeft.x and point.x > self.bottomLeft.x:
  15. if point.x < self.topRight.x and point.x < self.bottomRight.x:
  16. if point.y > self.topLeft.y and point.y < self.bottomLeft.y:
  17. return True
  18.  
  19. return False
  20.  
  21. p1 = Point((0,0))
  22. p2 = Point((2,0))
  23. p3 = Point((0,2))
  24. p4 = Point((2,2))
  25.  
  26. testP1 = Point((1,1))
  27. testP2 = Point((3,3))
  28.  
  29. rect = Rectangle()
  30. rect.topLeft = p1
  31. rect.topRight = p2
  32. rect.bottomRight = p4
  33. rect.bottomLeft = p3
  34.  
  35. print(rect.inside(testP1))
  36.  
  37. print(rect.inside(testP2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement