Bug fix #3671: Blender.Beztriple.New() did not accept sequences as parameters,
authorKen Hughes <khughes@pacific.edu>
Sun, 1 Jan 2006 15:50:53 +0000 (15:50 +0000)
committerKen Hughes <khughes@pacific.edu>
Sun, 1 Jan 2006 15:50:53 +0000 (15:50 +0000)
even though its error messages suggested it did.  Thanks to Yann for the
patch (I also added the ability to accept parameters without requiring
them to be in a tuple).  Also documented the New() function.

source/blender/python/api2_2x/BezTriple.c
source/blender/python/api2_2x/doc/Ipo.py

index 98e53d2fef8534e69cad04916b39ca61100c2798..1e835b3f3168d9fe41404c9f4fa521a47387a9bd 100644 (file)
@@ -136,43 +136,55 @@ PyTypeObject BezTriple_Type = {
 static PyObject *M_BezTriple_New( PyObject* self, PyObject * args )
 {
        float numbuf[9];
-       int status, length;
        PyObject* in_args = NULL;
+       int length;
 
-       if( !PyArg_ParseTuple( args, "|O", &in_args) )
-               return EXPP_ReturnPyObjError( PyExc_TypeError,
-                                       "expected sequence of 3 or 9 floats or nothing" );
+       /* accept list, tuple, or 3 or 9 args (which better be floats) */
+
+       length = PyTuple_Size( args );
+       if( length == 3 || length == 9 )
+               in_args = args;
+       else if( !PyArg_ParseTuple( args, "|O", &in_args) )
+               goto TypeError;
 
        if( !in_args ) {
                numbuf[0] = 0.0f; numbuf[1] = 0.0f; numbuf[2] = 0.0f;
                numbuf[3] = 0.0f; numbuf[4] = 0.0f; numbuf[5] = 0.0f;
                numbuf[6] = 0.0f; numbuf[7] = 0.0f; numbuf[8] = 0.0f;
        } else {
+               int i, length;
                if( !PySequence_Check( in_args ) )
-                       return EXPP_ReturnPyObjError( PyExc_TypeError,
-                                       "expected sequence of 3 or 9 floats or nothing" );
-               
+                       goto TypeError;
+
                length = PySequence_Length( in_args );
-               if( length == 9 )
-                       status = PyArg_ParseTuple( in_args, "fffffffff",
-                                       &numbuf[0], &numbuf[1], &numbuf[2], 
-                                       &numbuf[3], &numbuf[4], &numbuf[5],
-                                       &numbuf[6], &numbuf[7], &numbuf[8]);
-               else if( length == 3 ) {
-                       status = PyArg_ParseTuple( in_args, "fff",
-                                       &numbuf[0], &numbuf[1], &numbuf[2]);     
+               if( length != 9 && length != 3 )
+                       goto TypeError;
+               
+               for(i=0; i<length; i++) {
+                       PyObject *item, *pyfloat;
+                       item=PySequence_ITEM(in_args, i);
+                       if( !item )
+                               goto TypeError;
+                       pyfloat=PyNumber_Float(item);
+                       Py_DECREF(item);
+                       if( !pyfloat )
+                               goto TypeError;
+                       numbuf[i]=PyFloat_AS_DOUBLE(pyfloat);
+                       Py_DECREF(pyfloat);
+               }
+
+               if( length == 3 ) {
                        numbuf[3] = numbuf[0]; numbuf[6] = numbuf[0];
                        numbuf[4] = numbuf[1]; numbuf[7] = numbuf[1];
                        numbuf[5] = numbuf[2]; numbuf[8] = numbuf[2];
-               } else
-                       return EXPP_ReturnPyObjError( PyExc_TypeError,
-                                       "wrong number of points" );
-               if( !status )
-                       return EXPP_ReturnPyObjError( PyExc_AttributeError,
-                                       "sequence item not number");
+               }
        }
 
        return newBezTriple( numbuf );
+
+TypeError:
+       return EXPP_ReturnPyObjError( PyExc_TypeError,
+                       "expected sequence of 3 or 9 floats or nothing" );
 }
 
 /****************************************************************************
index b4a99c0216bad694e5bf89a7585f305c8c687aaf..8621bd18ca020ef6ab8b4b23b816aef1393647d9 100644 (file)
@@ -410,6 +410,17 @@ class BezTriple:
   @type hide: int
   """
 
+  def __init__(coords):
+    """
+    Create a new BezTriple object.  
+
+    @type coords: sequence of three or nine floats
+    @param coords: the coordinate values for the new control point.  If three
+    floats are given, then the handle values are automatically generated.
+    @rtype: BezTriple
+    @return: a new BezTriple object
+    """
+
   def getPoints():
     """
     Returns the xy coordinates of the Bezier knot point.