24
24
class Shape (PickleMixin , TypingAttrMixing , object ):
25
25
"""Base class for all the shapes.
26
26
27
- You usually dont want to create instances of this class directly but use
27
+ You usually don't want to create instances of this class directly but use
28
28
one of the specialized shapes instead (:py:class:`Circle`,
29
29
:py:class:`Poly` or :py:class:`Segment`).
30
30
31
- All the shapes can be copied and pickled. If you copy/pickle a shape the
31
+ All the shapes can be copied and pickled. If you copy/pickle a shape, the
32
32
body (if any) will also be copied.
33
33
"""
34
34
@@ -79,7 +79,7 @@ def shapefree(cp_shape: ffi.CData) -> None:
79
79
80
80
@property
81
81
def _id (self ) -> int :
82
- """Unique id of the Shape
82
+ """Unique id of the Shape.
83
83
84
84
.. note::
85
85
Experimental API. Likely to change in future major, minor orpoint
@@ -102,8 +102,8 @@ def _set_mass(self, mass: float) -> None:
102
102
_set_mass ,
103
103
doc = """The mass of this shape.
104
104
105
- This is useful when you let Pymunk calculate the total mass and inertia
106
- of a body from the shapes attached to it. (Instead of setting the body
105
+ This is useful when you let Pymunk calculate the total mass and inertia
106
+ of a body from the shapes attached to it. (Instead of setting the body
107
107
mass and inertia directly)
108
108
""" ,
109
109
)
@@ -118,9 +118,9 @@ def _set_density(self, density: float) -> None:
118
118
_get_density ,
119
119
_set_density ,
120
120
doc = """The density of this shape.
121
-
122
- This is useful when you let Pymunk calculate the total mass and inertia
123
- of a body from the shapes attached to it. (Instead of setting the body
121
+
122
+ This is useful when you let Pymunk calculate the total mass and inertia
123
+ of a body from the shapes attached to it. (Instead of setting the body
124
124
mass and inertia directly)
125
125
""" ,
126
126
)
@@ -168,7 +168,7 @@ def _set_collision_type(self, t: int) -> None:
168
168
_set_collision_type ,
169
169
doc = """User defined collision type for the shape.
170
170
171
- See :py:meth:`Space.add_collision_handler` function for more
171
+ See :py:meth:`Space.add_collision_handler` function for more
172
172
information on when to use this property.
173
173
""" ,
174
174
)
@@ -295,7 +295,7 @@ def update(self, transform: Transform) -> BB:
295
295
return BB (_bb .l , _bb .b , _bb .r , _bb .t )
296
296
297
297
def cache_bb (self ) -> BB :
298
- """Update and returns the bounding box of this shape"""
298
+ """Update and returns the bounding box of this shape. """
299
299
_bb = cp .cpShapeCacheBB (self ._shape )
300
300
return BB (_bb .l , _bb .b , _bb .r , _bb .t )
301
301
@@ -391,7 +391,7 @@ def _hashid(self, v: int) -> None:
391
391
cp .cpShapeSetHashID (self ._shape , v )
392
392
393
393
def __getstate__ (self ) -> _State :
394
- """Return the state of this object
394
+ """Return the state of this object.
395
395
396
396
This method allows the usage of the :mod:`copy` and :mod:`pickle`
397
397
modules with this class.
@@ -407,9 +407,9 @@ def __getstate__(self) -> _State:
407
407
408
408
409
409
class Circle (Shape ):
410
- """A circle shape defined by a radius
410
+ """A circle shape defined by a radius.
411
411
412
- This is the fastest and simplest collision shape
412
+ This is the fastest and simplest collision shape.
413
413
"""
414
414
415
415
_pickle_attrs_init = Shape ._pickle_attrs_init + ["radius" , "offset" ]
@@ -445,7 +445,7 @@ def unsafe_set_radius(self, r: float) -> None:
445
445
446
446
@property
447
447
def radius (self ) -> float :
448
- """The Radius of the circle"""
448
+ """The Radius of the circle. """
449
449
return cp .cpCircleShapeGetRadius (self ._shape )
450
450
451
451
def unsafe_set_offset (self , o : Tuple [float , float ]) -> None :
@@ -468,7 +468,7 @@ def offset(self) -> Vec2d:
468
468
469
469
470
470
class Segment (Shape ):
471
- """A line segment shape between two points
471
+ """A line segment shape between two points.
472
472
473
473
Meant mainly as a static shape. Can be beveled in order to give them a
474
474
thickness.
@@ -483,7 +483,7 @@ def __init__(
483
483
b : Tuple [float , float ],
484
484
radius : float ,
485
485
) -> None :
486
- """Create a Segment
486
+ """Create a Segment.
487
487
488
488
It is legal to send in None as body argument to indicate that this
489
489
shape is not attached to a body. However, you must attach it to a body
@@ -516,7 +516,7 @@ def _get_b(self) -> Vec2d:
516
516
def unsafe_set_endpoints (
517
517
self , a : Tuple [float , float ], b : Tuple [float , float ]
518
518
) -> None :
519
- """Set the two endpoints for this segment
519
+ """Set the two endpoints for this segment.
520
520
521
521
.. note::
522
522
This change is only picked up as a change to the position
@@ -535,7 +535,7 @@ def normal(self) -> Vec2d:
535
535
return Vec2d (v .x , v .y )
536
536
537
537
def unsafe_set_radius (self , r : float ) -> None :
538
- """Set the radius of the segment
538
+ """Set the radius of the segment.
539
539
540
540
.. note::
541
541
This change is only picked up as a change to the position
@@ -547,7 +547,7 @@ def unsafe_set_radius(self, r: float) -> None:
547
547
548
548
@property
549
549
def radius (self ) -> float :
550
- """The radius/thickness of the segment"""
550
+ """The radius/thickness of the segment. """
551
551
return cp .cpSegmentShapeGetRadius (self ._shape )
552
552
553
553
def set_neighbors (
@@ -564,7 +564,7 @@ def set_neighbors(
564
564
565
565
566
566
class Poly (Shape ):
567
- """A convex polygon shape
567
+ """A convex polygon shape.
568
568
569
569
Slowest, but most flexible collision shape.
570
570
"""
@@ -578,14 +578,16 @@ def __init__(
578
578
) -> None :
579
579
"""Create a polygon.
580
580
581
- A convex hull will be calculated from the vertexes automatically.
581
+ A convex hull will be calculated from the vertexes automatically. Note
582
+ that concave ones will be converted to a convex hull using the Quickhull
583
+ algorithm.
582
584
583
585
Adding a small radius will bevel the corners and can significantly
584
586
reduce problems where the poly gets stuck on seams in your geometry.
585
587
586
588
It is legal to send in None as body argument to indicate that this
587
589
shape is not attached to a body. However, you must attach it to a body
588
- before adding the shape to a space or used for a space shape query.
590
+ before adding the shape to a space or using for a space shape query.
589
591
590
592
.. note::
591
593
Make sure to put the vertices around (0,0) or the shape might
@@ -615,8 +617,8 @@ def __init__(
615
617
616
618
:param Body body: The body to attach the poly to
617
619
:param [(float,float)] vertices: Define a convex hull of the polygon
618
- with a counterclockwise winding.
619
- :param Transform transform: Transform will be applied to every vertex.
620
+ with a counterclockwise winding
621
+ :param Transform transform: Transform will be applied to every vertex
620
622
:param float radius: Set the radius of the poly shape
621
623
622
624
"""
@@ -652,10 +654,10 @@ def radius(self) -> float:
652
654
def create_box (
653
655
body : Optional ["Body" ], size : Tuple [float , float ] = (10 , 10 ), radius : float = 0
654
656
) -> "Poly" :
655
- """Convenience function to create a box given a width and height.
657
+ """Convenience function to create a box with given width and height.
656
658
657
659
The boxes will always be centered at the center of gravity of the
658
- body you are attaching them to. If you want to create an off-center
660
+ body you are attaching them to. If you want to create an off-center
659
661
box, you will need to use the normal constructor Poly(...).
660
662
661
663
Adding a small radius will bevel the corners and can significantly
@@ -680,7 +682,7 @@ def create_box_bb(body: Optional["Body"], bb: BB, radius: float = 0) -> "Poly":
680
682
"""Convenience function to create a box shape from a :py:class:`BB`.
681
683
682
684
The boxes will always be centered at the center of gravity of the
683
- body you are attaching them to. If you want to create an off-center
685
+ body you are attaching them to. If you want to create an off-center
684
686
box, you will need to use the normal constructor Poly(..).
685
687
686
688
Adding a small radius will bevel the corners and can significantly
@@ -700,7 +702,7 @@ def create_box_bb(body: Optional["Body"], bb: BB, radius: float = 0) -> "Poly":
700
702
return self
701
703
702
704
def get_vertices (self ) -> List [Vec2d ]:
703
- """Get the vertices in local coordinates for the polygon
705
+ """Get the vertices in local coordinates for the polygon.
704
706
705
707
If you need the vertices in world coordinates then the vertices can be
706
708
transformed by adding the body position and each vertex rotated by the
@@ -722,8 +724,8 @@ def get_vertices(self) -> List[Vec2d]:
722
724
:rtype: [:py:class:`Vec2d`]
723
725
"""
724
726
verts = []
725
- l = cp .cpPolyShapeGetCount (self ._shape )
726
- for i in range (l ):
727
+ lines = cp .cpPolyShapeGetCount (self ._shape )
728
+ for i in range (lines ):
727
729
v = cp .cpPolyShapeGetVert (self ._shape , i )
728
730
verts .append (Vec2d (v .x , v .y ))
729
731
return verts
@@ -748,7 +750,7 @@ def unsafe_set_vertices(
748
750
cp .cpPolyShapeSetVerts (self ._shape , len (vertices ), vertices , transform )
749
751
750
752
def __getstate__ (self ) -> _State :
751
- """Return the state of this object
753
+ """Return the state of this object.
752
754
753
755
This method allows the usage of the :mod:`copy` and :mod:`pickle`
754
756
modules with this class.
0 commit comments