Skip to content

Commit 72bbe3b

Browse files
committed
Add example in Poly docs of convex hull #257
1 parent bc90bf6 commit 72bbe3b

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

CHANGELOG.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Changelog
1414
New feature: Added Vec2d.polar_tuple
1515
Optimized Vec2d.angle and Vec2d.angle_degrees (note that the optimized versions treat 0 length vectors with x and/or y equal to -0 slightly differently.)
1616
Improved vec2d documentation
17-
17+
Improved Poly documentation
1818
1919
Extra thanks for aetle for a number of suggestions for improvements in this pymunk release
2020

pymunk/shapes.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ def collision_type(self, t: int) -> None:
154154

155155
@property
156156
def filter(self) -> ShapeFilter:
157-
"""Set the collision :py:class:`ShapeFilter` for this shape.
158-
"""
157+
"""Set the collision :py:class:`ShapeFilter` for this shape."""
159158
f = cp.cpShapeGetFilter(self._shape)
160159
return ShapeFilter(f.group, f.categories, f.mask)
161160

@@ -547,7 +546,11 @@ def __init__(
547546
548547
A convex hull will be calculated from the vertexes automatically. Note
549548
that concave ones will be converted to a convex hull using the Quickhull
550-
algorithm.
549+
algorithm::
550+
551+
>>> poly = Poly(None, [(-1,0), (0, -0.5), (1, 0), (0,-1)])
552+
>>> poly.get_vertices()
553+
[Vec2d(-1.0, 0.0), Vec2d(0.0, -1.0), Vec2d(1.0, 0.0)]
551554
552555
Adding a small radius will bevel the corners and can significantly
553556
reduce problems where the poly gets stuck on seams in your geometry.
@@ -562,23 +565,21 @@ def __init__(
562565
563566
Either directly place the vertices like the below example:
564567
565-
>>> import pymunk
566568
>>> w, h = 10, 20
567569
>>> vs = [(-w/2,-h/2), (w/2,-h/2), (w/2,h/2), (-w/2,h/2)]
568-
>>> poly_good = pymunk.Poly(None, vs)
570+
>>> poly_good = Poly(None, vs)
569571
>>> print(poly_good.center_of_gravity)
570572
Vec2d(0.0, 0.0)
571573
572574
Or use a transform to move them:
573575
574-
>>> import pymunk
575576
>>> width, height = 10, 20
576577
>>> vs = [(0, 0), (width, 0), (width, height), (0, height)]
577-
>>> poly_bad = pymunk.Poly(None, vs)
578+
>>> poly_bad = Poly(None, vs)
578579
>>> print(poly_bad.center_of_gravity)
579580
Vec2d(5.0, 10.0)
580-
>>> t = pymunk.Transform(tx=-width/2, ty=-height/2)
581-
>>> poly_good = pymunk.Poly(None, vs, transform=t)
581+
>>> t = Transform(tx=-width/2, ty=-height/2)
582+
>>> poly_good = Poly(None, vs, transform=t)
582583
>>> print(poly_good.center_of_gravity)
583584
Vec2d(0.0, 0.0)
584585

0 commit comments

Comments
 (0)