Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- def adjacent(self, pt1, pt2):
- return ((pt1.x == pt2.x and abs(pt1.y - pt2.y) == 1) or
- (pt1.y == pt2.y and abs(pt1.x - pt2.x) == 1))
- def distance_sq(self, p1, p2):
- return (p1.x - p2.x)**2 + (p1.y - p2.y)**2
- import point
- def find_nearest(world, pt, type):
- oftype = [(e, distance_sq(pt, entities.get_position(e)))
- for e in worldmodel.get_entities(world) if isinstance(e, type)]
- return nearest_entity(of type)
- AttributeError: 'module' object has no attribute 'distance_sq'
- class Point:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- @staticmethod
- def adjacent(pt1, pt2):
- return ((pt1.x == pt2.x and abs(pt1.y - pt2.y) == 1) or
- (pt1.y == pt2.y and abs(pt1.x - pt2.x) == 1))
- @staticmethod
- def distance_sq(p1, p2):
- return (p1.x - p2.x)**2 + (p1.y - p2.y)**2
- from point import Point
- ... Point.distance_sq(pt, entities.get_position(e))
- def adjacent(self, point):
- return (
- (self.x == point.x and abs(self.y - point.y) == 1) or
- (self.y == point.y and abs(self.x - point.x) == 1)
- )
- def distance_sq(self, point):
- return (self.x - point.x)**2 + (self.y - point.y)**2
- pt.distance_sq(entities.get_position(e))
- class Point:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- def adjacent(self, pt1, pt2):
- return ((pt1.x == pt2.x and abs(pt1.y - pt2.y) == 1) or
- (pt1.y == pt2.y and abs(pt1.x - pt2.x) == 1))
- def distance_sq(p1, p2):
- return (p1.x - p2.x)**2 + (p1.y - p2.y)**2
- import point
- point.distance_sq(point1, point2)
- class Point:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- def adjacent(self, pt1, pt2):
- return ((pt1.x == pt2.x and abs(pt1.y - pt2.y) == 1) or
- (pt1.y == pt2.y and abs(pt1.x - pt2.x) == 1))
- @classmethod
- def distance_sq(cls, p1, p2):
- return (p1.x - p2.x)**2 + (p1.y - p2.y)**2
- import point
- point.Point.distance_sq(point1, point2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement