refactoring

This commit is contained in:
Matthias Bisping 2022-04-11 10:29:13 +02:00
parent 57440f5106
commit 1bea5fb9a8
3 changed files with 51 additions and 49 deletions

View File

@ -10,7 +10,7 @@ from image_prediction.info import Info
from image_prediction.stitching.grouping import CoordGrouper from image_prediction.stitching.grouping import CoordGrouper
from image_prediction.stitching.utils import make_coord_getter, flatten_groups_once from image_prediction.stitching.utils import make_coord_getter, flatten_groups_once
from image_prediction.utils.generic import until from image_prediction.utils.generic import until
from test.utils.stitching import HorizontalSplitMapper, VerticalMapper from image_prediction.stitching.split_mapper import HorizontalSplitMapper, VerticalMapper
def no_new_merges(pairs1, pairs2): def no_new_merges(pairs1, pairs2):

View File

@ -0,0 +1,49 @@
import abc
from image_prediction.info import Info
class SplitMapper(abc.ABC):
def __init__(self, wrapped: dict, keymap: dict):
self.wrapped = wrapped
self.keymap = keymap
def __getitem__(self, key):
return self.wrapped[self.keymap[key]]
def __setitem__(self, key, value):
self.wrapped[self.keymap[key]] = value
@property
def dim(self):
return self["dim"]
@dim.setter
def dim(self, value):
self["dim"] = value
@property
def c1(self):
return self["c1"]
@c1.setter
def c1(self, value):
self["c1"] = value
@property
def c2(self):
return self["c2"]
@c2.setter
def c2(self, value):
self["c2"] = value
class HorizontalSplitMapper(SplitMapper):
def __init__(self, wrapped: dict):
super().__init__(wrapped, {"dim": Info.WIDTH, "c1": Info.X1, "c2": Info.X2})
class VerticalMapper(SplitMapper):
def __init__(self, wrapped: dict):
super().__init__(wrapped, {"dim": Info.HEIGHT, "c1": Info.Y1, "c2": Info.Y2})

View File

@ -1,57 +1,10 @@
import abc
import random import random
from copy import deepcopy from copy import deepcopy
from itertools import chain from itertools import chain
from funcy import rpartial, juxt from funcy import rpartial, juxt
from image_prediction.info import Info from image_prediction.stitching.split_mapper import SplitMapper, HorizontalSplitMapper, VerticalMapper
class SplitMapper(abc.ABC):
def __init__(self, wrapped: dict, keymap: dict):
self.wrapped = wrapped
self.keymap = keymap
def __getitem__(self, key):
return self.wrapped[self.keymap[key]]
def __setitem__(self, key, value):
self.wrapped[self.keymap[key]] = value
@property
def dim(self):
return self["dim"]
@dim.setter
def dim(self, value):
self["dim"] = value
@property
def c1(self):
return self["c1"]
@c1.setter
def c1(self, value):
self["c1"] = value
@property
def c2(self):
return self["c2"]
@c2.setter
def c2(self, value):
self["c2"] = value
class HorizontalSplitMapper(SplitMapper):
def __init__(self, wrapped: dict):
super().__init__(wrapped, {"dim": Info.WIDTH, "c1": Info.X1, "c2": Info.X2})
class VerticalMapper(SplitMapper):
def __init__(self, wrapped: dict):
super().__init__(wrapped, {"dim": Info.HEIGHT, "c1": Info.Y1, "c2": Info.Y2})
class BoxSplitter: class BoxSplitter: