@@ -252,30 +252,28 @@ def __repr__(self) -> str:
252
252
else :
253
253
return "Body(Body.STATIC)"
254
254
255
- def _set_mass (self , mass : float ) -> None :
256
- lib .cpBodySetMass (self ._body , mass )
257
-
258
- def _get_mass (self ) -> float :
255
+ @property
256
+ def mass (self ) -> float :
257
+ """Mass of the body."""
259
258
return lib .cpBodyGetMass (self ._body )
260
259
261
- mass = property (_get_mass , _set_mass , doc = """Mass of the body.""" )
260
+ @mass .setter
261
+ def mass (self , mass : float ) -> None :
262
+ lib .cpBodySetMass (self ._body , mass )
262
263
263
- def _set_moment (self , moment : float ) -> None :
264
- lib .cpBodySetMoment (self ._body , moment )
264
+ @property
265
+ def moment (self ) -> float :
266
+ """Moment of inertia (MoI or sometimes just moment) of the body.
265
267
266
- def _get_moment (self ) -> float :
268
+ The moment is like the rotational mass of a body.
269
+ """
267
270
return lib .cpBodyGetMoment (self ._body )
268
271
269
- moment = property (
270
- _get_moment ,
271
- _set_moment ,
272
- doc = """Moment of inertia (MoI or sometimes just moment) of the body.
273
-
274
- The moment is like the rotational mass of a body.
275
- """ ,
276
- )
272
+ @moment .setter
273
+ def moment (self , moment : float ) -> None :
274
+ lib .cpBodySetMoment (self ._body , moment )
277
275
278
- def _set_position (self , pos : Union [ Vec2d , Tuple [float , float ] ]) -> None :
276
+ def _set_position (self , pos : Tuple [float , float ]) -> None :
279
277
assert len (pos ) == 2
280
278
lib .cpBodySetPosition (self ._body , pos )
281
279
@@ -344,16 +342,9 @@ def _get_force(self) -> Vec2d:
344
342
force applied manually from the apply force functions.""" ,
345
343
)
346
344
347
- def _set_angle (self , angle : float ) -> None :
348
- lib .cpBodySetAngle (self ._body , angle )
349
-
350
- def _get_angle (self ) -> float :
351
- return lib .cpBodyGetAngle (self ._body )
352
-
353
- angle = property (
354
- _get_angle ,
355
- _set_angle ,
356
- doc = """Rotation of the body in radians.
345
+ @property
346
+ def angle (self ) -> float :
347
+ """Rotation of the body in radians.
357
348
358
349
When changing the rotation you may also want to call
359
350
:py:func:`Space.reindex_shapes_for_body` to update the collision
@@ -365,43 +356,39 @@ def _get_angle(self) -> float:
365
356
If you get small/no changes to the angle when for example a
366
357
ball is "rolling" down a slope it might be because the Circle shape
367
358
attached to the body or the slope shape does not have any friction
368
- set.""" ,
369
- )
359
+ set."""
360
+ return lib . cpBodyGetAngle ( self . _body )
370
361
371
- def _set_angular_velocity (self , w : float ) -> None :
372
- lib .cpBodySetAngularVelocity (self ._body , w )
362
+ @angle .setter
363
+ def angle (self , angle : float ) -> None :
364
+ lib .cpBodySetAngle (self ._body , angle )
373
365
374
- def _get_angular_velocity (self ) -> float :
366
+ @property
367
+ def angular_velocity (self ) -> float :
368
+ """The angular velocity of the body in radians per second."""
375
369
return lib .cpBodyGetAngularVelocity (self ._body )
376
370
377
- angular_velocity = property (
378
- _get_angular_velocity ,
379
- _set_angular_velocity ,
380
- doc = """The angular velocity of the body in radians per second.""" ,
381
- )
371
+ @angular_velocity .setter
372
+ def angular_velocity (self , w : float ) -> None :
373
+ lib .cpBodySetAngularVelocity (self ._body , w )
382
374
383
- def _set_torque (self , t : float ) -> None :
384
- lib .cpBodySetTorque (self ._body , t )
375
+ @property
376
+ def torque (self ) -> float :
377
+ """The torque applied to the body.
385
378
386
- def _get_torque ( self ) -> float :
379
+ This value is reset for every time step."""
387
380
return lib .cpBodyGetTorque (self ._body )
388
381
389
- torque = property (
390
- _get_torque ,
391
- _set_torque ,
392
- doc = """The torque applied to the body.
393
-
394
- This value is reset for every time step.""" ,
395
- )
382
+ @torque .setter
383
+ def torque (self , t : float ) -> None :
384
+ lib .cpBodySetTorque (self ._body , t )
396
385
397
- def _get_rotation_vector (self ) -> Vec2d :
386
+ @property
387
+ def rotation_vector (self ) -> Vec2d :
388
+ """The rotation vector for the body."""
398
389
v = lib .cpBodyGetRotation (self ._body )
399
390
return Vec2d (v .x , v .y )
400
391
401
- rotation_vector = property (
402
- _get_rotation_vector , doc = """The rotation vector for the body."""
403
- )
404
-
405
392
@property
406
393
def space (self ) -> Optional ["Space" ]:
407
394
"""Get the :py:class:`Space` that the body has been added to (or
@@ -609,7 +596,20 @@ def is_sleeping(self) -> bool:
609
596
"""Returns true if the body is sleeping."""
610
597
return bool (lib .cpBodyIsSleeping (self ._body ))
611
598
612
- def _set_type (self , body_type : _BodyType ) -> None :
599
+ @property
600
+ def body_type (self ) -> _BodyType :
601
+ """The type of a body (:py:const:`Body.DYNAMIC`,
602
+ :py:const:`Body.KINEMATIC` or :py:const:`Body.STATIC`).
603
+
604
+ When changing an body to a dynamic body, the mass and moment of
605
+ inertia are recalculated from the shapes added to the body. Custom
606
+ calculated moments of inertia are not preserved when changing types.
607
+ This function cannot be called directly in a collision callback.
608
+ """
609
+ return lib .cpBodyGetType (self ._body )
610
+
611
+ @body_type .setter
612
+ def body_type (self , body_type : _BodyType ) -> None :
613
613
if body_type != Body .DYNAMIC :
614
614
for c in self .constraints :
615
615
assert (c .a != self and c .b .body_type == Body .DYNAMIC ) or (
@@ -618,22 +618,6 @@ def _set_type(self, body_type: _BodyType) -> None:
618
618
619
619
lib .cpBodySetType (self ._body , body_type )
620
620
621
- def _get_type (self ) -> _BodyType :
622
- return lib .cpBodyGetType (self ._body )
623
-
624
- body_type = property (
625
- _get_type ,
626
- _set_type ,
627
- doc = """The type of a body (:py:const:`Body.DYNAMIC`,
628
- :py:const:`Body.KINEMATIC` or :py:const:`Body.STATIC`).
629
-
630
- When changing an body to a dynamic body, the mass and moment of
631
- inertia are recalculated from the shapes added to the body. Custom
632
- calculated moments of inertia are not preserved when changing types.
633
- This function cannot be called directly in a collision callback.
634
- """ ,
635
- )
636
-
637
621
def each_arbiter (
638
622
self ,
639
623
func : Callable [..., None ], # TODO: Fix me once PEP 612 is ready
0 commit comments