refactoring
This commit is contained in:
parent
2fcb0bd149
commit
29028cc1a5
@ -1,5 +1,5 @@
|
||||
from copy import deepcopy
|
||||
from functools import partial
|
||||
from functools import partial, reduce
|
||||
from itertools import groupby
|
||||
from itertools import starmap, chain, repeat
|
||||
from typing import Iterable, List
|
||||
@ -128,16 +128,18 @@ class Stitcher:
|
||||
|
||||
def merge_group(group):
|
||||
|
||||
def merge_with(current_pair, pairs):
|
||||
def merge_with(aggregation_pair, pairs):
|
||||
|
||||
to_remove = []
|
||||
def aggregate_on_head(pairs_aggr: Iterable[ImageMetadataPair], pair: ImageMetadataPair):
|
||||
"""Keeps the image that is being merged with as the head and aggregates non-mergables in the tail"""
|
||||
aggr, non_aggr = juxt(first, rest)(pairs_aggr)
|
||||
if y2_getter(aggr) == y1_getter(pair):
|
||||
aggr = merge_pair_vertically(aggr, pair)
|
||||
return aggr, *non_aggr
|
||||
else:
|
||||
return aggr, pair, *non_aggr
|
||||
|
||||
for pair in pairs:
|
||||
if y2_getter(current_pair) == y1_getter(pair):
|
||||
current_pair = merge_pair_vertically(current_pair, pair)
|
||||
to_remove.append(pair)
|
||||
|
||||
return [current_pair, *filter(lambda p: p not in to_remove, pairs)]
|
||||
return list(reduce(aggregate_on_head, pairs, [aggregation_pair]))
|
||||
|
||||
pairs = list(group)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user