Skip to content

Commit 1fd8cd2

Browse files
authored
Merge pull request #210 from pygame-community/rename_polygon_get_bounding_box
Renamed Polygon get_bounding_box to as_rect
2 parents 3aaa39f + 671c02c commit 1fd8cd2

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
lines changed

benchmarks/GEOMETRY_polygon_benchmark.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ def polygon(self):
182182
("NC float list", "po100.collidepoint([0.0, 1000.0])"),
183183
]
184184

185-
get_bounding_box_tests = [
186-
("3", "po3.get_bounding_box()"),
187-
("4", "po4.get_bounding_box()"),
188-
("100", "po100.get_bounding_box()"),
185+
as_rect_tests = [
186+
("3", "po3.as_rect()"),
187+
("4", "po4.as_rect()"),
188+
("100", "po100.as_rect()"),
189189
]
190190

191191
subscript_assignment_tests = [
@@ -228,7 +228,7 @@ def polygon(self):
228228
("Rotate", rotate_tests),
229229
("Rotate_ip", rotate_ip_tests),
230230
("Collidepoint", collidepoint_tests),
231-
("Get Bounding Box", get_bounding_box_tests),
231+
("Get Bounding Box", as_rect_tests),
232232
("Subscript", subscript_tests),
233233
("Subscript Assignment", subscript_assignment_tests),
234234
("Scale", scale_tests),

docs/geometry.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ other objects.
192192

193193
scale_ip: Scales the polygon by the given amount in place.
194194

195-
get_bounding_box: Returns the smallest rectangle that contains the polygon.
195+
as_rect: Returns the smallest rectangle that contains the polygon.
196196

197197
as_segments: Returns a list of lines that make up the polygon.
198198

docs/polygon.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,10 @@ Polygon Methods
344344

345345
.. ## Polygon.pop_vertex ##
346346
347-
.. method:: get_bounding_box
347+
.. method:: as_rect
348348

349349
| :sl:`returns the bounding box of the polygon`
350-
| :sg:`get_bounding_box() -> Rect`
350+
| :sg:`as_rect() -> Rect`
351351
352352
Returns a `pygame.Rect` object that contains the `Polygon`. The Rect object will
353353
be the smallest rectangle that contains the `Polygon`.
@@ -361,7 +361,7 @@ Polygon Methods
361361
Keep in mind that the more vertices the polygon has, the more CPU time it will
362362
take to calculate the bounding box.
363363

364-
.. ## Polygon.get_bounding_box ##
364+
.. ## Polygon.as_rect ##
365365
366366
.. method:: scale
367367

geometry.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class Polygon:
245245
@overload
246246
def collidepoint(self, point: Coordinate) -> bool: ...
247247
def collideline(self, line: LineValue, only_edges: bool = False) -> bool: ...
248-
def get_bounding_box(self) -> Rect: ...
248+
def as_rect(self) -> Rect: ...
249249
def is_convex(self) -> bool: ...
250250
@overload
251251
def collidecircle(self, polygon: CircleValue, only_edges: bool = False) -> bool: ...

src_c/polygon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ pg_polygon_rotate_ip(pgPolygonObject *self, PyObject *const *args,
11191119
}
11201120

11211121
static PyObject *
1122-
pg_polygon_get_bounding_box(pgPolygonObject *self, PyObject *_null)
1122+
pg_polygon_as_rect(pgPolygonObject *self, PyObject *_null)
11231123
{
11241124
/* Return a Rect object that is the smallest rectangle that contains
11251125
the polygon. */
@@ -1313,7 +1313,7 @@ static struct PyMethodDef pg_polygon_methods[] = {
13131313
{"collideline", (PyCFunction)pg_polygon_collideline, METH_FASTCALL, NULL},
13141314
{"collidecircle", (PyCFunction)pg_polygon_collidecircle, METH_FASTCALL,
13151315
NULL},
1316-
{"get_bounding_box", (PyCFunction)pg_polygon_get_bounding_box, METH_NOARGS,
1316+
{"as_rect", (PyCFunction)pg_polygon_as_rect, METH_NOARGS,
13171317
NULL},
13181318
{"is_convex", (PyCFunction)pg_polygon_is_convex, METH_NOARGS, NULL},
13191319
{"__copy__", (PyCFunction)pg_polygon_copy, METH_NOARGS, NULL},

test/test_polygon.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,11 +1531,11 @@ def test_assign_vertices_center_Vector2(self):
15311531

15321532
self.assertEqual((2.5, 2.5), poly.center)
15331533

1534-
def test_get_bounding_box_horizontal_line(self):
1534+
def test_as_rect_horizontal_line(self):
15351535
vertices = [(0, 0), (1, 0), (2, 0), (3, 0)]
15361536
poly = Polygon(vertices)
15371537

1538-
bounding_box = poly.get_bounding_box()
1538+
bounding_box = poly.as_rect()
15391539
expected_bounding_box = _calculate_bounding_box(vertices)
15401540

15411541
self.assertTrue(bounding_box.width > 0)
@@ -1545,11 +1545,11 @@ def test_get_bounding_box_horizontal_line(self):
15451545
for vertex in vertices:
15461546
self.assertTrue(bounding_box.collidepoint(vertex))
15471547

1548-
def test_get_bounding_box_vertical_line(self):
1548+
def test_as_rect_vertical_line(self):
15491549
vertices = [(0, 0), (0, 1), (0, 2), (0, 3)]
15501550
poly = Polygon(vertices)
15511551

1552-
bounding_box = poly.get_bounding_box()
1552+
bounding_box = poly.as_rect()
15531553
expected_bounding_box = _calculate_bounding_box(vertices)
15541554

15551555
self.assertTrue(bounding_box.width > 0)
@@ -1559,11 +1559,11 @@ def test_get_bounding_box_vertical_line(self):
15591559
for vertex in vertices:
15601560
self.assertTrue(bounding_box.collidepoint(vertex))
15611561

1562-
def test_get_bounding_box_square(self):
1562+
def test_as_rect_square(self):
15631563
vertices = [(0, 0), (0, 1), (1, 1), (1, 0)]
15641564
poly = Polygon(vertices)
15651565

1566-
bounding_box = poly.get_bounding_box()
1566+
bounding_box = poly.as_rect()
15671567
expected_bounding_box = _calculate_bounding_box(vertices)
15681568

15691569
self.assertTrue(bounding_box.width > 0)
@@ -1573,11 +1573,11 @@ def test_get_bounding_box_square(self):
15731573
for vertex in vertices:
15741574
self.assertTrue(bounding_box.collidepoint(vertex))
15751575

1576-
def test_get_bounding_box_diagonal_line(self):
1576+
def test_as_rect_diagonal_line(self):
15771577
vertices = [(0, 0), (1, 1), (2, 2), (3, 3)]
15781578
poly = Polygon(vertices)
15791579

1580-
bounding_box = poly.get_bounding_box()
1580+
bounding_box = poly.as_rect()
15811581
expected_bounding_box = _calculate_bounding_box(vertices)
15821582

15831583
self.assertTrue(bounding_box.width > 0)
@@ -1587,11 +1587,11 @@ def test_get_bounding_box_diagonal_line(self):
15871587
for vertex in vertices:
15881588
self.assertTrue(bounding_box.collidepoint(vertex))
15891589

1590-
def test_get_bounding_box_negative_positions(self):
1590+
def test_as_rect_negative_positions(self):
15911591
vertices = [(0.5, 0.5), (-0.5, -0.5), (1.5, 1.5), (-1.5, -1.5)]
15921592
poly = Polygon(vertices)
15931593

1594-
bounding_box = poly.get_bounding_box()
1594+
bounding_box = poly.as_rect()
15951595
expected_bounding_box = _calculate_bounding_box(vertices)
15961596

15971597
self.assertTrue(bounding_box.width > 0)
@@ -1601,13 +1601,13 @@ def test_get_bounding_box_negative_positions(self):
16011601
for vertex in vertices:
16021602
self.assertTrue(bounding_box.collidepoint(vertex))
16031603

1604-
def test_get_bounding_box_nonsimple_random_positions(self):
1604+
def test_as_rect_nonsimple_random_positions(self):
16051605
vertices = []
16061606
for i in range(1000):
16071607
vertices.append((random.uniform(-100, 100), random.uniform(-100, 100)))
16081608
poly = Polygon(vertices)
16091609

1610-
bounding_box = poly.get_bounding_box()
1610+
bounding_box = poly.as_rect()
16111611
expected_bounding_box = _calculate_bounding_box(vertices)
16121612

16131613
self.assertTrue(bounding_box.width > 0)
@@ -1617,18 +1617,18 @@ def test_get_bounding_box_nonsimple_random_positions(self):
16171617
for vertex in vertices:
16181618
self.assertTrue(bounding_box.collidepoint(vertex))
16191619

1620-
def test_get_bounding_box_return_type(self):
1621-
"""Tests whether the get_bounding_box method returns a Rect."""
1620+
def test_as_rect_return_type(self):
1621+
"""Tests whether the as_rect method returns a Rect."""
16221622
poly = Polygon(_some_vertices.copy())
1623-
self.assertIsInstance(poly.get_bounding_box(), Rect)
1623+
self.assertIsInstance(poly.as_rect(), Rect)
16241624

1625-
def test_get_bounding_box_argnum(self):
1626-
"""Tests whether the get_bounding_box method correctly handles invalid parameter
1625+
def test_as_rect_argnum(self):
1626+
"""Tests whether the as_rect method correctly handles invalid parameter
16271627
numbers."""
16281628
poly = Polygon(_some_vertices.copy())
16291629

16301630
with self.assertRaises(TypeError):
1631-
poly.get_bounding_box(1)
1631+
poly.as_rect(1)
16321632

16331633
def test_assign_subscript(self):
16341634
"""Tests whether assigning to a subscript works correctly."""

0 commit comments

Comments
 (0)