[Bf-blender-cvs] [6912fe1] master: mathutils: let Vector.normalize() return the original length.
Sybren A. Stüvel
noreply at git.blender.org
Thu Jan 29 15:30:41 CET 2015
Commit: 6912fe132fbd37422ab62938cf2e823821cbbb2a
Author: Sybren A. Stüvel
Date: Thu Jan 29 14:47:20 2015 +0100
Branches: master
https://developer.blender.org/rB6912fe132fbd37422ab62938cf2e823821cbbb2a
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).
===================================================================
M source/blender/python/mathutils/mathutils_Vector.c
===================================================================
diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c
index 167fb5b..640a335 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"
More information about the Bf-blender-cvs
mailing list