Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(AttrsMixin, ReprMixin): # 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()