Skip to content

[WIP] Implement new Level of Detail algorithm and tests#1

Closed
Copilot wants to merge 1 commit intomasterfrom
copilot/add-new-lod-algorithm
Closed

[WIP] Implement new Level of Detail algorithm and tests#1
Copilot wants to merge 1 commit intomasterfrom
copilot/add-new-lod-algorithm

Conversation

Copy link
Copy Markdown

Copilot AI commented Oct 27, 2025

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

The goal is to add a new Level of Detail (LOD) algorithm to this project, replace the current one's invocation in the GUI, and add tests for the new module.

1. New LOD Algorithm Implementation

A new LOD algorithm needs to be implemented with the following specifications:

  • Input Data: The algorithm will process a series of mouse movement events. Each event is a struct: {dx: i16, dy: i16, tsc: u32, utsc: u32}. The tsc and utsc fields are timestamps. This data is used to plot dx vs. time and -dy vs. time.

  • Data Segmentation:

    • The algorithm must analyze the events to identify and segment them into groups of "good events" and "discrete events".
    • Discrete/Not Good Events: An event is considered "not good" or "discrete" if it meets any of the following criteria:
      1. Both dx and dy are zero.
      2. It shows poor time consistency. The relationship between the event index and its timestamp should be linear (for a constant report rate) or fit a cubic polynomial well. Deviations indicate inconsistency.
      3. It is an outlier when fitting dx vs. time or dy vs. time to a cubic polynomial.
    • Segmentation Logic: The final output of this stage should be a List<(List<good events> or discrete event)>. The goal is to maximize the length of the List<good events> while ensuring a high coefficient of determination (R-squared, close to 1) for the polynomial fit. This may involve an iterative approach, starting with an initial number of events for regression and expanding the window (e.g., by a factor of 1.5 or 2) to find the optimal balance between segment length and fit quality.
  • Result Caching: The results of the segmentation and regression analysis should be cached to improve performance on subsequent rendering calls.

2. LOD Plotting Function

Create a function that the plotting module will call to get the list of events to render.

  • Function Signature & Parameters:

    • events: The source event data.
    • resolution: The rendering resolution of the plot.
    • x_range, y_range: The visible ranges of the plot.
    • tolerance: A threshold for the number of events that can map to a single screen coordinate before simplification is triggered.
    • zoom_factor: A factor (>1) to anticipate user zooming. The simplification should be calculated for a higher resolution (resolution * zoom_factor) to improve drag performance.
  • Simplification Logic:

    • The function should leverage the cached segmentation results.
    • If a cached result can be used for the given zoom_factor and ranges, it should be reused.
    • It must calculate which events fall onto the same physical screen coordinates based on the effective resolution and plot ranges.
    • If the number of events at a coordinate exceeds the tolerance, some events must be hidden.
    • Constraint: The first and last events of any "good event list" segment must not be hidden to ensure continuity in the plot lines.
  • Return Value: The function must return a list of indices corresponding to the original events array that are not hidden and should be drawn.

3. Integration

  • In the GUI code, find the call site for the current LOD/plotting function.
  • Comment out the call to the old algorithm.
  • Add a new call to the function created in step 2.

4. Testing

  • Create a new test module for the LOD algorithm.
  • Write tests to verify its correctness.
  • Use the test datasets located in the /examples/test/ directory as input for these tests.

This pull request was created as a result of the following prompt from Copilot chat.

The goal is to add a new Level of Detail (LOD) algorithm to this project, replace the current one's invocation in the GUI, and add tests for the new module.

1. New LOD Algorithm Implementation

A new LOD algorithm needs to be implemented with the following specifications:

  • Input Data: The algorithm will process a series of mouse movement events. Each event is a struct: {dx: i16, dy: i16, tsc: u32, utsc: u32}. The tsc and utsc fields are timestamps. This data is used to plot dx vs. time and -dy vs. time.

  • Data Segmentation:

    • The algorithm must analyze the events to identify and segment them into groups of "good events" and "discrete events".
    • Discrete/Not Good Events: An event is considered "not good" or "discrete" if it meets any of the following criteria:
      1. Both dx and dy are zero.
      2. It shows poor time consistency. The relationship between the event index and its timestamp should be linear (for a constant report rate) or fit a cubic polynomial well. Deviations indicate inconsistency.
      3. It is an outlier when fitting dx vs. time or dy vs. time to a cubic polynomial.
    • Segmentation Logic: The final output of this stage should be a List<(List<good events> or discrete event)>. The goal is to maximize the length of the List<good events> while ensuring a high coefficient of determination (R-squared, close to 1) for the polynomial fit. This may involve an iterative approach, starting with an initial number of events for regression and expanding the window (e.g., by a factor of 1.5 or 2) to find the optimal balance between segment length and fit quality.
  • Result Caching: The results of the segmentation and regression analysis should be cached to improve performance on subsequent rendering calls.

2. LOD Plotting Function

Create a function that the plotting module will call to get the list of events to render.

  • Function Signature & Parameters:

    • events: The source event data.
    • resolution: The rendering resolution of the plot.
    • x_range, y_range: The visible ranges of the plot.
    • tolerance: A threshold for the number of events that can map to a single screen coordinate before simplification is triggered.
    • zoom_factor: A factor (>1) to anticipate user zooming. The simplification should be calculated for a higher resolution (resolution * zoom_factor) to improve drag performance.
  • Simplification Logic:

    • The function should leverage the cached segmentation results.
    • If a cached result can be used for the given zoom_factor and ranges, it should be reused.
    • It must calculate which events fall onto the same physical screen coordinates based on the effective resolution and plot ranges.
    • If the number of events at a coordinate exceeds the tolerance, some events must be hidden.
    • Constraint: The first and last events of any "good event list" segment must not be hidden to ensure continuity in the plot lines.
  • Return Value: The function must return a list of indices corresponding to the original events array that are not hidden and should be drawn.

3. Integration

  • In the GUI code, find the call site for the current LOD/plotting function.
  • Comment out the call to the old algorithm.
  • Add a new call to the function created in step 2.

4. Testing

  • Create a new test module for the LOD algorithm.
  • Write tests to verify its correctness.
  • Use the test datasets located in the /examples/test/ directory as input for these tests.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

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.

2 participants