Skip to content

Commit ae97262

Browse files
authored
Merge pull request #209 from pygame-community/align_object_attributes
Align attributes across objects
2 parents 46cc666 + a1db509 commit ae97262

File tree

14 files changed

+250
-243
lines changed

14 files changed

+250
-243
lines changed

benchmarks/GEOMETRY_polygon_benchmark.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def polygon(self):
7272
("verts_num 3", "po3.verts_num"),
7373
("vertices 4", "po4.vertices"),
7474
("verts_num 4", "po4.verts_num"),
75-
("c_x 3", "po3.c_x"),
76-
("c_y 3", "po3.c_y"),
77-
("c_x 4", "po4.c_x"),
78-
("c_y 4", "po4.c_y"),
75+
("centerx 3", "po3.centerx"),
76+
("centery 3", "po3.centery"),
77+
("centerx 4", "po4.centerx"),
78+
("centery 4", "po4.centery"),
7979
("center 3", "po3.center"),
8080
("center 4", "po4.center"),
8181
("perimeter 3", "po3.perimeter"),
@@ -88,10 +88,10 @@ def polygon(self):
8888
# ("vertices float", "po4.vertices = [p1_f, p2_f, p3_f, p4_f]"),
8989
("center int", "po4.center = p1_i"),
9090
("center float", "po4.center = p1_f"),
91-
("c_x int", "po4.c_x = 50"),
92-
("c_y int", "po4.c_y = 50"),
93-
("c_x float", "po4.c_x = 50.0"),
94-
("c_y float", "po4.c_y = 50.0"),
91+
("centerx int", "po4.centerx = 50"),
92+
("centery int", "po4.centery = 50"),
93+
("centerx float", "po4.centerx = 50.0"),
94+
("centery float", "po4.centery = 50.0"),
9595
]
9696

9797
copy_tests = [

docs/geometry.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ other objects.
8888

8989
angle: The angle of the line.
9090

91-
midpoint: The midpoint of the line.
91+
center: The center of the line.
9292

93-
midpoint_x: The x coordinate of the midpoint of the line.
93+
centerx: The x coordinate of the center of the line.
9494

95-
midpoint_y: The y coordinate of the midpoint of the line.
95+
centery: The y coordinate of the center of the line.
9696

9797
slope: The slope of the line.
9898

@@ -160,9 +160,9 @@ other objects.
160160

161161
center: The center point of the polygon.
162162

163-
c_x: The x coordinate of the center of the polygon.
163+
centerx: The x coordinate of the center of the polygon.
164164

165-
c_y: The y coordinate of the center of the polygon.
165+
centery: The y coordinate of the center of the polygon.
166166

167167
perimeter: The perimeter of the polygon.
168168

docs/line.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,32 +111,32 @@ Line Attributes
111111
This attribute is read-only, it cannot be reassigned. To change the line's slope
112112
use the `rotate` method or change its `a` or `b` attributes.
113113

114-
.. attribute:: midpoint
114+
.. attribute:: center
115115
| :sl:`the coordinate of the middle point of the line`
116-
| :sg:`midpoint -> (float, float)`
116+
| :sg:`center -> (float, float)`
117117
118-
The midpoint of the line. Calculated using the `((x1 + x2) / 2, (y1 + y2) / 2)` formula.
118+
The center of the line. Calculated using the `((x1 + x2) / 2, (y1 + y2) / 2)` formula.
119119
It can be reassigned to move the `Line`. If reassigned the `x1`, `y1`, `x2`, `y2`
120-
attributes will be changed in order to produce a `Line` with matching midpoint.
120+
attributes will be changed in order to produce a `Line` with matching center.
121121

122-
.. attribute:: midpoint_x
122+
.. attribute:: centerx
123123
| :sl:`the x coordinate of the middle point of the line`
124-
| :sg:`midpoint_x -> float`
124+
| :sg:`centerx -> float`
125125
126-
The `x` coordinate of the midpoint of the line, it's calculated using
126+
The `x` coordinate of the center of the line, it's calculated using
127127
the `((x1 + x2) / 2)` formula. It can be reassigned to move the `Line`.
128128
If reassigned the `x1` and `x2` attributes will be changed in order to
129-
produce a `Line` with matching midpoint. The `y1` and `y2` attributes will not
129+
produce a `Line` with matching center. The `y1` and `y2` attributes will not
130130
be affected.
131131

132-
.. attribute:: midpoint_y
132+
.. attribute:: centery
133133
| :sl:`the y coordinate of the middle point of the line`
134-
| :sg:`midpoint_y -> float`
134+
| :sg:`centery -> float`
135135
136-
The `y` coordinate of the midpoint of the `Line`, it's calculated using
136+
The `y` coordinate of the center of the `Line`, it's calculated using
137137
the `((y1 + y2) / 2)` formula. It can be reassigned to move the `Line`.
138138
If reassigned the `y1` and `y2` attributes will be changed in order to
139-
produce a `Line` with matching midpoint. The `x1` and `x2` attributes will not
139+
produce a `Line` with matching center. The `x1` and `x2` attributes will not
140140
be affected.
141141

142142
Line Methods
@@ -220,7 +220,7 @@ Line Methods
220220
| :sg:`scale(factor_and_origin) -> Line`
221221
222222
Returns a new `Line` which is scaled by the given factor from the specified origin with 0.0 being
223-
the startpoint, 0.5 being the midpoint and 1.0 being the end point.
223+
the startpoint, 0.5 being the center and 1.0 being the end point.
224224
The original `Line` is not modified.
225225

226226
.. ## Line.scale ##
@@ -232,7 +232,7 @@ Line Methods
232232
| :sg:`scale_ip(factor_and_origin) -> None`
233233
234234
Scales the `Line` by the given factor from the specified origin with 0.0 being
235-
the startpoint, 0.5 being the midpoint and 1.0 being the end point.
235+
the startpoint, 0.5 being the center and 1.0 being the end point.
236236
The original `Line` is modified.
237237

238238
.. ## Line.scale_ip ##

docs/polygon.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@ Polygon Attributes
7979
move the `Polygon`. If reassigned, the `Polygon`'s vertices will be moved to
8080
create a `Polygon` with matching center.
8181

82-
.. attribute:: c_x
82+
.. attribute:: centerx
8383
| :sl:`the x coordinate of the center of the polygon`
84-
| :sg:`c_x -> float`
84+
| :sg:`centerx -> float`
8585
8686
It's the x coordinate of the center of the `Polygon`. It is calculated as the
8787
average of all the x coordinates of the vertices. It can be reassigned to move
8888
the `Polygon`. If reassigned, the polygon's vertices will be moved to
8989
create a `Polygon` with matching center.
9090

91-
.. attribute:: c_y
91+
.. attribute:: centery
9292
| :sl:`the y coordinate of the center of the polygon`
93-
| :sg:`c_y -> float`
93+
| :sg:`centery -> float`
9494
9595
It's the y coordinate of the center of the `Polygon`. It is calculated as the
9696
average of all the y coordinates of the vertices. It can be reassigned to move

examples/polygon_line_collision.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from geometry import Line, regular_polygon
66

77

8-
# using this because we're missing line.rotate(), rotates a line around its midpoint
8+
# using this because we're missing line.rotate(), rotates a line around its center
99
def rotate_line(line, d_ang):
1010
angle = radians(d_ang)
1111
ca, sa = cos(angle), sin(angle)
12-
xm, ym = line.midpoint
12+
xm, ym = line.center
1313
ax, ay = line.a
1414
bx, by = line.b
1515
ax -= xm
@@ -64,7 +64,7 @@ def rotate_line(line, d_ang):
6464
while running:
6565
delta = (clock.tick(FPS) / 1000) * 60
6666

67-
line.midpoint = pygame.mouse.get_pos()
67+
line.center = pygame.mouse.get_pos()
6868

6969
colliding = line.collidepolygon(polygon, only_edges)
7070
# Alternative:

geometry.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ class Line(Sequence[float]):
5454
a: Tuple[float, float]
5555
b: Tuple[float, float]
5656
length: float
57-
midpoint: Tuple[float, float]
58-
midpoint_x: float
59-
midpoint_y: float
57+
center: Tuple[float, float]
58+
centerx: float
59+
centery: float
6060
slope: float
6161
__safe_for_unpickling__: Literal[True]
6262
__hash__: None # type: ignore
@@ -205,8 +205,8 @@ class Polygon:
205205
vertices: List[Coordinate]
206206
verts_num: int
207207
perimeter: float
208-
c_x: float
209-
c_y: float
208+
centerx: float
209+
centery: float
210210
center: Tuple[float, float]
211211
__safe_for_unpickling__: Literal[True]
212212
__hash__: None # type: ignore

src_c/geometry.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ geometry_regular_polygon(PyObject *_null, PyObject *const *args,
257257

258258
ret->polygon.vertices = vertices;
259259
ret->polygon.verts_num = sides;
260-
ret->polygon.c_x = Cx;
261-
ret->polygon.c_y = Cy;
260+
ret->polygon.centerx = Cx;
261+
ret->polygon.centery = Cy;
262262

263263
return (PyObject *)ret;
264264
}

src_c/include/geometry.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static PyTypeObject pgPolygon_Type;
6363
typedef struct {
6464
Py_ssize_t verts_num;
6565
double *vertices;
66-
double c_x, c_y;
66+
double centerx, centery;
6767
} pgPolygonBase;
6868

6969
typedef struct {
@@ -75,8 +75,8 @@ typedef struct {
7575
#define pgPolygon_AsPolygon(o) (pgPolygon_CAST(o)->polygon)
7676
#define pgPolygon_GETVERTICES(o) (pgPolygon_AsPolygon(o).vertices)
7777
#define pgPolygon_GETVERTSNUM(o) (pgPolygon_AsPolygon(o).verts_num)
78-
#define pgPolygon_GETCENTER_X(o) (pgPolygon_AsPolygon(o).c_x)
79-
#define pgPolygon_GETCENTER_Y(o) (pgPolygon_AsPolygon(o).c_y)
78+
#define pgPolygon_GETCENTER_X(o) (pgPolygon_AsPolygon(o).centerx)
79+
#define pgPolygon_GETCENTER_Y(o) (pgPolygon_AsPolygon(o).centery)
8080

8181
// return 1 if success and 0 if failure
8282
static int

src_c/line.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,21 +1236,21 @@ pg_line_getsafepickle(pgLineObject *self, void *closure)
12361236
}
12371237

12381238
static PyObject *
1239-
pg_line_get_midpoint(pgLineObject *self, void *closure)
1239+
pg_line_get_center(pgLineObject *self, void *closure)
12401240
{
12411241
return pg_TupleFromDoublePair((self->line.x1 + self->line.x2) / 2,
12421242
(self->line.y1 + self->line.y2) / 2);
12431243
}
12441244

12451245
static int
1246-
pg_line_set_midpoint(pgLineObject *self, PyObject *value, void *closure)
1246+
pg_line_set_center(pgLineObject *self, PyObject *value, void *closure)
12471247
{
12481248
double m_x, m_y;
12491249
DEL_ATTR_NOT_SUPPORTED_CHECK_NO_NAME(value);
12501250
if (!pg_TwoDoublesFromObj(value, &m_x, &m_y)) {
12511251
PyErr_SetString(
12521252
PyExc_TypeError,
1253-
"Invalid midpoint value, expected a sequence of 2 numbers");
1253+
"Invalid center value, expected a sequence of 2 numbers");
12541254
return -1;
12551255
}
12561256

@@ -1266,19 +1266,19 @@ pg_line_set_midpoint(pgLineObject *self, PyObject *value, void *closure)
12661266
}
12671267

12681268
static PyObject *
1269-
pg_line_get_midpoint_x(pgLineObject *self, void *closure)
1269+
pg_line_get_centerx(pgLineObject *self, void *closure)
12701270
{
12711271
return PyFloat_FromDouble((self->line.x1 + self->line.x2) / 2);
12721272
}
12731273

12741274
static int
1275-
pg_line_set_midpoint_x(pgLineObject *self, PyObject *value, void *closure)
1275+
pg_line_set_centerx(pgLineObject *self, PyObject *value, void *closure)
12761276
{
12771277
double m_x;
12781278
DEL_ATTR_NOT_SUPPORTED_CHECK_NO_NAME(value);
12791279
if (!pg_DoubleFromObj(value, &m_x)) {
12801280
PyErr_SetString(PyExc_TypeError,
1281-
"Invalid midpoint_x value, expected a numeric value");
1281+
"Invalid centerx value, expected a numeric value");
12821282
return -1;
12831283
}
12841284

@@ -1289,19 +1289,19 @@ pg_line_set_midpoint_x(pgLineObject *self, PyObject *value, void *closure)
12891289
}
12901290

12911291
static PyObject *
1292-
pg_line_get_midpoint_y(pgLineObject *self, void *closure)
1292+
pg_line_get_centery(pgLineObject *self, void *closure)
12931293
{
12941294
return PyFloat_FromDouble((self->line.y1 + self->line.y2) / 2);
12951295
}
12961296

12971297
static int
1298-
pg_line_set_midpoint_y(pgLineObject *self, PyObject *value, void *closure)
1298+
pg_line_set_centery(pgLineObject *self, PyObject *value, void *closure)
12991299
{
13001300
double m_y;
13011301
DEL_ATTR_NOT_SUPPORTED_CHECK_NO_NAME(value);
13021302
if (!pg_DoubleFromObj(value, &m_y)) {
13031303
PyErr_SetString(PyExc_TypeError,
1304-
"Invalid midpoint_y value, expected a numeric value");
1304+
"Invalid centery value, expected a numeric value");
13051305
return -1;
13061306
}
13071307

@@ -1320,12 +1320,12 @@ static PyGetSetDef pg_line_getsets[] = {
13201320
{"b", (getter)pg_line_getb, (setter)pg_line_setb, NULL, NULL},
13211321
{"length", (getter)pg_line_getlength, NULL, NULL, NULL},
13221322
{"slope", (getter)pg_line_getslope, NULL, NULL, NULL},
1323-
{"midpoint", (getter)pg_line_get_midpoint, (setter)pg_line_set_midpoint,
1323+
{"center", (getter)pg_line_get_center, (setter)pg_line_set_center,
13241324
NULL, NULL},
1325-
{"midpoint_x", (getter)pg_line_get_midpoint_x,
1326-
(setter)pg_line_set_midpoint_x, NULL, NULL},
1327-
{"midpoint_y", (getter)pg_line_get_midpoint_y,
1328-
(setter)pg_line_set_midpoint_y, NULL, NULL},
1325+
{"centerx", (getter)pg_line_get_centerx,
1326+
(setter)pg_line_set_centerx, NULL, NULL},
1327+
{"centery", (getter)pg_line_get_centery,
1328+
(setter)pg_line_set_centery, NULL, NULL},
13291329
{"angle", (getter)pg_line_getangle, NULL, NULL, NULL},
13301330
{"__safe_for_unpickling__", (getter)pg_line_getsafepickle, NULL, NULL,
13311331
NULL},

0 commit comments

Comments
 (0)