Skip to content

Conversation

salmagro
Copy link
Contributor

This MR introduces the MatchType enumeration to TimeseriesRef, providing the option to choose between exact and nearest time matching. Changes include updates to the atTime and getRawIndexAtTime methods to support this new functionality.

For a detailed problem description see: #968

@facontidavide
Copy link
Owner

look at CI...

- Added an enumeration MatchType with options Exact and Nearest.
- Modified atTime and getRawIndexAtTime in TimeseriesRef to support MatchType, allowing callers to specify whether they need an exact timestamp match or the nearest available match.
- Adjusted the atTime method to throw an error when an exact match is required but not found, enhancing error handling for strict match requirements.
@salmagro
Copy link
Contributor Author

I have resolved the compilation issues. However, I have a question regarding the proposal to pass an enum class MatchType to the atTime method.
Do we need to make any modifications when exposing this to Lua in this line https://github.com/facontidavide/PlotJuggler/blob/main/plotjuggler_base/src/reactive_function.cpp#L116?
How should the enum class MatchType be defined from Lua?

if (match_type == MatchType::Exact)
{
auto it = std::find_if(_plot_data->begin(), _plot_data->end(),
[t](const auto& point) { return point.x == t; });

Check notice

Code scanning / CodeQL

Equality test on floating-point values

Equality checks on floating point values can yield unexpected results.
@@ -25,7 +31,10 @@ struct TimeseriesRef

void set(unsigned index, double x, double y);

double atTime(double t) const;
double atTime(double t, MatchType match_type) const;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding new argument breaks older scripts. The best way it should be a default value but ain't sure it's possible with lua.

@firemark
Copy link

How should the enum class MatchType be defined from Lua?

Maybe you should define standalone functions like Uncle bob once said. In this way you should add three functions:

  • getRawIndexAtExactTime
  • getRawIndexAtTime
  • getAtExactTime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants