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:
authorCampbell Barton <ideasman42@gmail.com>2014-02-05 16:32:51 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-02-05 16:36:30 +0400
commit06b6cd83459713ef5c00f705f6cdf1481ed24179 (patch)
tree6ca366756271e9bc91ebe68f757a87ddbbf1b252 /source/blender/python
parent7d4c04597ef40e5f48f5f9173fe40ba79c104df3 (diff)
PyAPI: mathutils.Vector.cross now works for 2d vectors (returns a float)
also fixed crash when running on large vectors (raises exception now)
Diffstat (limited to 'source/blender/python')
-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,