<commit_before>import random


class City(object):
    __slots__ = ["buildings", "road_mesh", "spawn_points", "meshes", "materials"]

    def __init__(self):
        self.buildings = []
        self.meshes = []
        self.materials = []
        self.spawn_points = []
        self.road_mesh = None


class Building(object):
    __slots__ = ["position", "mesh"]

    def __init__(self, position, mesh):
        self.position = position
        self.mesh = mesh


class Mesh(object):
    __slots__ = ["vertices", "faces", "material"]

    def __init__(self, vertices, faces, material=None):
        self.vertices = vertices
        self.faces = faces
        self.material = material


class Vertex(object):
    __slots__ = ["position", "normal"]

    def __init__(self, position=(0.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0)):
        self.position = position
        self.normal = normal


class CityGen(object):
    def __init__(self):
        self.city = City()

    def generate(self):
        self.city = gen_city()

    def dump_obj(self, path, name):
        write_obj(self.city, path, name)


def create_lots(lot, block):
    width = lot[2] - lot[0]
    height = lot[3] - lot[1]
    if width < 30 or height < 30:
        if lot[0] == block[0] or lot[1] == block[1] or lot[2] == block[2] or lot[3] == block[3]:
            return [lot]
        return []

    ret = []

    if width > height:
        new_width = width * random.uniform(0.3, 0.7)
        ret += create_lots((lot[0], lot[1], lot[0]+new_width, lot[3]), block)
        ret += create_lots((lot[0]+new_width, lot[1], lot[2], lot[3]), block)
        return ret

    new_height = height * random.uniform(0.3, 0.7)
    ret += create_lots((lot[0], lot[1], lot[2], lot[1]+new_height), block)
    ret += create_lots((lot[0], lot[1]+new_height, lot[2], lot[3]), block)
    return ret


def gen_city(city_width=500, city_height=500, lane_width=6, block_width=80, block_height=80, block_var=0.25):
    city = City()
    x_off = city_width / 2.0
    y_off = city_height / 2.0

    # Roads
    vert_roads = []
    vert_progress = 0
    while True:
        variance = random.random() * block_var * block_width
        progress = block_width + variance
        if vert_progress + progress > city_width:
            break
        vert_progress += progress
        vert_roads.append(vert_progress)

    hor_roads = []
    hor_progress = 0
    while True:
        variance = random.random() * block_var * block_height
        progress = block_height + variance
        if hor_progress + progress > city_height:
            break
        hor_progress += progress
        hor_roads.append(hor_progress)

    x_offset = (city_width - hor_progress) / 2.0
    y_offset = (city_height - vert_progress) / 2.0

    # Blocks
    blocks = []
    road_verts = []
    road_faces = []
    for i in range(len(vert_roads)):
        x1 = 0.0 if i == 0 else vert_roads[i-1] + lane_width
        x1 += x_offset
        x2 = vert_roads[i] - lane_width
        x2 += x_offset
        for j in range(len(hor_roads)):
            y1 = 0.0 if j == 0 else hor_roads[j-1] + lane_width
            y1 += y_offset
            y2 = hor_roads[j] - lane_width
            y2 += y_offset

            blocks.append((x1, y1, x2, y2))

            if i != len(vert_roads)-1 and j != len(hor_roads)-1:
                city.spawn_points.append((vert_roads[i] - x_off, hor_roads[j] - y_off, 0.0))
                verts = []
                normal = (0, 0, 1)
                x3 = vert_roads[i] + lane_width + x_offset
                y3 = hor_roads[j] + lane_width + y_offset
                vert_off = len(road_verts)
                road_verts.append(Vertex((x2 - x_off, y2 - y_off, 0.0), normal))
                road_verts.append(Vertex((x3 - x_off, y2 - y_off, 0.0), normal))
                road_verts.append(Vertex((x3 - x_off, y3 - y_off, 0.0), normal))
                road_verts.append(Vertex((x2 - x_off, y3 - y_off, 0.0), normal))
                road_faces.append((vert_off + 0, vert_off + 1, vert_off + 2))
                road_faces.append((vert_off + 2, vert_off + 3, vert_off + 0))
                if j > 0:
                    road_faces.append((vert_off-1, vert_off-2, vert_off+1))<commit_msg>Spawn Points: Fixing the spawn points so they are on the streets<commit_after>import random


class City(object):
    __slots__ = ["buildings", "road_mesh", "spawn_points", "meshes", "materials"]

    def __init__(self):
        self.buildings = []
        self.meshes = []
        self.materials = []
        self.spawn_points = []
        self.road_mesh = None


class Building(object):
    __slots__ = ["position", "mesh"]

    def __init__(self, position, mesh):
        self.position = position
        self.mesh = mesh


class Mesh(object):
    __slots__ = ["vertices", "faces", "material"]

    def __init__(self, vertices, faces, material=None):
        self.vertices = vertices
        self.faces = faces
        self.material = material


class Vertex(object):
    __slots__ = ["position", "normal"]

    def __init__(self, position=(0.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0)):
        self.position = position
        self.normal = normal


class CityGen(object):
    def __init__(self):
        self.city = City()

    def generate(self):
        self.city = gen_city()

    def dump_obj(self, path, name):
        write_obj(self.city, path, name)


def create_lots(lot, block):
    width = lot[2] - lot[0]
    height = lot[3] - lot[1]
    if width < 30 or height < 30:
        if lot[0] == block[0] or lot[1] == block[1] or lot[2] == block[2] or lot[3] == block[3]:
            return [lot]
        return []

    ret = []

    if width > height:
        new_width = width * random.uniform(0.3, 0.7)
        ret += create_lots((lot[0], lot[1], lot[0]+new_width, lot[3]), block)
        ret += create_lots((lot[0]+new_width, lot[1], lot[2], lot[3]), block)
        return ret

    new_height = height * random.uniform(0.3, 0.7)
    ret += create_lots((lot[0], lot[1], lot[2], lot[1]+new_height), block)
    ret += create_lots((lot[0], lot[1]+new_height, lot[2], lot[3]), block)
    return ret


def gen_city(city_width=500, city_height=500, lane_width=6, block_width=80, block_height=80, block_var=0.25):
    city = City()
    x_off = city_width / 2.0
    y_off = city_height / 2.0

    # Roads
    vert_roads = []
    vert_progress = 0
    while True:
        variance = random.random() * block_var * block_width
        progress = block_width + variance
        if vert_progress + progress > city_width:
            break
        vert_progress += progress
        vert_roads.append(vert_progress)

    hor_roads = []
    hor_progress = 0
    while True:
        variance = random.random() * block_var * block_height
        progress = block_height + variance
        if hor_progress + progress > city_height:
            break
        hor_progress += progress
        hor_roads.append(hor_progress)

    x_offset = (city_width - hor_progress) / 2.0
    y_offset = (city_height - vert_progress) / 2.0

    # Blocks
    blocks = []
    road_verts = []
    road_faces = []
    for i in range(len(vert_roads)):
        x1 = 0.0 if i == 0 else vert_roads[i-1] + lane_width
        x1 += x_offset
        x2 = vert_roads[i] - lane_width
        x2 += x_offset
        for j in range(len(hor_roads)):
            y1 = 0.0 if j == 0 else hor_roads[j-1] + lane_width
            y1 += y_offset
            y2 = hor_roads[j] - lane_width
            y2 += y_offset

            blocks.append((x1, y1, x2, y2))

            if i != len(vert_roads)-1 and j != len(hor_roads)-1:
                verts = []
                normal = (0, 0, 1)
                x3 = vert_roads[i] + lane_width + x_offset
                y3 = hor_roads[j] + lane_width + y_offset

                spawn_point = ((x2+x3)/2.0-x_off, (y2+y3)/2.0-y_off, 0.0)
                city.spawn_points.append(spawn_point)

                vert_off = len(road_verts)
                road_verts.append(Vertex((x2 - x_off, y2 - y_off, 0.0), normal))
                road_verts.append(Vertex((x3 - x_off, y2 - y_off, 0.0), normal))
                road_verts.append(Vertex((x3 - x_off, y3 - y_off, 0.0), normal))
                road_verts.append(Vertex((x2 - x_off, y3 - y_off, 0.0), normal))
                road_faces.append((vert_off + 0, vert_off + 1, vert_off + 2))
                road_faces.append((vert_off + 2, vert_off + 3, vert_off + 0))
                if j > 0:
                    road_faces.append((vert_off-1, vert_off-2, vert_off+1))
{'fraction_non_alphanumeric': 0.13431786216596342, 'fraction_numerical': 0.03164556962025317, 'mean_word_length': 2.152198005171777, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1743716', 'n_tokens_mistral': 3063, 'n_tokens_neox': 2875, 'n_words': 670}