Matthias Bisping cef97b33f9 Refactoring: Move
Move page partitioners into partitioner module
2023-02-01 17:20:32 +01:00

23 lines
764 B
Python

from cv_analysis.utils.rectangle import Rectangle
from synthesis.partitioner.page_partitioner import PagePartitioner
from synthesis.random import rnd
class RandomPagePartitioner(PagePartitioner):
def __init__(self):
super().__init__()
def generate_content_boxes(self, box: Rectangle, depth=0):
if depth >= self.max_recursion_depth:
yield box
else:
child_boxes = self.generate_child_boxes(
box,
axis=rnd.choice(["x", "y"]),
split_percentage=rnd.uniform(0.3, 0.7),
)
if self.recurse(depth):
yield from (self.generate_content_boxes(b, depth + 1) for b in child_boxes)
else:
yield child_boxes