Skip to content

Find closest line segment for Line plots#234

Open
lucasmerlin wants to merge 3 commits intomainfrom
lucas/find-closest-line-segment
Open

Find closest line segment for Line plots#234
lucasmerlin wants to merge 3 commits intomainfrom
lucas/find-closest-line-segment

Conversation

@lucasmerlin
Copy link
Collaborator

It will now find the line closest to the cursor, so you don't need to hover the points exactly
https://github.com/user-attachments/assets/6aec87b3-97ad-4f41-94a4-f38ea1b985da

@lucasmerlin lucasmerlin requested a review from Copilot March 10, 2026 13:23
@github-actions
Copy link

View snapshot changes at kitdiff

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves egui_plot line hover interaction by selecting the closest line segment to the cursor (instead of requiring precise point hovering), enabling more intuitive tooltips and highlighting.

Changes:

  • Added a point-to-line-segment squared-distance helper in math.rs.
  • Overrode Line’s find_closest to compute proximity to segments and select the best match for hover/tooltips.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
egui_plot/src/math.rs Adds dist_sq_to_segment used to measure cursor proximity to a line segment.
egui_plot/src/items/series.rs Updates Line::find_closest to choose the nearest segment and map it to a data-point index for tooltip/highlight.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

lucasmerlin and others added 2 commits March 10, 2026 14:29
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@lucasmerlin lucasmerlin added enhancement New feature or request include in changelog This change will be included in the changelog labels Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request include in changelog This change will be included in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants