Skip to content

Commit 3879c28

Browse files
author
zhen.chen
committed
refactor(dataset): use "AttrsMixin" in "Box3D"
1 parent 089639b commit 3879c28

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

tensorbay/geometry/box.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import warnings
2020
from typing import Dict, Iterable, Optional, Tuple, Type, TypeVar
2121

22-
from ..utility import MatrixType, ReprMixin, ReprType, UserSequence, common_loads
22+
from ..utility import AttrsMixin, MatrixType, ReprMixin, ReprType, UserSequence, attr, common_loads
2323
from .transform import Transform3D
2424
from .vector import Vector2D, Vector3D
2525

@@ -324,7 +324,7 @@ def area(self) -> float:
324324
return self.width * self.height
325325

326326

327-
class Box3D(ReprMixin):
327+
class Box3D(ReprMixin, AttrsMixin): # pylint: disable=too-many-ancestors
328328
"""This class defines the concept of Box3D.
329329
330330
:class:`Box3D` contains the information of a 3D bounding box such as the transform,
@@ -363,6 +363,9 @@ class Box3D(ReprMixin):
363363
_repr_type = ReprType.INSTANCE
364364
_repr_attrs: Tuple[str, ...] = ("size", "translation", "rotation")
365365

366+
_size: Vector3D = attr(key="size")
367+
_transform: Transform3D = attr(key=None)
368+
366369
def __init__(
367370
self,
368371
size: Iterable[float],
@@ -413,10 +416,6 @@ def _line_intersect(length1: float, length2: float, midpoint_distance: float) ->
413416
intersect_length = min(line1_max, line2_max) - max(line1_min, line2_min)
414417
return intersect_length if intersect_length > 0 else 0
415418

416-
def _loads(self, contents: Dict[str, Dict[str, float]]) -> None:
417-
self._size = Vector3D.loads(contents["size"])
418-
self._transform = Transform3D.loads(contents)
419-
420419
@classmethod
421420
def loads(cls: Type[_B3], contents: Dict[str, Dict[str, float]]) -> _B3:
422421
"""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]]:
567566
}
568567
569568
"""
570-
contents = self._transform.dumps()
571-
contents["size"] = self.size.dumps()
572-
return contents
569+
return self._dumps()

0 commit comments

Comments
 (0)