+ // Get data for listed signals
+ for (entry_t &e : list) {
+ // Calculate sample number from cursor position
+ const double samples_per_pixel = e.signal->base()->get_samplerate() * scale();
+ const int64_t x_offset = offset().convert_to<double>() / scale();
+ const int64_t sample_num = max(((x_offset + p.x()) * samples_per_pixel), 0.0);
+
+ vector<data::LogicSegment::EdgePair> edges =
+ e.signal->get_nearest_level_changes(sample_num);
+
+ if (edges.empty())
+ continue;
+
+ // Check first edge
+ const int64_t first_sample_delta = abs(sample_num - edges.front().first);
+ const int64_t first_delta = first_sample_delta / samples_per_pixel;
+ e.delta = first_delta;
+ e.sample = edges.front().first;
+
+ // Check second edge if available
+ if (edges.size() == 2) {
+ // Note: -1 because this is usually the right edge and sample points are left-aligned
+ const int64_t second_sample_delta = abs(sample_num - edges.back().first - 1);
+ const int64_t second_delta = second_sample_delta / samples_per_pixel;
+
+ // If both edges are too close, we mark this signal as being dense
+ if ((first_delta + second_delta) <= snap_distance_)
+ e.is_dense = true;
+
+ if (second_delta < first_delta) {
+ e.delta = second_delta;
+ e.sample = edges.back().first;
+ }
+ }
+ }