code: public static double wrapDouble(double value, double min, double max)
      {
          double newValue = value;
          final double step = max - min;
  
          if (Double.compare(newValue, max) >= 0)
          {
              while (Double.compare(newValue, max) >= 0)
              {
                  newValue -= step;
              }
          }
          else if (newValue < min)
          {
              while (newValue < min)
              {
                  newValue += step;
              }
          }
          return newValue;
      }
docs: Wrap value (keep value between min and max). Useful to keep an angle between 0 and 360 for example.
  
  @param value The input value.
  @param min The minimum value (included).
  @param max The maximum value (excluded).
  @return The wrapped value.