feat: XYWHRect __add__ __sub__ support

This commit is contained in:
283375 2023-08-02 01:40:36 +08:00
parent 6c411e6769
commit 425b788c08

View File

@ -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)])