Skip to content

Commit a8976cb

Browse files
committed
Add a note on the convex poly constraints.
1 parent 51735b6 commit a8976cb

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

pymunk/shapes.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
class Shape(PickleMixin, TypingAttrMixing, object):
2525
"""Base class for all the shapes.
2626
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
2828
one of the specialized shapes instead (:py:class:`Circle`,
2929
:py:class:`Poly` or :py:class:`Segment`).
3030
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
3232
body (if any) will also be copied.
3333
"""
3434

@@ -79,7 +79,7 @@ def shapefree(cp_shape: ffi.CData) -> None:
7979

8080
@property
8181
def _id(self) -> int:
82-
"""Unique id of the Shape
82+
"""Unique id of the Shape.
8383
8484
.. note::
8585
Experimental API. Likely to change in future major, minor orpoint
@@ -102,8 +102,8 @@ def _set_mass(self, mass: float) -> None:
102102
_set_mass,
103103
doc="""The mass of this shape.
104104
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
107107
mass and inertia directly)
108108
""",
109109
)
@@ -118,9 +118,9 @@ def _set_density(self, density: float) -> None:
118118
_get_density,
119119
_set_density,
120120
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
124124
mass and inertia directly)
125125
""",
126126
)
@@ -168,7 +168,7 @@ def _set_collision_type(self, t: int) -> None:
168168
_set_collision_type,
169169
doc="""User defined collision type for the shape.
170170
171-
See :py:meth:`Space.add_collision_handler` function for more
171+
See :py:meth:`Space.add_collision_handler` function for more
172172
information on when to use this property.
173173
""",
174174
)
@@ -295,7 +295,7 @@ def update(self, transform: Transform) -> BB:
295295
return BB(_bb.l, _bb.b, _bb.r, _bb.t)
296296

297297
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."""
299299
_bb = cp.cpShapeCacheBB(self._shape)
300300
return BB(_bb.l, _bb.b, _bb.r, _bb.t)
301301

@@ -391,7 +391,7 @@ def _hashid(self, v: int) -> None:
391391
cp.cpShapeSetHashID(self._shape, v)
392392

393393
def __getstate__(self) -> _State:
394-
"""Return the state of this object
394+
"""Return the state of this object.
395395
396396
This method allows the usage of the :mod:`copy` and :mod:`pickle`
397397
modules with this class.
@@ -407,9 +407,9 @@ def __getstate__(self) -> _State:
407407

408408

409409
class Circle(Shape):
410-
"""A circle shape defined by a radius
410+
"""A circle shape defined by a radius.
411411
412-
This is the fastest and simplest collision shape
412+
This is the fastest and simplest collision shape.
413413
"""
414414

415415
_pickle_attrs_init = Shape._pickle_attrs_init + ["radius", "offset"]
@@ -445,7 +445,7 @@ def unsafe_set_radius(self, r: float) -> None:
445445

446446
@property
447447
def radius(self) -> float:
448-
"""The Radius of the circle"""
448+
"""The Radius of the circle."""
449449
return cp.cpCircleShapeGetRadius(self._shape)
450450

451451
def unsafe_set_offset(self, o: Tuple[float, float]) -> None:
@@ -468,7 +468,7 @@ def offset(self) -> Vec2d:
468468

469469

470470
class Segment(Shape):
471-
"""A line segment shape between two points
471+
"""A line segment shape between two points.
472472
473473
Meant mainly as a static shape. Can be beveled in order to give them a
474474
thickness.
@@ -483,7 +483,7 @@ def __init__(
483483
b: Tuple[float, float],
484484
radius: float,
485485
) -> None:
486-
"""Create a Segment
486+
"""Create a Segment.
487487
488488
It is legal to send in None as body argument to indicate that this
489489
shape is not attached to a body. However, you must attach it to a body
@@ -516,7 +516,7 @@ def _get_b(self) -> Vec2d:
516516
def unsafe_set_endpoints(
517517
self, a: Tuple[float, float], b: Tuple[float, float]
518518
) -> None:
519-
"""Set the two endpoints for this segment
519+
"""Set the two endpoints for this segment.
520520
521521
.. note::
522522
This change is only picked up as a change to the position
@@ -535,7 +535,7 @@ def normal(self) -> Vec2d:
535535
return Vec2d(v.x, v.y)
536536

537537
def unsafe_set_radius(self, r: float) -> None:
538-
"""Set the radius of the segment
538+
"""Set the radius of the segment.
539539
540540
.. note::
541541
This change is only picked up as a change to the position
@@ -547,7 +547,7 @@ def unsafe_set_radius(self, r: float) -> None:
547547

548548
@property
549549
def radius(self) -> float:
550-
"""The radius/thickness of the segment"""
550+
"""The radius/thickness of the segment."""
551551
return cp.cpSegmentShapeGetRadius(self._shape)
552552

553553
def set_neighbors(
@@ -578,14 +578,15 @@ def __init__(
578578
) -> None:
579579
"""Create a polygon.
580580
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.
582583
583-
Adding a small radius will bevel the corners and can significantly
584+
Add a small radius will bevel the corners and can significantly
584585
reduce problems where the poly gets stuck on seams in your geometry.
585586
586587
It is legal to send in None as body argument to indicate that this
587588
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.
589+
before adding the shape to a space or using for a space shape query.
589590
590591
.. note::
591592
Make sure to put the vertices around (0,0) or the shape might
@@ -615,8 +616,8 @@ def __init__(
615616
616617
:param Body body: The body to attach the poly to
617618
: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.
619+
with a counterclockwise winding
620+
:param Transform transform: Transform will be applied to every vertex
620621
:param float radius: Set the radius of the poly shape
621622
622623
"""
@@ -652,10 +653,10 @@ def radius(self) -> float:
652653
def create_box(
653654
body: Optional["Body"], size: Tuple[float, float] = (10, 10), radius: float = 0
654655
) -> "Poly":
655-
"""Convenience function to create a box given a width and height.
656+
"""Convenience function to create a box with given width and height.
656657
657658
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
659+
body you are attaching them to. If you want to create an off-center
659660
box, you will need to use the normal constructor Poly(...).
660661
661662
Adding a small radius will bevel the corners and can significantly
@@ -680,7 +681,7 @@ def create_box_bb(body: Optional["Body"], bb: BB, radius: float = 0) -> "Poly":
680681
"""Convenience function to create a box shape from a :py:class:`BB`.
681682
682683
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
684+
body you are attaching them to. If you want to create an off-center
684685
box, you will need to use the normal constructor Poly(..).
685686
686687
Adding a small radius will bevel the corners and can significantly
@@ -700,7 +701,7 @@ def create_box_bb(body: Optional["Body"], bb: BB, radius: float = 0) -> "Poly":
700701
return self
701702

702703
def get_vertices(self) -> List[Vec2d]:
703-
"""Get the vertices in local coordinates for the polygon
704+
"""Get the vertices in local coordinates for the polygon.
704705
705706
If you need the vertices in world coordinates then the vertices can be
706707
transformed by adding the body position and each vertex rotated by the
@@ -722,8 +723,8 @@ def get_vertices(self) -> List[Vec2d]:
722723
:rtype: [:py:class:`Vec2d`]
723724
"""
724725
verts = []
725-
l = cp.cpPolyShapeGetCount(self._shape)
726-
for i in range(l):
726+
lines = cp.cpPolyShapeGetCount(self._shape)
727+
for i in range(lines):
727728
v = cp.cpPolyShapeGetVert(self._shape, i)
728729
verts.append(Vec2d(v.x, v.y))
729730
return verts
@@ -748,7 +749,7 @@ def unsafe_set_vertices(
748749
cp.cpPolyShapeSetVerts(self._shape, len(vertices), vertices, transform)
749750

750751
def __getstate__(self) -> _State:
751-
"""Return the state of this object
752+
"""Return the state of this object.
752753
753754
This method allows the usage of the :mod:`copy` and :mod:`pickle`
754755
modules with this class.

0 commit comments

Comments
 (0)