1919import warnings
2020from 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
2323from .transform import Transform3D
2424from .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 ):
328328 """This class defines the concept of Box3D.
329329
330330 :class:`Box3D` contains the information of a 3D bounding box such as the transform,
@@ -340,7 +340,7 @@ class Box3D(ReprMixin):
340340 Examples:
341341 *Initialization Method 1:* Init from size, translation and rotation.
342342
343- >>> Box3D([1, 2, 3], [0, 1, 0, 0], [1, 2, 3])
343+ >>> Box3D([1, 2, 3], [0, 1, 0, 0], [1, 2, 3]) # pylint: disable=too-many-ancestors
344344 Box3D(
345345 (size): Vector3D(1, 2, 3)
346346 (translation): Vector3D(1, 2, 3),
@@ -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