From 29028cc1a552dbcbfb9e36643559e87806aefd15 Mon Sep 17 00:00:00 2001 From: Matthias Bisping Date: Thu, 7 Apr 2022 17:44:54 +0200 Subject: [PATCH] refactoring --- test/unit_tests/image_stitcher_test.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/unit_tests/image_stitcher_test.py b/test/unit_tests/image_stitcher_test.py index 01f8b41..8e18f67 100644 --- a/test/unit_tests/image_stitcher_test.py +++ b/test/unit_tests/image_stitcher_test.py @@ -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)