def split(self, min_size=(6, 6), direction=None):
        assert self.corner1 is not None
        assert self.corner2 is not None

        size = (abs(self.corner1[0] - self.corner2[0]),
                abs(self.corner1[1] - self.corner2[1]))

        if direction is None:
            # 1 split horizontal, 2 split vertical
            direction = random.randint(1, 2)
        assert(direction in (1, 2))

        if direction == 1:
            if size[1] < 2 * min_size[1]:
                if size[0] < 2 * min_size[0]:
                    return None
                else:
                    direction = 2
        else:
            if size[0] < 2 * min_size[0]:
                if size[1] < 2 * min_size[1]:
                    return None
                else:
                    direction = 1

        if direction == 1:
            split_location = random.randint(min_size[1], size[1] - min_size[1])
            self.node1 = BSPSection(self.corner1,
                                    (self.corner2[0],
                                        self.corner1[1] + split_location),
                                    self, direction)
            self.node2 = BSPSection((self.corner1[0],
                                     self.corner1[1] + split_location + 1),
                                    self.corner2,
                                    self, direction)
        else:
            split_location = random.randint(min_size[0], size[0] - min_size[0])
            self.node1 = BSPSection(self.corner1,
                                    (self.corner1[0] + split_location,
                                     self.corner2[1]),
                                    self, direction)
            self.node2 = BSPSection((self.corner1[0] + split_location + 1,
                                    self.corner1[1]),
                                    self.corner2,
                                    self, direction)
Split BSPSection in two
dataset/ETHPy150Open tuturto/pyherc/src/pyherc/generators/utils.py/BSPSection.split