|
19 | 19 | import warnings |
20 | 20 | from typing import Dict, Iterable, Optional, Tuple, Type, TypeVar |
21 | 21 |
|
22 | | -from ..utility import MatrixType, ReprMixin, ReprType, UserSequence, common_loads |
| 22 | +from ..utility import AttrsMixin, MatrixType, ReprMixin, ReprType, UserSequence, attr, common_loads |
23 | 23 | from .transform import Transform3D |
24 | 24 | from .vector import Vector2D, Vector3D |
25 | 25 |
|
@@ -324,7 +324,7 @@ def area(self) -> float: |
324 | 324 | return self.width * self.height |
325 | 325 |
|
326 | 326 |
|
327 | | -class Box3D(ReprMixin): |
| 327 | +class Box3D(ReprMixin, AttrsMixin): # pylint: disable=too-many-ancestors |
328 | 328 | """This class defines the concept of Box3D. |
329 | 329 |
|
330 | 330 | :class:`Box3D` contains the information of a 3D bounding box such as the transform, |
@@ -363,6 +363,9 @@ class Box3D(ReprMixin): |
363 | 363 | _repr_type = ReprType.INSTANCE |
364 | 364 | _repr_attrs: Tuple[str, ...] = ("size", "translation", "rotation") |
365 | 365 |
|
| 366 | + _size: Vector3D = attr(key="size") |
| 367 | + _transform: Transform3D = attr(key=None) |
| 368 | + |
366 | 369 | def __init__( |
367 | 370 | self, |
368 | 371 | size: Iterable[float], |
@@ -413,10 +416,6 @@ def _line_intersect(length1: float, length2: float, midpoint_distance: float) -> |
413 | 416 | intersect_length = min(line1_max, line2_max) - max(line1_min, line2_min) |
414 | 417 | return intersect_length if intersect_length > 0 else 0 |
415 | 418 |
|
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 | | - |
420 | 419 | @classmethod |
421 | 420 | def loads(cls: Type[_B3], contents: Dict[str, Dict[str, float]]) -> _B3: |
422 | 421 | """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]]: |
567 | 566 | } |
568 | 567 |
|
569 | 568 | """ |
570 | | - contents = self._transform.dumps() |
571 | | - contents["size"] = self.size.dumps() |
572 | | - return contents |
| 569 | + return self._dumps() |
0 commit comments