PyVector init should be pretty reliable now

This commit is contained in:
John McCardle 2024-03-31 14:21:07 -04:00
parent c13e185289
commit 5edebdd643
1 changed files with 5 additions and 13 deletions

View File

@ -56,28 +56,19 @@ int PyVector::init(PyVectorObject* self, PyObject* args, PyObject* kwds)
using namespace mcrfpydef;
static const char* keywords[] = { "x", "y", nullptr };
PyObject* leader = NULL;
double x=0, y=0;
float x=0, y=0;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Of", const_cast<char**>(keywords), &leader, &y))
{
//PyErr_SetString(PyExc_TypeError, "mcrfpy.Vector requires a 2-tuple or two numeric values");
self->data = sf::Vector2f();
return 0;
return -1;
}
else if (leader == NULL || leader == Py_None)
if (leader == NULL || leader == Py_None)
{
self->data = sf::Vector2f();
return 0;
}
// if the "r" arg is already a vector, yoink that color value
else if (PyObject_IsInstance(leader, (PyObject*)&PyVectorType))
{
self->data = ((PyVectorObject*)leader)->data;
return 0;
}
// else if the "r" arg is a 3-tuple, initialize to (r, g, b, 255)
// (if the "r" arg is a 4-tuple, initialize to (r, g, b, a))
else if (PyTuple_Check(leader))
if (PyTuple_Check(leader))
{
if (PyTuple_Size(leader) != 2)
{
@ -88,6 +79,7 @@ int PyVector::init(PyVectorObject* self, PyObject* args, PyObject* kwds)
y = PyFloat_AsDouble(PyTuple_GetItem(leader, 1));
self->data = sf::Vector2f(x, y);
return 0;
}
// else -
else if (!PyFloat_Check(leader) && !(PyLong_Check(leader)))