refactoring
This commit is contained in:
parent
51793d19e9
commit
303970db51
@ -50,4 +50,7 @@ class Stitcher:
|
||||
return pairs
|
||||
|
||||
def stitch(self, pairs: Iterable[ImageMetadataPair]) -> List[ImageMetadataPair]:
|
||||
return until_convergence(self.merge_along_both_axes, pairs)
|
||||
def break_condition(pairs1, pairs2):
|
||||
return len(pairs1) == len(pairs2)
|
||||
|
||||
return until_convergence(self.merge_along_both_axes, break_condition, pairs)
|
||||
|
||||
@ -130,8 +130,12 @@ def make_merger_aggregator(direction):
|
||||
|
||||
|
||||
def merge_group(group, direction):
|
||||
|
||||
def break_condition(pairs1, pairs2):
|
||||
return len(pairs1) == len(pairs2)
|
||||
|
||||
reduce_group = make_merger_aggregator(direction)
|
||||
return until_convergence(reduce_group, group)
|
||||
return until_convergence(reduce_group, break_condition, group)
|
||||
|
||||
|
||||
def merge_group_horizontally(group):
|
||||
|
||||
@ -8,7 +8,7 @@ def chunk_iterable(iterable, chunk_size):
|
||||
return takewhile(truth, map(tuple, starmap(islice, repeat((iter(iterable), chunk_size)))))
|
||||
|
||||
|
||||
def until_convergence(func, *args, **kwargs):
|
||||
def until_convergence(func, cond, *args, **kwargs):
|
||||
for a, b in chunk_iterable(iterate(func, *args, **kwargs), chunk_size=2):
|
||||
if len(a) == len(b):
|
||||
if cond(a, b):
|
||||
return a
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user