def inVisualRange(self, enemy): if utils.isInside(self.character.rect.center[0], self.character.rect.center[1], self.character.visual_rad, enemy.rect.center[0], enemy.rect.center[1]): return True return False
def find(location, bounds, data, allData, name=None): more = True token = None while (more): #print('search...') if (not token): if (name): psn = gmaps.places_nearby(location=location, rank_by='distance', keyword=name) else: psn = gmaps.places_nearby(location=location, rank_by='distance', type='supermarket') else: #print('token = ' + token) psn = gmaps.places_nearby(location=location, page_token=token) with open('psn.yml', 'w') as yaml_file: dump(psn, yaml_file, default_flow_style=False, Dumper=Dumper) #print('psn:') #print(dump(psn, default_flow_style=False, Dumper=Dumper)) #print('saving token') for p in psn['results']: if (not utils.isInside(p['geometry']['location'], bounds)): # Not in the bounding box #print('this one is not inside:') #print(dump(p, default_flow_style=False, Dumper=Dumper)) more = False break if (data.get(p['place_id'])): # Already found this one continue dist = utils.distance((p['geometry']['location']['lat'], p['geometry']['location']['lng']), (location['lat'], location['lng'])) gRec = { 'name': p['name'], 'vicinity': p['vicinity'], 'location': p['geometry']['location'], 'distance': dist } data[p['place_id']] = gRec p['distance'] = dist allData.append(p) token = psn.get('next_page_token') print('more = ' + str(more)) print('token = ' + str(token)) if (not token): # finished more = False break time.sleep(2) # next_page_token not immediately ready server-side
def evaluate(loc, data, value): if (not utils.isInside({'lat': loc[0], 'lng': loc[1]}, data['bounds'])): print('ERROR: evaluation point outside of safety grid bounds') sys.exit(1) y_dist_start = loc[0] - data['startgrid']['lat'] x_dist_start = loc[1] - data['startgrid']['lng'] row = int(y_dist_start // data['lenstep']['y']) col = int(x_dist_start // data['lenstep']['x']) score = data['grid'][row][col] return utils.evaluate_function(value['function'], score)
def triangulate_CPU(triangles, coords): trs = [] trs.append(triangles[0]) for i in range(len(coords)): p = coords[i] for t in trs: if utils.isInside(p, t): ccwCoords = utils.orderVertices([p, t.v1, t.v2]) tn1 = Triangle(ccwCoords[0], ccwCoords[1], ccwCoords[2]) ccwCoords = utils.orderVertices([p, t.v2, t.v3]) tn2 = Triangle(ccwCoords[0], ccwCoords[1], ccwCoords[2]) ccwCoords = utils.orderVertices([p, t.v3, t.v1]) tn3 = Triangle(ccwCoords[0], ccwCoords[1], ccwCoords[2]) trs.append(tn1) trs.append(tn2) trs.append(tn3) trs.remove(t) break return trs
def chasing(self, enemy): enemyX = enemy.rect.center[0] enemyY = enemy.rect.center[1] actualX = self.character.rect.center[0] actualY = self.character.rect.center[1] if utils.isInside(actualX, actualY, self.character.attack_rad, enemyX, enemyY): self.stopMoving() self.chasingState = False self.attackingState = True return else: self.chasingState = True self.attackingState = False print('chasing') if actualX < enemyX - enemy.velocity: self.character.moveRight = True else: self.character.moveRight = False if actualX > enemyX + enemy.velocity: self.character.moveLeft = True else: self.character.moveLeft = False if actualY < enemyY - enemy.velocity: self.character.moveDown = True else: self.character.moveDown = False if actualY > enemyY + enemy.velocity: self.character.moveUp = True else: self.character.moveUp = False
def test_isInside(self): polygon1 = [[0, 0], [10, 0], [10, 10], [0, 10]] n = len(polygon1) p = [20, 20] self.assertTrue(isInside(polygon1, n, p) is False) p = [5, 5] self.assertTrue(isInside(polygon1, n, p) is True) polygon2 = [[0, 0], [5, 5], [5, 0]] p = [3, 3] n = len(polygon2) self.assertTrue(isInside(polygon2, n, p) is True) p = [5, 1] self.assertTrue(isInside(polygon2, n, p) is True) p = [8, 1] self.assertTrue(isInside(polygon2, n, p) is False) polygon3 = [[0, 0], [10, 0], [10, 10], [0, 10]] p = [-1, 10] n = len(polygon3) self.assertTrue(isInside(polygon3, n, p) is False)
#fname = "Lab-1-2019-Dannye.txt" hull0 = utils.graham_scan(list(pts0),False) hull1 = utils.graham_scan(list(pts1),False) #plot_both(pts0, pts1, hull0, hull1) intersection_hull = utils.get_intersection_of_hulls(hull0, hull1) allpts = np.append(pts0, pts1, axis = 0) inside_points = [] outside_pts = [] for p in allpts: if utils.isInside(p, intersection_hull): inside_points.append(p) else: outside_pts.append(p) inside_points = np.array(inside_points) outside_pts = np.array(outside_pts) f = open("output.txt", "w+") f.write("Convex hull 0:\n") for i in hull0: f.write(str(i[0])+' '+str(i[1])+ '\n') f.write("Convex hull 1:\n") for i in hull1: f.write(str(i[0])+' '+str(i[1])+ '\n') f.write("Points inside the intersectio:\n")