+ support First and Last keywords in discretize

This commit is contained in:
wmayer 2014-08-14 11:16:54 +02:00
parent 3d2a2b06f0
commit 9ed61f107b
6 changed files with 114 additions and 51 deletions

View File

@ -28,12 +28,30 @@ The function accepts keywords as argument:
discretize(Number=n) => gives a list of 'n' equidistant points
discretize(Distance=d) => gives a list of equidistant points with distance 'd'
discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the curve
discretize(Angular=a,Curvatre=c) => gives a list of points with an angular deflection of 'a'
and a curvature deflection of 'c'
discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a'
and a curvature deflection of 'c'. Optionally a minimum number of points
can be set which by default is set to 2.
Optionally you can set the keywords 'First' and 'Last' to define a sub-range of the parameter range
of the curve.
If no keyword is given then it depends on whether the argument is an int or float.
If it's an int then the behaviour is as if using the keyword 'Number', if it's float
then the behaviour is as if using the keyword 'Distance'.
Example:
import Part
c=Part.Circle()
c.Radius=5
p=c.discretize(Number=50,First=3.14)
s=Part.Compound([Part.Vertex(i) for i in p])
Part.show(s)
p=c.discretize(Angular=0.09,Curvature=0.01,Last=3.14,Minimum=100)
s=Part.Compound([Part.Vertex(i) for i in p])
Part.show(s)
</UserDocu>
</Documentation>
</Methode>

View File

@ -129,6 +129,8 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds)
bool uniformAbscissaDistance = false;
int numPoints = -1;
double distance = -1;
double first = adapt.FirstParameter();
double last = adapt.LastParameter();
// use no kwds
PyObject* dist_or_num;
@ -148,16 +150,16 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds)
}
else {
// use Number kwds
static char* kwds_numPoints[] = {"Number",NULL};
static char* kwds_numPoints[] = {"Number","First","Last",NULL};
PyErr_Clear();
if (PyArg_ParseTupleAndKeywords(args, kwds, "i", kwds_numPoints, &numPoints)) {
if (PyArg_ParseTupleAndKeywords(args, kwds, "i|dd", kwds_numPoints, &numPoints, &first, &last)) {
uniformAbscissaPoints = true;
}
else {
// use Abscissa kwds
static char* kwds_Distance[] = {"Distance",NULL};
static char* kwds_Distance[] = {"Distance","First","Last",NULL};
PyErr_Clear();
if (PyArg_ParseTupleAndKeywords(args, kwds, "d", kwds_Distance, &distance)) {
if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Distance, &distance, &first, &last)) {
uniformAbscissaDistance = true;
}
}
@ -166,9 +168,9 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds)
if (uniformAbscissaPoints || uniformAbscissaDistance) {
GCPnts_UniformAbscissa discretizer;
if (uniformAbscissaPoints)
discretizer.Initialize (adapt, numPoints);
discretizer.Initialize (adapt, numPoints, first, last);
else
discretizer.Initialize (adapt, distance);
discretizer.Initialize (adapt, distance, first, last);
if (discretizer.IsDone () && discretizer.NbPoints () > 0) {
Py::List points;
@ -181,17 +183,17 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds)
return Py::new_reference_to(points);
}
else {
PyErr_SetString(PyExc_Exception, "Descretization of wire failed");
PyErr_SetString(PyExc_Exception, "Discretization of curve failed");
return 0;
}
}
// use Deflection kwds
static char* kwds_Deflection[] = {"Deflection",NULL};
static char* kwds_Deflection[] = {"Deflection","First","Last",NULL};
PyErr_Clear();
double deflection;
if (PyArg_ParseTupleAndKeywords(args, kwds, "d", kwds_Deflection, &deflection)) {
GCPnts_UniformDeflection discretizer(adapt, deflection);
if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Deflection, &deflection, &first, &last)) {
GCPnts_UniformDeflection discretizer(adapt, deflection, first, last);
if (discretizer.IsDone () && discretizer.NbPoints () > 0) {
Py::List points;
int nbPoints = discretizer.NbPoints ();
@ -203,18 +205,19 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds)
return Py::new_reference_to(points);
}
else {
PyErr_SetString(PyExc_Exception, "Descretization of wire failed");
PyErr_SetString(PyExc_Exception, "Discretization of curve failed");
return 0;
}
}
// use TangentialDeflection kwds
static char* kwds_TangentialDeflection[] = {"Angular","Curvature",NULL};
static char* kwds_TangentialDeflection[] = {"Angular","Curvature","First","Last","Minimum",NULL};
PyErr_Clear();
double angular;
double curvature;
if (PyArg_ParseTupleAndKeywords(args, kwds, "dd", kwds_TangentialDeflection, &angular, &curvature)) {
GCPnts_TangentialDeflection discretizer(adapt, angular, curvature);
int minimumPoints = 2;
if (PyArg_ParseTupleAndKeywords(args, kwds, "dd|ddi", kwds_TangentialDeflection, &angular, &curvature, &first, &last, &minimumPoints)) {
GCPnts_TangentialDeflection discretizer(adapt, first, last, angular, curvature, minimumPoints);
if (discretizer.NbPoints () > 0) {
Py::List points;
int nbPoints = discretizer.NbPoints ();
@ -226,7 +229,7 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds)
return Py::new_reference_to(points);
}
else {
PyErr_SetString(PyExc_Exception, "Descretization of wire failed");
PyErr_SetString(PyExc_Exception, "Discretization of curve failed");
return 0;
}
}

View File

@ -76,12 +76,30 @@ The function accepts keywords as argument:
discretize(Number=n) => gives a list of 'n' equidistant points
discretize(Distance=d) => gives a list of equidistant points with distance 'd'
discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the edge
discretize(Angular=a,Curvatre=c) => gives a list of points with an angular deflection of 'a'
and a curvature deflection of 'c'
discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a'
and a curvature deflection of 'c'. Optionally a minimum number of points
can be set which by default is set to 2.
Optionally you can set the keywords 'First' and 'Last' to define a sub-range of the parameter range
of the edge.
If no keyword is given then it depends on whether the argument is an int or float.
If it's an int then the behaviour is as if using the keyword 'Number', if it's float
then the behaviour is as if using the keyword 'Distance'.
Example:
import Part
c=Part.Circle()
c.Radius=5
p=c.discretize(Number=50,First=3.14)
s=Part.Compound([Part.Vertex(i) for i in p])
Part.show(s)
p=c.discretize(Angular=0.09,Curvature=0.01,Last=3.14,Minimum=100)
s=Part.Compound([Part.Vertex(i) for i in p])
Part.show(s)
</UserDocu>
</Documentation>
</Methode>

View File

@ -397,6 +397,8 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds)
bool uniformAbscissaDistance = false;
int numPoints = -1;
double distance = -1;
double first = adapt.FirstParameter();
double last = adapt.LastParameter();
// use no kwds
PyObject* dist_or_num;
@ -416,16 +418,16 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds)
}
else {
// use Number kwds
static char* kwds_numPoints[] = {"Number",NULL};
static char* kwds_numPoints[] = {"Number","First","Last",NULL};
PyErr_Clear();
if (PyArg_ParseTupleAndKeywords(args, kwds, "i", kwds_numPoints, &numPoints)) {
if (PyArg_ParseTupleAndKeywords(args, kwds, "i|dd", kwds_numPoints, &numPoints, &first, &last)) {
uniformAbscissaPoints = true;
}
else {
// use Abscissa kwds
static char* kwds_Distance[] = {"Distance",NULL};
static char* kwds_Distance[] = {"Distance","First","Last",NULL};
PyErr_Clear();
if (PyArg_ParseTupleAndKeywords(args, kwds, "d", kwds_Distance, &distance)) {
if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Distance, &distance, &first, &last)) {
uniformAbscissaDistance = true;
}
}
@ -434,9 +436,9 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds)
if (uniformAbscissaPoints || uniformAbscissaDistance) {
GCPnts_UniformAbscissa discretizer;
if (uniformAbscissaPoints)
discretizer.Initialize (adapt, numPoints);
discretizer.Initialize (adapt, numPoints, first, last);
else
discretizer.Initialize (adapt, distance);
discretizer.Initialize (adapt, distance, first, last);
if (discretizer.IsDone () && discretizer.NbPoints () > 0) {
Py::List points;
@ -449,17 +451,17 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds)
return Py::new_reference_to(points);
}
else {
PyErr_SetString(PyExc_Exception, "Descretization of curve failed");
PyErr_SetString(PyExc_Exception, "Discretization of edge failed");
return 0;
}
}
// use Deflection kwds
static char* kwds_Deflection[] = {"Deflection",NULL};
static char* kwds_Deflection[] = {"Deflection","First","Last",NULL};
PyErr_Clear();
double deflection;
if (PyArg_ParseTupleAndKeywords(args, kwds, "d", kwds_Deflection, &deflection)) {
GCPnts_UniformDeflection discretizer(adapt, deflection);
if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Deflection, &deflection, &first, &last)) {
GCPnts_UniformDeflection discretizer(adapt, deflection, first, last);
if (discretizer.IsDone () && discretizer.NbPoints () > 0) {
Py::List points;
int nbPoints = discretizer.NbPoints ();
@ -471,18 +473,19 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds)
return Py::new_reference_to(points);
}
else {
PyErr_SetString(PyExc_Exception, "Descretization of curve failed");
PyErr_SetString(PyExc_Exception, "Discretization of edge failed");
return 0;
}
}
// use TangentialDeflection kwds
static char* kwds_TangentialDeflection[] = {"Angular","Curvature",NULL};
static char* kwds_TangentialDeflection[] = {"Angular","Curvature","First","Last","Minimum",NULL};
PyErr_Clear();
double angular;
double curvature;
if (PyArg_ParseTupleAndKeywords(args, kwds, "dd", kwds_TangentialDeflection, &angular, &curvature)) {
GCPnts_TangentialDeflection discretizer(adapt, angular, curvature);
int minimumPoints = 2;
if (PyArg_ParseTupleAndKeywords(args, kwds, "dd|ddi", kwds_TangentialDeflection, &angular, &curvature, &first, &last, &minimumPoints)) {
GCPnts_TangentialDeflection discretizer(adapt, first, last, angular, curvature, minimumPoints);
if (discretizer.NbPoints () > 0) {
Py::List points;
int nbPoints = discretizer.NbPoints ();
@ -494,7 +497,7 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds)
return Py::new_reference_to(points);
}
else {
PyErr_SetString(PyExc_Exception, "Descretization of curve failed");
PyErr_SetString(PyExc_Exception, "Discretization of edge failed");
return 0;
}
}

View File

@ -58,12 +58,30 @@ The function accepts keywords as argument:
discretize(Number=n) => gives a list of 'n' equidistant points
discretize(Distance=d) => gives a list of equidistant points with distance 'd'
discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the wire
discretize(Angular=a,Curvatre=c) => gives a list of points with an angular deflection of 'a'
and a curvature deflection of 'c'
discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a'
and a curvature deflection of 'c'. Optionally a minimum number of points
can be set which by default is set to 2.
Optionally you can set the keywords 'First' and 'Last' to define a sub-range of the parameter range
of the wire.
If no keyword is given then it depends on whether the argument is an int or float.
If it's an int then the behaviour is as if using the keyword 'Number', if it's float
then the behaviour is as if using the keyword 'Distance'.
Example:
import Part
c=Part.Circle()
c.Radius=5
p=c.discretize(Number=50,First=3.14)
s=Part.Compound([Part.Vertex(i) for i in p])
Part.show(s)
p=c.discretize(Angular=0.09,Curvature=0.01,Last=3.14,Minimum=100)
s=Part.Compound([Part.Vertex(i) for i in p])
Part.show(s)
</UserDocu>
</Documentation>
</Methode>

View File

@ -338,6 +338,8 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds)
bool uniformAbscissaDistance = false;
int numPoints = -1;
double distance = -1;
double first = adapt.FirstParameter();
double last = adapt.LastParameter();
// use no kwds
PyObject* dist_or_num;
@ -357,16 +359,16 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds)
}
else {
// use Number kwds
static char* kwds_numPoints[] = {"Number",NULL};
static char* kwds_numPoints[] = {"Number","First","Last",NULL};
PyErr_Clear();
if (PyArg_ParseTupleAndKeywords(args, kwds, "i", kwds_numPoints, &numPoints)) {
if (PyArg_ParseTupleAndKeywords(args, kwds, "i|dd", kwds_numPoints, &numPoints, &first, &last)) {
uniformAbscissaPoints = true;
}
else {
// use Abscissa kwds
static char* kwds_Distance[] = {"Distance",NULL};
static char* kwds_Distance[] = {"Distance","First","Last",NULL};
PyErr_Clear();
if (PyArg_ParseTupleAndKeywords(args, kwds, "d", kwds_Distance, &distance)) {
if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Distance, &distance, &first, &last)) {
uniformAbscissaDistance = true;
}
}
@ -375,9 +377,9 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds)
if (uniformAbscissaPoints || uniformAbscissaDistance) {
GCPnts_UniformAbscissa discretizer;
if (uniformAbscissaPoints)
discretizer.Initialize (adapt, numPoints);
discretizer.Initialize (adapt, numPoints, first, last);
else
discretizer.Initialize (adapt, distance);
discretizer.Initialize (adapt, distance, first, last);
if (discretizer.IsDone () && discretizer.NbPoints () > 0) {
Py::List points;
@ -390,17 +392,17 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds)
return Py::new_reference_to(points);
}
else {
PyErr_SetString(PyExc_Exception, "Descretization of wire failed");
PyErr_SetString(PyExc_Exception, "Discretization of wire failed");
return 0;
}
}
// use Deflection kwds
static char* kwds_Deflection[] = {"Deflection",NULL};
static char* kwds_Deflection[] = {"Deflection","First","Last",NULL};
PyErr_Clear();
double deflection;
if (PyArg_ParseTupleAndKeywords(args, kwds, "d", kwds_Deflection, &deflection)) {
GCPnts_UniformDeflection discretizer(adapt, deflection);
if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Deflection, &deflection, &first, &last)) {
GCPnts_UniformDeflection discretizer(adapt, deflection, first, last);
if (discretizer.IsDone () && discretizer.NbPoints () > 0) {
Py::List points;
int nbPoints = discretizer.NbPoints ();
@ -412,18 +414,19 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds)
return Py::new_reference_to(points);
}
else {
PyErr_SetString(PyExc_Exception, "Descretization of wire failed");
PyErr_SetString(PyExc_Exception, "Discretization of wire failed");
return 0;
}
}
// use TangentialDeflection kwds
static char* kwds_TangentialDeflection[] = {"Angular","Curvature",NULL};
static char* kwds_TangentialDeflection[] = {"Angular","Curvature","First","Last","Minimum",NULL};
PyErr_Clear();
double angular;
double curvature;
if (PyArg_ParseTupleAndKeywords(args, kwds, "dd", kwds_TangentialDeflection, &angular, &curvature)) {
GCPnts_TangentialDeflection discretizer(adapt, angular, curvature);
int minimumPoints = 2;
if (PyArg_ParseTupleAndKeywords(args, kwds, "dd|ddi", kwds_TangentialDeflection, &angular, &curvature, &first, &last, &minimumPoints)) {
GCPnts_TangentialDeflection discretizer(adapt, first, last, angular, curvature, minimumPoints);
if (discretizer.NbPoints () > 0) {
Py::List points;
int nbPoints = discretizer.NbPoints ();
@ -435,7 +438,7 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds)
return Py::new_reference_to(points);
}
else {
PyErr_SetString(PyExc_Exception, "Descretization of wire failed");
PyErr_SetString(PyExc_Exception, "Discretization of wire failed");
return 0;
}
}