LCOV - code coverage report
Current view: top level - src - RangeSliderLogic.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 33 33
Test Date: 2026-03-03 00:31:37 Functions: 100.0 % 4 4

            Line data    Source code
       1              : #include "RangeSliderLogic.h"
       2              : 
       3           35 : float RangeSliderLogic::valueToPixel(double value, double rangeMin, double rangeMax,
       4              :                                      float trackStart, float trackWidth) {
       5           35 :     if (rangeMax <= rangeMin) return trackStart;
       6           70 :     return trackStart + static_cast<float>((value - rangeMin) / (rangeMax - rangeMin)) *
       7           35 :         trackWidth;
       8           35 : }
       9              : 
      10            7 : double RangeSliderLogic::pixelToValue(float pixel, double rangeMin, double rangeMax,
      11              :                                       float trackStart, float trackWidth) {
      12            7 :     if (trackWidth <= 0.0f) return rangeMin;
      13           14 :     return rangeMin + static_cast<double>((pixel - trackStart) / trackWidth) * (rangeMax -
      14            7 :         rangeMin);
      15            7 : }
      16              : 
      17            8 : bool RangeSliderLogic::isInMiddleZone(float mouseX,
      18              :                                       double minVal, double maxVal,
      19              :                                       double rangeMin, double rangeMax,
      20              :                                       float trackStart, float trackWidth,
      21              :                                       float thumbRadius) {
      22            8 :     const float minPx = valueToPixel(minVal, rangeMin, rangeMax, trackStart, trackWidth);
      23            8 :     const float maxPx = valueToPixel(maxVal, rangeMin, rangeMax, trackStart, trackWidth);
      24            8 :     const float zoneLeft = minPx + thumbRadius;
      25            8 :     const float zoneRight = maxPx - thumbRadius;
      26            8 :     return zoneLeft < zoneRight && mouseX >= zoneLeft && mouseX <= zoneRight;
      27              : }
      28              : 
      29            7 : std::pair<double, double> RangeSliderLogic::applyDrag(
      30              :     double initialMin, double initialMax,
      31              :     double rangeMin, double rangeMax,
      32              :     float deltaPixels,
      33              :     float trackStart, float trackWidth) {
      34            7 :     if (trackWidth <= 0.0f) return {initialMin, initialMax};
      35              : 
      36            7 :     const double interval = initialMax - initialMin;
      37           21 :     const double deltaValue = static_cast<double>(deltaPixels) / static_cast<double>(
      38           14 :         trackWidth) * (rangeMax - rangeMin);
      39              : 
      40            7 :     double newMin = initialMin + deltaValue;
      41            7 :     double newMax = initialMax + deltaValue;
      42              : 
      43            7 :     if (newMin < rangeMin) {
      44            2 :         newMin = rangeMin;
      45            2 :         newMax = rangeMin + interval;
      46            2 :     }
      47            7 :     if (newMax > rangeMax) {
      48            2 :         newMax = rangeMax;
      49            2 :         newMin = rangeMax - interval;
      50            2 :     }
      51              : 
      52            7 :     return {newMin, newMax};
      53            7 : }
        

Generated by: LCOV version 2.4-0