refactoring

This commit is contained in:
Matthias Bisping 2022-04-05 19:38:29 +02:00
parent 315679468b
commit ef70e11352

View File

@ -58,7 +58,7 @@ class BoxSplitter:
new_boxes = splitter(box)
return new_boxes
def __tree_recurse(self, boxes, step)
def __tree_recurse(self, boxes, step):
return map(rpartial(self.__split_recursively, step + 1), boxes)
def __split_horizontal(self, box):
@ -67,23 +67,27 @@ class BoxSplitter:
def __split_vertical(self, box):
return self.__split_if_large_enough(VerticalKeyMapper(box))
def __split_if_large_enough(self, sabox: SplitKeyMapper):
return self.__get_child_boxes(sabox) if self.__large_enough(sabox) else self.__base_case(sabox.box)
def __split_if_large_enough(self, wrapped_box: SplitKeyMapper):
return (
self.__get_child_boxes(wrapped_box)
if self.__large_enough(wrapped_box)
else self.__base_case(wrapped_box.box)
)
@staticmethod
def __large_enough(box):
return box["dim"] >= 10
@staticmethod
def __get_child_boxes(sabox: SplitKeyMapper):
def __get_child_boxes(wrapped_box: SplitKeyMapper):
split_len = random.randint(5, sabox["dim"] - 5)
split_point = sabox["c1"] + split_len
split_len = random.randint(5, wrapped_box["dim"] - 5)
split_point = wrapped_box["c1"] + split_len
box_left, box_right = juxt(deepcopy, deepcopy)(sabox)
box_left, box_right = juxt(deepcopy, deepcopy)(wrapped_box)
box_left["dim"] = split_len
box_right["dim"] = sabox["dim"] - split_len
box_right["dim"] = wrapped_box["dim"] - split_len
box_left["c2"] = split_point
box_right["c1"] = split_point