mirror of
https://github.com/283375/arcaea-offline-ocr.git
synced 2025-04-16 03:50:18 +00:00
feat: XYWHRect __add__
__sub__
support
This commit is contained in:
parent
6c411e6769
commit
425b788c08
@ -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)])
|
||||
|
Loading…
x
Reference in New Issue
Block a user