Exemple #1
0
 /**
  * Sets the min and max value for scaling. This assumes that the entries in the color scale range
  * from 0 to 1. This also forces the scaling to be min/max. Min will be scaled to 0 and max will
  * be scaled to 1 in the color scale. All values between will be linearly interpolated. Values out
  * of bounds will be forced into range according to the forceValuesIntoRange property, which is
  * false by default.
  *
  * @param min The minimum value to be expected (smaller values will just be forced to min.
  * @param max The maximum value to be expected (larger values will just be forced to max.
  */
 public void setScaleRange(final double min, final double max) {
   this.min = min;
   this.max = max;
   if (scaling != Scaling.Modulo) {
     scaling = Scaling.MinMax;
   }
   cache = null;
   buildCache();
 }
Exemple #2
0
  public final int[] lookup(final double v) {
    if (Double.isNaN(v) || v == transparent) {
      return nullColor;
    }
    if (cache == null) {
      buildCache();
    }

    if (v < min) {
      if (forceValuesIntoRange) {
        return cache[0];
      }
      return nullColor;
    } else if (v > max) {
      if (forceValuesIntoRange) {
        return cache[CACHE_SIZE - 1];
      }
      return nullColor;
    } else {
      final int i = (int) ((v - min) / (max - min) * (CACHE_SIZE - 1) + 0.5);
      // int i = (int) ((v - min) / (max - min) * (CACHE_SIZE - 1));
      return cache[i];
    }
  }