New methods: Curve.isCyclic(), CurNurb.isCyclic() for checking if curve is cyclic ( closed ). Both methods are boolean.
Patch contributed by Toni Alatalo. Thanks.
This commit is contained in:
@@ -63,6 +63,7 @@ static PyObject *CurNurb_iterNext( BPy_CurNurb * self );
|
||||
PyObject *CurNurb_append( BPy_CurNurb * self, PyObject * args );
|
||||
PyObject *CurNurb_pointAtIndex( Nurb * nurb, int index );
|
||||
static PyObject *CurNurb_isNurb( BPy_CurNurb * self );
|
||||
static PyObject *CurNurb_isCyclic( BPy_CurNurb * self );
|
||||
|
||||
char M_CurNurb_doc[] = "CurNurb";
|
||||
|
||||
@@ -426,6 +427,23 @@ static PyObject *CurNurb_isNurb( BPy_CurNurb * self )
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* CurNurb_isCyclic()
|
||||
* test whether spline cyclic (closed) or not (open)
|
||||
*/
|
||||
|
||||
static PyObject *CurNurb_isCyclic( BPy_CurNurb * self )
|
||||
{
|
||||
/* supposing that the flagu is always set */
|
||||
|
||||
if( self->nurb->flagu & CU_CYCLIC ) {
|
||||
Py_INCREF( Py_True );
|
||||
return Py_True;
|
||||
} else {
|
||||
Py_INCREF( Py_False );
|
||||
return ( Py_False );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
table of module methods
|
||||
@@ -463,6 +481,8 @@ static PyMethodDef BPy_CurNurb_methods[] = {
|
||||
"( point ) - add a new point. arg is BezTriple or list of x,y,z,w floats"},
|
||||
{"isNurb", ( PyCFunction ) CurNurb_isNurb, METH_NOARGS,
|
||||
"( ) - boolean function tests if this spline is type nurb or bezier"},
|
||||
{"isCyclic", ( PyCFunction ) CurNurb_isCyclic, METH_NOARGS,
|
||||
"( ) - boolean function tests if this spline is cyclic (closed) or not (open)"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
@@ -106,6 +106,7 @@ static PyObject *Curve_getSize( BPy_Curve * self );
|
||||
static PyObject *Curve_setSize( BPy_Curve * self, PyObject * args );
|
||||
static PyObject *Curve_getNumCurves( BPy_Curve * self );
|
||||
static PyObject *Curve_isNurb( BPy_Curve * self, PyObject * args );
|
||||
static PyObject *Curve_isCyclic( BPy_Curve * self, PyObject * args);
|
||||
static PyObject *Curve_getNumPoints( BPy_Curve * self, PyObject * args );
|
||||
static PyObject *Curve_getNumPoints( BPy_Curve * self, PyObject * args );
|
||||
|
||||
@@ -204,6 +205,8 @@ Sets a control point "},
|
||||
{"isNurb", ( PyCFunction ) Curve_isNurb,
|
||||
METH_VARARGS,
|
||||
"(nothing or integer) - returns 1 if curve is type Nurb, O otherwise."},
|
||||
{"isCyclic", ( PyCFunction ) Curve_isCyclic,
|
||||
METH_VARARGS, "( nothing or integer ) - returns true if curve is cyclic (closed), false otherwise."},
|
||||
{"getNumPoints", ( PyCFunction ) Curve_getNumPoints,
|
||||
METH_VARARGS,
|
||||
"(nothing or integer) - returns the number of points of the specified curve"},
|
||||
@@ -1058,6 +1061,49 @@ static PyObject *Curve_isNurb( BPy_Curve * self, PyObject * args )
|
||||
"couldn't get curve type" ) );
|
||||
}
|
||||
|
||||
/* trying to make a check for closedness (cyclic), following on isNurb (above)
|
||||
copy-pasting done by antont@kyperjokki.fi */
|
||||
|
||||
static PyObject *Curve_isCyclic( BPy_Curve * self, PyObject * args )
|
||||
{
|
||||
int curve_num = 0; /* default value */
|
||||
int is_cyclic;
|
||||
Nurb *ptrnurb;
|
||||
PyObject *ret_val;
|
||||
int i;
|
||||
|
||||
/* parse and check input args */
|
||||
if( !PyArg_ParseTuple( args, "|i", &curve_num ) ) {
|
||||
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"expected int argument" ) );
|
||||
}
|
||||
if( curve_num < 0 ) {
|
||||
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"curve number must be non-negative" ) );
|
||||
}
|
||||
|
||||
ptrnurb = self->curve->nurb.first;
|
||||
|
||||
if( !ptrnurb ) /* no splines in this curve */
|
||||
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"no splines in this Curve" ) );
|
||||
|
||||
for( i = 0; i < curve_num; i++ ) {
|
||||
ptrnurb = ptrnurb->next;
|
||||
if( !ptrnurb ) /* if zero, we ran just ran out of curves */
|
||||
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
|
||||
"curve index out of range" ) );
|
||||
}
|
||||
|
||||
if( ptrnurb->flagu & CU_CYCLIC ){
|
||||
Py_INCREF( Py_True );
|
||||
return Py_True;
|
||||
} else {
|
||||
Py_INCREF( Py_False );
|
||||
return Py_False;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Curve_appendPoint( numcurve, new_point )
|
||||
|
||||
@@ -226,7 +226,7 @@ class Curve:
|
||||
|
||||
def getControlPoint(numcurve,numpoint):
|
||||
"""
|
||||
Get the curve's control point value.
|
||||
Get the curve's control point value. The numpoint arg is an index into the list of points and starts with 0.
|
||||
@type numcurve: int
|
||||
@type numpoint: int
|
||||
@rtype: list of floats
|
||||
@@ -237,7 +237,7 @@ class Curve:
|
||||
|
||||
def setControlPoint( numcurve, numpoint, controlpoint):
|
||||
"""
|
||||
Set the Curve's controlpoint value.
|
||||
Set the Curve's controlpoint value. The numpoint arg is an index into the list of points and starts with 0.
|
||||
@rtype: PyNone
|
||||
@type numcurve: int
|
||||
@type numpoint: int
|
||||
@@ -333,12 +333,22 @@ class Curve:
|
||||
"""
|
||||
method used to determine whether a CurNurb is of type Bezier or of type Nurb.
|
||||
@rtype: integer
|
||||
@return: Zero of curve is type Bezier, One if curve is of type Nurb.
|
||||
@return: Zero if curve is type Bezier, One if curve is of type Nurb.
|
||||
@type curve_num: integer
|
||||
@param curve_num: zero-based index into list of curves in this Curve.
|
||||
@raise AttributeError: throws exception if curve_num is out of range.
|
||||
"""
|
||||
|
||||
def isCyclic( curve_num ):
|
||||
"""
|
||||
Boolean method checks whether the curve is cyclic (closed) or not.
|
||||
|
||||
@rtype: boolean
|
||||
@return: True if is cyclic, False if not
|
||||
@type curve_num: integer
|
||||
@param curve_num: zero-based index into list of curves in this Curve
|
||||
@raise AttributeError: throws exception if curve_num is out of range.
|
||||
"""
|
||||
|
||||
class CurNurb:
|
||||
"""
|
||||
@@ -384,5 +394,12 @@ class CurNurb:
|
||||
@return: True or False
|
||||
"""
|
||||
|
||||
def isCyclic():
|
||||
"""
|
||||
Boolean method checks whether a CurNurb is cyclic (a closed curve) or not.
|
||||
@rtype: boolean
|
||||
@return: True or False
|
||||
"""
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user