Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. class Point:
  2. def __init__(self, x, y):
  3. self.x = x
  4. self.y = y
  5.  
  6. def adjacent(self, pt1, pt2):
  7. return ((pt1.x == pt2.x and abs(pt1.y - pt2.y) == 1) or
  8. (pt1.y == pt2.y and abs(pt1.x - pt2.x) == 1))
  9.  
  10. def distance_sq(self, p1, p2):
  11. return (p1.x - p2.x)**2 + (p1.y - p2.y)**2
  12.  
  13. import point
  14.  
  15. def find_nearest(world, pt, type):
  16. oftype = [(e, distance_sq(pt, entities.get_position(e)))
  17. for e in worldmodel.get_entities(world) if isinstance(e, type)]
  18.  
  19. return nearest_entity(of type)
  20.  
  21. AttributeError: 'module' object has no attribute 'distance_sq'
  22.  
  23. class Point:
  24. def __init__(self, x, y):
  25. self.x = x
  26. self.y = y
  27.  
  28. @staticmethod
  29. def adjacent(pt1, pt2):
  30. return ((pt1.x == pt2.x and abs(pt1.y - pt2.y) == 1) or
  31. (pt1.y == pt2.y and abs(pt1.x - pt2.x) == 1))
  32.  
  33. @staticmethod
  34. def distance_sq(p1, p2):
  35. return (p1.x - p2.x)**2 + (p1.y - p2.y)**2
  36.  
  37. from point import Point
  38.  
  39. ... Point.distance_sq(pt, entities.get_position(e))
  40.  
  41. def adjacent(self, point):
  42. return (
  43. (self.x == point.x and abs(self.y - point.y) == 1) or
  44. (self.y == point.y and abs(self.x - point.x) == 1)
  45. )
  46.  
  47. def distance_sq(self, point):
  48. return (self.x - point.x)**2 + (self.y - point.y)**2
  49.  
  50. pt.distance_sq(entities.get_position(e))
  51.  
  52. class Point:
  53. def __init__(self, x, y):
  54. self.x = x
  55. self.y = y
  56.  
  57. def adjacent(self, pt1, pt2):
  58. return ((pt1.x == pt2.x and abs(pt1.y - pt2.y) == 1) or
  59. (pt1.y == pt2.y and abs(pt1.x - pt2.x) == 1))
  60.  
  61. def distance_sq(p1, p2):
  62. return (p1.x - p2.x)**2 + (p1.y - p2.y)**2
  63.  
  64. import point
  65. point.distance_sq(point1, point2)
  66.  
  67. class Point:
  68. def __init__(self, x, y):
  69. self.x = x
  70. self.y = y
  71.  
  72. def adjacent(self, pt1, pt2):
  73. return ((pt1.x == pt2.x and abs(pt1.y - pt2.y) == 1) or
  74. (pt1.y == pt2.y and abs(pt1.x - pt2.x) == 1))
  75.  
  76. @classmethod
  77. def distance_sq(cls, p1, p2):
  78. return (p1.x - p2.x)**2 + (p1.y - p2.y)**2
  79.  
  80. import point
  81. point.Point.distance_sq(point1, point2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement