|
1 | | -#include "geometry.h" |
2 | 1 | #include "doc/geometry_doc.h" |
| 2 | +#include "geometry_common.h" |
3 | 3 |
|
4 | 4 | static PyObject * |
5 | 5 | _pg_circle_subtype_new(PyTypeObject *type, pgCircleBase *circle) |
@@ -27,176 +27,6 @@ _pg_circle_subtype_new3(PyTypeObject *type, double x, double y, double r) |
27 | 27 | return (PyObject *)circle_obj; |
28 | 28 | } |
29 | 29 |
|
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 | | - |
200 | 30 | static PyObject * |
201 | 31 | pg_circle_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
202 | 32 | { |
|
0 commit comments