2022-04-11 13:03:02 +02:00

41 lines
1.1 KiB
Python

from copy import deepcopy
from dataclasses import field, dataclass
from operator import attrgetter
from image_prediction.info import Info
@dataclass
class SplitMapper:
"""Manages access into a mapping M by indirection through a specified access mapping to achieve a common
interface between various M_i.
"""
__access_mapping: dict
wrapped: dict
__wrapped: dict = field(init=False)
def __post_init__(self):
for k, v in self.__access_mapping.items():
setattr(self, k, self.__wrapped[v])
@property
def wrapped(self):
ret = deepcopy(self.__wrapped)
ret.update(dict(zip(self.__access_mapping.values(), attrgetter(*self.__access_mapping.keys())(self))))
return ret
@wrapped.setter
def wrapped(self, wrapped):
self.__wrapped = wrapped
class HorizontalSplitMapper(SplitMapper):
def __init__(self, wrapped: dict):
super().__init__({"dim": Info.WIDTH, "c1": Info.X1, "c2": Info.X2}, wrapped)
class VerticalSplitMapper(SplitMapper):
def __init__(self, wrapped: dict):
super().__init__({"dim": Info.HEIGHT, "c1": Info.Y1, "c2": Info.Y2}, wrapped)