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:
authorSybren A. Stüvel <sybren@stuvel.eu>2015-01-29 16:47:20 +0300
committerSybren A. Stüvel <sybren@stuvel.eu>2015-01-29 17:29:01 +0300
commit6912fe132fbd37422ab62938cf2e823821cbbb2a (patch)
tree27cd414be29ebaf2ac150ece9e9e693cc8652057 /source/blender/python/mathutils/mathutils_Vector.c
parent4a99c1ad759b30fbd35e3a81581e88c5b0faf366 (diff)
mathutils: let Vector.normalize() return the original length.
The length has to be calculated for normalization anyway, and it is already returned by normalize_vn(vec, size).
Diffstat (limited to 'source/blender/python/mathutils/mathutils_Vector.c')
-rw-r--r--source/blender/python/mathutils/mathutils_Vector.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c
index 167fb5bcf3d..640a3358386 100644
--- a/source/blender/python/mathutils/mathutils_Vector.c
+++ b/source/blender/python/mathutils/mathutils_Vector.c
@@ -349,6 +349,9 @@ PyDoc_STRVAR(Vector_normalize_doc,
"\n"
" Normalize the vector, making the length of the vector always 1.0.\n"
"\n"
+" :return: the original length of the vector, before normalization\n"
+" :rtype: float\n"
+"\n"
" .. warning:: Normalizing a vector where all values are zero has no effect.\n"
"\n"
" .. note:: Normalize works for vectors of all sizes,\n"
@@ -356,14 +359,15 @@ PyDoc_STRVAR(Vector_normalize_doc,
);
static PyObject *Vector_normalize(VectorObject *self)
{
+ float length;
int size = (self->size == 4 ? 3 : self->size);
if (BaseMath_ReadCallback(self) == -1)
return NULL;
- normalize_vn(self->vec, size);
+ length = normalize_vn(self->vec, size);
(void)BaseMath_WriteCallback(self);
- Py_RETURN_NONE;
+ return PyFloat_FromDouble(length);
}
PyDoc_STRVAR(Vector_normalized_doc,
".. method:: normalized()\n"