diff options
author | Willian Padovani Germano <wpgermano@gmail.com> | 2005-05-25 08:52:52 +0400 |
---|---|---|
committer | Willian Padovani Germano <wpgermano@gmail.com> | 2005-05-25 08:52:52 +0400 |
commit | 2a1fe1b0cbbb45cbec7d9864ad79b1b321880da0 (patch) | |
tree | 098787ab375a550fd606ff7965a13d3e5b0960e7 /source/blender/python/api2_2x/Mathutils.c | |
parent | 524e411dbfce7702c270a590c78aba4012f66666 (diff) |
BPython bug fixes:
- Patch #2491: Mathutils.AngleBetweenVecs BUGFIX
http://projects.blender.org/tracker/?func=detail&aid=2491&group_id=9&atid=127
- #2607: Python String button can segfault if the allowable length is greater than 400
http://projects.blender.org/tracker/?func=detail&atid=125&aid=2607&group_id=9
- #2490: Vector == None gives warning
http://projects.blender.org/tracker/?func=detail&aid=2490&group_id=9&atid=125
- #2476: Image.Draw()
http://projects.blender.org/tracker/?func=detail&aid=2476&group_id=9&atid=125
All reported by Campbell, who also wrote the #2491 patch. Ken Hughes provided patches for #2490 and #2476. Thanks guys.
Diffstat (limited to 'source/blender/python/api2_2x/Mathutils.c')
-rw-r--r-- | source/blender/python/api2_2x/Mathutils.c | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/source/blender/python/api2_2x/Mathutils.c b/source/blender/python/api2_2x/Mathutils.c index 910b1587974..8c8a69f7a1d 100644 --- a/source/blender/python/api2_2x/Mathutils.c +++ b/source/blender/python/api2_2x/Mathutils.c @@ -25,7 +25,7 @@ * * This is a new part of Blender. * - * Contributor(s): Joseph Gilbert + * Contributor(s): Joseph Gilbert, Campbell Barton * * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ @@ -369,8 +369,19 @@ static PyObject *M_Mathutils_DotVecs( PyObject * self, PyObject * args ) static PyObject *M_Mathutils_AngleBetweenVecs( PyObject * self, PyObject * args ) { + // original vectors, makea copy of these VectorObject *vec1; VectorObject *vec2; + + /* copy of the 2 input vectors, these can be normalized + without input vectors being normalized. bugfix + no need to use vector objects, just use floats + No Chance of 4D vectors getting in. + + Use doubles, since floats will return nan when input vecs are large.*/ + double vec1copy[3]; + double vec2copy[3]; + float norm; double dot, angleRads; int x; @@ -386,30 +397,43 @@ static PyObject *M_Mathutils_AngleBetweenVecs( PyObject * self, if( vec1->size > 3 || vec2->size > 3 ) return ( EXPP_ReturnPyObjError( PyExc_TypeError, "only 2D,3D vectors are supported\n" ) ); - - //normalize vec1 + + /* Check for 2 vectors being the same */ + if (vec1->size == 3 && + vec1->vec[0] == vec2->vec[0] && + vec1->vec[1] == vec2->vec[1] && + vec1->vec[2] == vec2->vec[2]) + return PyFloat_FromDouble( dot ); /* 2 points are the same, return zero */ + else if (vec1->size == 2 && + vec1->vec[0] == vec2->vec[0] && + vec1->vec[1] == vec2->vec[1]) + return PyFloat_FromDouble( dot ); /* 2 points are the same, return zero */ + + //normalize vec1copy norm = 0.0f; for( x = 0; x < vec1->size; x++ ) { - norm += vec1->vec[x] * vec1->vec[x]; + vec1copy[x] = vec1->vec[x]; /* Assign new vector in the loop */ + norm += vec1copy[x] * vec1copy[x]; } norm = ( float ) sqrt( norm ); for( x = 0; x < vec1->size; x++ ) { - vec1->vec[x] /= norm; + vec1copy[x] /= norm; } - //normalize vec2 + //normalize vec2copy norm = 0.0f; for( x = 0; x < vec2->size; x++ ) { - norm += vec2->vec[x] * vec2->vec[x]; + vec2copy[x] = vec2->vec[x]; /* Assign new vector in the loop */ + norm += vec2copy[x] * vec2copy[x]; } norm = ( float ) sqrt( norm ); for( x = 0; x < vec2->size; x++ ) { - vec2->vec[x] /= norm; + vec2copy[x] /= norm; } //dot product for( x = 0; x < vec1->size; x++ ) { - dot += vec1->vec[x] * vec2->vec[x]; + dot += vec1copy[x] * vec2copy[x]; } //I believe saacos checks to see if the vectors are normalized |