Пример #1
0
def check_cluster(spawnpoint, cluster, radius, time_threshold):
    # discard infinite cost or too far away
    if cost(spawnpoint, cluster, time_threshold) > 2 * radius:
        return False

    new_centroid = cluster.simulate_centroid(spawnpoint)

    # we'd be removing ourselves
    if clsmath.distance(spawnpoint.position, new_centroid) > radius:
        return False

    # we'd be removing x
    if any(clsmath.distance(x.position, new_centroid) > radius for x in cluster):
        return False

    return True
Пример #2
0
def cost(spawnpoint, cluster, time_threshold):
    distance = clsmath.distance(spawnpoint.position, cluster.centroid)

    min_time = min(cluster.min_time, spawnpoint.time)
    max_time = max(cluster.max_time, spawnpoint.time)

    if max_time - min_time > time_threshold:
        return float('inf')

    return distance
Пример #3
0
def test(cluster, radius, time_threshold):
    assert cluster.max_time - cluster.min_time <= time_threshold

    for p in cluster:
        assert clsmath.distance(p.position, cluster.centroid) <= radius
        assert cluster.min_time <= p.time <= cluster.max_time