Edge.getParameterByLength fix

This commit is contained in:
tomate44
2018-02-14 18:46:35 +01:00
parent 23fff2b1d3
commit 4e2d7c36ca
2 changed files with 16 additions and 10 deletions

View File

@@ -16,18 +16,21 @@
</Documentation>
<Methode Name="getParameterByLength" Const="true">
<Documentation>
<UserDocu>paramval = getParameterByLength(pos)
<UserDocu>paramval = getParameterByLength(pos, [tolerance = 1e-7])
Get the value of the primary parameter at the given distance along the cartesian
length of the curve.
length of the edge.
Args:
pos (float or int): The distance along the length of the curve at which to
pos (float or int): The distance along the length of the edge at which to
determine the primary parameter value. See help for the FirstParameter or
LastParameter properties for more information on the primary parameter.
If the given value is positive, the distance from edge start is used.
If the given value is negative, the distance from edge end is used.
tol (float): Computing tolerance. Optional, defaults to 1e-7.
Returns:
paramval (float): the value of the primary parameter defining the curve at the
paramval (float): the value of the primary parameter defining the edge at the
given position along its cartesian length.
</UserDocu>
</Documentation>

View File

@@ -187,7 +187,8 @@ int TopoShapeEdgePy::PyInit(PyObject* args, PyObject* /*kwd*/)
PyObject* TopoShapeEdgePy::getParameterByLength(PyObject *args)
{
double u;
if (!PyArg_ParseTuple(args, "d",&u))
double t=Precision::Confusion();
if (!PyArg_ParseTuple(args, "d|d",&u,&t))
return 0;
const TopoDS_Edge& e = TopoDS::Edge(getTopoShapePtr()->getShape());
@@ -197,15 +198,17 @@ PyObject* TopoShapeEdgePy::getParameterByLength(PyObject *args)
double first = BRepLProp_CurveTool::FirstParameter(adapt);
double last = BRepLProp_CurveTool::LastParameter(adapt);
if (!Precision::IsInfinite(first) && !Precision::IsInfinite(last)) {
double length = GCPnts_AbscissaPoint::Length(adapt);
double length = GCPnts_AbscissaPoint::Length(adapt,t);
if (u < 0 || u > length) {
if (u < -length || u > length) {
PyErr_SetString(PyExc_ValueError, "value out of range");
return 0;
}
double stretch = (last - first) / length;
u = first + u*stretch;
if (u < 0)
u = length+u;
GCPnts_AbscissaPoint abscissaPoint(t,adapt,u,first);
double parm = abscissaPoint.Parameter();
return PyFloat_FromDouble(parm);
}
return PyFloat_FromDouble(u);