code: private static double constrainNum(double min, double size, double h) {
  
          if (h < min) {
              return min;
          }
          if (h >= (min + size)) {
              return (min + size) - 1;
          }
          return h;
      }
docs: Helper method to constrain a number inside a given interval.<p>
  
  If the number is inside the given range, it will be returned unchanged, otherwise either the maximum
  or minimum of the range is returned depending on on which side the value lies.
  
  @param min the minimum value
  @param size the difference between maximum and minimum value
  @param h the number to constrain
  
  @return the constrained value