From 3879c2806d4a9ff3163e4444ddd8a43f0a8cb219 Mon Sep 17 00:00:00 2001 From: "zhen.chen" Date: Wed, 19 May 2021 16:30:13 +0800 Subject: [PATCH] refactor(dataset): use "AttrsMixin" in "Box3D" --- tensorbay/geometry/box.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tensorbay/geometry/box.py b/tensorbay/geometry/box.py index 1a7f8fa6c..8664cd90d 100644 --- a/tensorbay/geometry/box.py +++ b/tensorbay/geometry/box.py @@ -19,7 +19,7 @@ import warnings from typing import Dict, Iterable, Optional, Tuple, Type, TypeVar -from ..utility import MatrixType, ReprMixin, ReprType, UserSequence, common_loads +from ..utility import AttrsMixin, MatrixType, ReprMixin, ReprType, UserSequence, attr, common_loads from .transform import Transform3D from .vector import Vector2D, Vector3D @@ -324,7 +324,7 @@ def area(self) -> float: return self.width * self.height -class Box3D(ReprMixin): +class Box3D(ReprMixin, AttrsMixin): # pylint: disable=too-many-ancestors """This class defines the concept of Box3D. :class:`Box3D` contains the information of a 3D bounding box such as the transform, @@ -363,6 +363,9 @@ class Box3D(ReprMixin): _repr_type = ReprType.INSTANCE _repr_attrs: Tuple[str, ...] = ("size", "translation", "rotation") + _size: Vector3D = attr(key="size") + _transform: Transform3D = attr(key=None) + def __init__( self, size: Iterable[float], @@ -413,10 +416,6 @@ def _line_intersect(length1: float, length2: float, midpoint_distance: float) -> intersect_length = min(line1_max, line2_max) - max(line1_min, line2_min) return intersect_length if intersect_length > 0 else 0 - def _loads(self, contents: Dict[str, Dict[str, float]]) -> None: - self._size = Vector3D.loads(contents["size"]) - self._transform = Transform3D.loads(contents) - @classmethod def loads(cls: Type[_B3], contents: Dict[str, Dict[str, float]]) -> _B3: """Load a :class:`Box3D` from a dict containing the coordinates of the 3D box. @@ -567,6 +566,4 @@ def dumps(self) -> Dict[str, Dict[str, float]]: } """ - contents = self._transform.dumps() - contents["size"] = self.size.dumps() - return contents + return self._dumps()