| 309 | "); |
| 310 | |
| 311 | static PyObject * |
| 312 | Math_linear_interpolate(PyObject *self, PyObject *args) |
| 313 | { |
| 314 | auto api = PyUtilApiFunction("Oi", PyRunTimeErr, __func__); |
| 315 | PyObject *pointsArg; |
| 316 | int numInterpPoints = 0; |
| 317 | |
| 318 | if (!PyArg_ParseTuple(args, api.format, &pointsArg, &numInterpPoints)) { |
| 319 | return api.argsError(); |
| 320 | } |
| 321 | |
| 322 | // Get an array of points from the pointsArgs list. |
| 323 | int dim = 2; |
| 324 | auto pts = GetPointsFromList(api, pointsArg, dim, "points"); |
| 325 | if (pts == nullptr) { |
| 326 | return nullptr; |
| 327 | } |
| 328 | int nlistpts = PyList_Size(pointsArg); |
| 329 | |
| 330 | // Calculate dt so that our time series will go from 0 to T. |
| 331 | double t0 = pts[0][0]; |
| 332 | double dt = (pts[nlistpts-1][0]-t0)/(numInterpPoints-1); |
| 333 | double **outPts = NULL; |
| 334 | |
| 335 | // Perform the linear interpolation. |
| 336 | auto mathObj = cvMath(); |
| 337 | if (mathObj.linearInterpolate(pts, nlistpts, t0, dt, numInterpPoints, &outPts) == SV_ERROR) { |
| 338 | mathObj.deleteArray(pts,nlistpts,dim); |
| 339 | api.error("Error linear interplating points."); |
| 340 | return nullptr; |
| 341 | } |
| 342 | |
| 343 | // create result string |
| 344 | char r[2048]; |
| 345 | PyObject *pylist = PyList_New(numInterpPoints); |
| 346 | for (int i = 0; i < numInterpPoints; i++) { |
| 347 | r[0] = '\0'; |
| 348 | sprintf(r,"%.6le %.6le",outPts[i][0],outPts[i][1]); |
| 349 | PyObject *rr = PyBytes_FromString(r); |
| 350 | PyList_SET_ITEM(pylist, i, rr); |
| 351 | } |
| 352 | |
| 353 | mathObj.deleteArray(pts,nlistpts,dim); |
| 354 | mathObj.deleteArray(outPts,numInterpPoints,dim); |
| 355 | |
| 356 | return pylist; |
| 357 | } |
| 358 | |
| 359 | //--------------------- |
| 360 | // Math_curve_length |
nothing calls this directly
no test coverage detected