
import math

def distance((x1,y1),(x2,y2)):
    return math.sqrt((x2-x1) ** 2 + (y2-y1) ** 2)

# The World Database represents a collection of objects indexed by their position in the real plane

class WorldDatabase:
    
    def __init__(self):
        self.data = dict()

    def put(self, data):
        self.data.update(data)

    def search(self, position, search_range):
        return [(point,self.data[point]) for point in self.data if distance(position, point) <= search_range]



database = WorldDatabase()

# Initializes the database with a list of pairs (position, object) where each position is of the form (x,y)
def initialize_world_database(initial_data):
    database.put([((pos[0],pos[1]), obj) for [pos,obj] in initial_data])

# Returns a list of all the objects within a distance d of the given position (where position is of the form (x,y)
def query_world_database(position, d):
    return database.search(position, d)
