Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/python/mathutils/mathutils_Vector.c')
-rw-r--r--source/blender/python/mathutils/mathutils_Vector.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c
index 68a070ef428..19246978cbf 100644
--- a/source/blender/python/mathutils/mathutils_Vector.c
+++ b/source/blender/python/mathutils/mathutils_Vector.c
@@ -855,30 +855,36 @@ PyDoc_STRVAR(Vector_cross_doc,
" :arg other: The other vector to perform the cross product with.\n"
" :type other: :class:`Vector`\n"
" :return: The cross product.\n"
-" :rtype: :class:`Vector`\n"
+" :rtype: :class:`Vector` or float when 2D vectors are used\n"
"\n"
-" .. note:: both vectors must be 3D\n"
+" .. note:: both vectors must be 2D or 3D\n"
);
static PyObject *Vector_cross(VectorObject *self, PyObject *value)
{
- VectorObject *ret;
- float tvec[MAX_DIMENSIONS];
+ PyObject *ret;
+ float tvec[3];
if (BaseMath_ReadCallback(self) == -1)
return NULL;
- if (mathutils_array_parse(tvec, self->size, self->size, value, "Vector.cross(other), invalid 'other' arg") == -1)
- return NULL;
-
- if (self->size != 3) {
+ if (self->size > 3) {
PyErr_SetString(PyExc_ValueError,
- "Vector must be 3D");
+ "Vector must be 2D or 3D");
return NULL;
}
- ret = (VectorObject *)Vector_CreatePyObject(NULL, 3, Py_NEW, Py_TYPE(self));
- cross_v3_v3v3(ret->vec, self->vec, tvec);
- return (PyObject *)ret;
+ if (mathutils_array_parse(tvec, self->size, self->size, value, "Vector.cross(other), invalid 'other' arg") == -1)
+ return NULL;
+
+ if (self->size == 3) {
+ ret = Vector_CreatePyObject(NULL, 3, Py_NEW, Py_TYPE(self));
+ cross_v3_v3v3(((VectorObject *)ret)->vec, self->vec, tvec);
+ }
+ else {
+ /* size == 2 */
+ ret = PyFloat_FromDouble(cross_v2v2(self->vec, tvec));
+ }
+ return ret;
}
PyDoc_STRVAR(Vector_dot_doc,