Skip to content

Commit

Permalink
refactor(dataset): use "AttrsMixin" in "Box3D"
Browse files Browse the repository at this point in the history
  • Loading branch information
zhen.chen committed May 26, 2021
1 parent 089639b commit 3879c28
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions tensorbay/geometry/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()

0 comments on commit 3879c28

Please sign in to comment.