opensim-core: DataTable::getRow() should not perform equality comparison on double

DataTable::getRow() uses std::find() to search for a specified entry in the independent column. When the independent variable is of type double (e.g., time, as will often be the case), std::find() must include a tolerance (e.g., using std::find_if()). Currently, filling a TimeSeriesTable with time points spaced 0.01 seconds apart and doing

for (unsigned i=0u; i<table.getNumRows(); ++i)
    table.getRow(0.01*i);

throws KeyNotFound when i=6u due to roundoff error.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

I think this issue can be closed now. The PR #1372 added functions getNearestRow and updNearestRow. It also adds documentation to getRow pointing to these added functions depending on the need.

If the PR #1372 gets merged, it will add a function named getNearestRow which can be used instead to avoid this problem. So basically that PR addresses this issue.