From 4e2d7c36ca8cd79bc5a109b681cf0a1ed04f6681 Mon Sep 17 00:00:00 2001 From: tomate44 Date: Wed, 14 Feb 2018 18:46:35 +0100 Subject: [PATCH] Edge.getParameterByLength fix --- src/Mod/Part/App/TopoShapeEdgePy.xml | 11 +++++++---- src/Mod/Part/App/TopoShapeEdgePyImp.cpp | 15 +++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Mod/Part/App/TopoShapeEdgePy.xml b/src/Mod/Part/App/TopoShapeEdgePy.xml index a7dba7096b..da63af8a89 100644 --- a/src/Mod/Part/App/TopoShapeEdgePy.xml +++ b/src/Mod/Part/App/TopoShapeEdgePy.xml @@ -16,18 +16,21 @@ - paramval = getParameterByLength(pos) + 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. diff --git a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp index aa631d0a6c..633fd88052 100644 --- a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp @@ -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);