Skip to content

Commit 5a4acb6

Browse files
authored
Merge pull request #2731 from itzpr3d4t0r/reorganize-geometry-internals
Reorganize geometry internals
2 parents 89dfdb5 + a0b09d6 commit 5a4acb6

File tree

7 files changed

+214
-231
lines changed

7 files changed

+214
-231
lines changed

src_c/circle.c

Lines changed: 1 addition & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "geometry.h"
21
#include "doc/geometry_doc.h"
2+
#include "geometry_common.h"
33

44
static PyObject *
55
_pg_circle_subtype_new(PyTypeObject *type, pgCircleBase *circle)
@@ -27,176 +27,6 @@ _pg_circle_subtype_new3(PyTypeObject *type, double x, double y, double r)
2727
return (PyObject *)circle_obj;
2828
}
2929

30-
static int
31-
_pg_circle_set_radius(PyObject *value, pgCircleBase *circle)
32-
{
33-
double radius = 0;
34-
if (!pg_DoubleFromObj(value, &radius) || radius <= 0) {
35-
return 0;
36-
}
37-
circle->r = radius;
38-
39-
return 1;
40-
}
41-
42-
static int
43-
pgCircle_FromObject(PyObject *obj, pgCircleBase *out)
44-
{
45-
Py_ssize_t length;
46-
47-
if (pgCircle_Check(obj)) {
48-
*out = pgCircle_AsCircle(obj);
49-
return 1;
50-
}
51-
52-
/* Paths for sequences */
53-
if (pgSequenceFast_Check(obj)) {
54-
PyObject **f_arr = PySequence_Fast_ITEMS(obj);
55-
length = PySequence_Fast_GET_SIZE(obj);
56-
57-
if (length == 3) {
58-
if (!pg_DoubleFromObj(f_arr[0], &out->x) ||
59-
!pg_DoubleFromObj(f_arr[1], &out->y) ||
60-
!_pg_circle_set_radius(f_arr[2], out)) {
61-
return 0;
62-
}
63-
return 1;
64-
}
65-
else if (length == 1) {
66-
if (!pgCircle_FromObject(f_arr[0], out)) {
67-
return 0;
68-
}
69-
return 1;
70-
}
71-
else if (length == 2) {
72-
if (!pg_TwoDoublesFromObj(f_arr[0], &out->x, &out->y) ||
73-
!_pg_circle_set_radius(f_arr[1], out)) {
74-
return 0;
75-
}
76-
return 1;
77-
}
78-
else {
79-
/* Sequences of size other than 3 or 1 are not supported
80-
(don't wanna support infinite sequence nesting anymore)*/
81-
return 0;
82-
}
83-
}
84-
else if (PySequence_Check(obj)) {
85-
PyObject *tmp = NULL;
86-
length = PySequence_Length(obj);
87-
if (length == 3) {
88-
/*These are to be substituted with better pg_DoubleFromSeqIndex()
89-
* implementations*/
90-
tmp = PySequence_ITEM(obj, 0);
91-
if (!pg_DoubleFromObj(tmp, &out->x)) {
92-
Py_DECREF(tmp);
93-
return 0;
94-
}
95-
Py_DECREF(tmp);
96-
97-
tmp = PySequence_ITEM(obj, 1);
98-
if (!pg_DoubleFromObj(tmp, &out->y)) {
99-
Py_DECREF(tmp);
100-
return 0;
101-
}
102-
Py_DECREF(tmp);
103-
104-
tmp = PySequence_ITEM(obj, 2);
105-
if (!_pg_circle_set_radius(tmp, out)) {
106-
Py_DECREF(tmp);
107-
return 0;
108-
}
109-
Py_DECREF(tmp);
110-
111-
return 1;
112-
}
113-
else if (length == 2) {
114-
tmp = PySequence_ITEM(obj, 0);
115-
if (!pg_TwoDoublesFromObj(tmp, &out->x, &out->y)) {
116-
Py_DECREF(tmp);
117-
return 0;
118-
}
119-
Py_DECREF(tmp);
120-
121-
tmp = PySequence_ITEM(obj, 1);
122-
if (!_pg_circle_set_radius(tmp, out)) {
123-
Py_DECREF(tmp);
124-
return 0;
125-
}
126-
Py_DECREF(tmp);
127-
128-
return 1;
129-
}
130-
else if (length == 1) {
131-
tmp = PySequence_ITEM(obj, 0);
132-
if (PyUnicode_Check(obj) || !pgCircle_FromObject(tmp, out)) {
133-
Py_DECREF(tmp);
134-
return 0;
135-
}
136-
Py_DECREF(tmp);
137-
return 1;
138-
}
139-
else {
140-
/* Sequences of size other than 3 or 1 are not supported
141-
(don't wanna support infinite sequence nesting anymore)*/
142-
return 0;
143-
}
144-
}
145-
146-
/* Path for objects that have a circle attribute */
147-
PyObject *circleattr;
148-
if (!(circleattr = PyObject_GetAttrString(obj, "circle"))) {
149-
PyErr_Clear();
150-
return 0;
151-
}
152-
153-
if (PyCallable_Check(circleattr)) /*call if it's a method*/
154-
{
155-
PyObject *circleresult = PyObject_CallObject(circleattr, NULL);
156-
Py_DECREF(circleattr);
157-
if (!circleresult) {
158-
PyErr_Clear();
159-
return 0;
160-
}
161-
circleattr = circleresult;
162-
}
163-
164-
if (!pgCircle_FromObject(circleattr, out)) {
165-
PyErr_Clear();
166-
Py_DECREF(circleattr);
167-
return 0;
168-
}
169-
170-
Py_DECREF(circleattr);
171-
172-
return 1;
173-
}
174-
175-
static int
176-
pgCircle_FromObjectFastcall(PyObject *const *args, Py_ssize_t nargs,
177-
pgCircleBase *out)
178-
{
179-
if (nargs == 1) {
180-
return pgCircle_FromObject(args[0], out);
181-
}
182-
else if (nargs == 2) {
183-
if (!pg_TwoDoublesFromObj(args[0], &out->x, &out->y) ||
184-
!_pg_circle_set_radius(args[1], out)) {
185-
return 0;
186-
}
187-
return 1;
188-
}
189-
else if (nargs == 3) {
190-
if (!pg_DoubleFromObj(args[0], &out->x) ||
191-
!pg_DoubleFromObj(args[1], &out->y) ||
192-
!_pg_circle_set_radius(args[2], out)) {
193-
return 0;
194-
}
195-
return 1;
196-
}
197-
return 0;
198-
}
199-
20030
static PyObject *
20131
pg_circle_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
20232
{

src_c/collisions.c

Lines changed: 0 additions & 35 deletions
This file was deleted.

src_c/collisions.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

src_c/geometry.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#include "geometry.h"
2-
#include "collisions.c"
31
#include "circle.c"
2+
#include "geometry_common.c"
43

54
static PyMethodDef geometry_methods[] = {{NULL, NULL, 0, NULL}};
65

src_c/geometry.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ typedef struct {
2121
#define pgCircle_Check(o) ((o)->ob_type == &pgCircle_Type)
2222

2323
static PyTypeObject pgCircle_Type;
24-
25-
static int
26-
pgCircle_FromObject(PyObject *obj, pgCircleBase *out);
27-
28-
static int
29-
pgCircle_FromObjectFastcall(PyObject *const *args, Py_ssize_t nargs,
30-
pgCircleBase *out);
3124
/* Constants */
3225

3326
/* PI */

0 commit comments

Comments
 (0)