11#include "doc/geometry_doc.h"
22#include "geometry_common.h"
3+ #include "methodobject.h"
4+ #include "pytypedefs.h"
35
46static double
57pgLine_Length (pgLineBase * line )
@@ -179,27 +181,6 @@ _line_scale_helper(pgLineBase *line, double factor, double origin)
179181 return 1 ;
180182}
181183
182- void
183- _normalize_vector (double * vector )
184- {
185- double length = sqrt (vector [0 ] * vector [0 ] + vector [1 ] * vector [1 ]);
186- // check to see if the vector is zero
187- if (length == 0 ) {
188- vector [0 ] = 0 ;
189- vector [1 ] = 0 ;
190- }
191- else {
192- vector [0 ] /= length ;
193- vector [1 ] /= length ;
194- }
195- }
196-
197- double
198- _length_of_vector (double * vector )
199- {
200- return sqrt (vector [0 ] * vector [0 ] + vector [1 ] * vector [1 ]);
201- }
202-
203184static PyObject *
204185_line_project_helper (pgLineBase * line , double * point , int clamp )
205186{
@@ -281,21 +262,25 @@ pg_line_scale_ip(pgLineObject *self, PyObject *const *args, Py_ssize_t nargs)
281262}
282263
283264static PyObject *
284- pg_line_project (pgLineObject * self , PyObject * const * args , Py_ssize_t nargs ,
285- PyObject * kwnames )
265+ pg_line_project (pgLineObject * self , PyObject * args , PyObject * kwnames )
286266{
287267 double point [2 ] = {0.f , 0.f };
288268 int clamp = 0 ;
289269
290- if (nargs >= 1 ) {
291- if (!pg_TwoDoublesFromObj (args [0 ], & point [0 ], & point [1 ])) {
292- return RAISE (PyExc_TypeError ,
293- "project requires a sequence of two numbers" );
294- }
270+ PyObject * point_obj = NULL ;
271+
272+ static char * kwlist [] = {"point" , "clamp" , NULL };
273+
274+ if (!PyArg_ParseTupleAndKeywords (args , kwnames , "O|p:project" , kwlist ,
275+ & point_obj , & clamp )) {
276+ return RAISE (
277+ PyExc_TypeError ,
278+ "project requires a sequence(point) and an optional clamp flag" );
295279 }
296280
297- if (kwnames != NULL ) {
298- clamp = PyObject_IsTrue (args [nargs ]);
281+ if (!pg_TwoDoublesFromObj (point_obj , & point [0 ], & point [1 ])) {
282+ return RAISE (PyExc_TypeError ,
283+ "project requires a sequence of two numbers" );
299284 }
300285
301286 PyObject * projected_point ;
@@ -319,7 +304,7 @@ static struct PyMethodDef pg_line_methods[] = {
319304 {"scale" , (PyCFunction )pg_line_scale , METH_FASTCALL , DOC_LINE_SCALE },
320305 {"scale_ip" , (PyCFunction )pg_line_scale_ip , METH_FASTCALL ,
321306 DOC_LINE_SCALEIP },
322- {"project" , (PyCFunction )pg_line_project , METH_FASTCALL | METH_KEYWORDS ,
307+ {"project" , (PyCFunction )pg_line_project , METH_VARARGS | METH_KEYWORDS ,
323308 DOC_LINE_PROJECT },
324309 {NULL , NULL , 0 , NULL }};
325310
0 commit comments