diff --git a/src/arcaea_offline_ocr/types.py b/src/arcaea_offline_ocr/types.py index bac409b..8c0730d 100644 --- a/src/arcaea_offline_ocr/types.py +++ b/src/arcaea_offline_ocr/types.py @@ -1,4 +1,5 @@ -from typing import NamedTuple +from collections.abc import Iterable +from typing import NamedTuple, Tuple, Union import numpy as np @@ -11,3 +12,15 @@ class XYWHRect(NamedTuple): y: int w: int h: int + + def __add__(self, other: Union["XYWHRect", Tuple[int, int, int, int]]): + if not isinstance(other, Iterable) or len(other) != 4: + raise ValueError() + + return self.__class__(*[a + b for a, b in zip(self, other)]) + + def __sub__(self, other: Union["XYWHRect", Tuple[int, int, int, int]]): + if not isinstance(other, Iterable) or len(other) != 4: + raise ValueError() + + return self.__class__(*[a - b for a, b in zip(self, other)])