package de.lmu.ifi.dbs.elki.utilities.scaling;

/**
 * Simple linear scaling function.
 * 
 * @author Erich Schubert
 */
public class LinearScaling implements StaticScalingFunction {
  /**
   * Scaling factor
   */
	private double factor;
	
	/**
	 * Shift
	 */
	private double shift;
	
	/**
	 * Constructor with defaults resulting in identity.
	 */
	public LinearScaling(){
		this(1.0, 0.0);
	}
	
  /**
   * Constructor with scaling only.
   * 
   * @param factor Scaling factor
   */
  public LinearScaling(double factor){
    this(factor, 0.0);
  }

	/**
	 * Full constructor.
	 * 
	 * @param factor Scaling factor
	 * @param shift Shift value
	 */
	public LinearScaling(double factor, double shift){
		this.factor = factor;
		this.shift = shift;
	}

	@Override
	public double getScaled(double d) {
		return factor*d + shift;
	}
	
  @Override
  public double getMin() {
    return Double.NEGATIVE_INFINITY;
  }
  
  @Override
  public double getMax() {
    return Double.POSITIVE_INFINITY;
  }
}

@@ -41,16 +41,63 @@
 aling;%0A%0A
+import de.lmu.ifi.dbs.elki.math.DoubleMinMax;%0A%0A
 /**%0A * S
@@ -251,25 +251,26 @@
 actor%0A   */%0A
-%09
+  
 private doub
@@ -280,24 +280,25 @@
 factor;%0A
-%09%0A%09
+%0A  
 /**%0A
-%09
+  
  * Shift
@@ -298,22 +298,24 @@
 * Shift%0A
-%09
+  
  */%0A
-%09
+  
 private 
@@ -332,16 +332,17 @@
 ft;%0A
-%09%0A%09
+%0A  
 /**%0A
-%09
+  
  * C
@@ -389,22 +389,24 @@
 entity.%0A
-%09
+  
  */%0A
-%09
+  
 public L
@@ -419,20 +419,23 @@
 caling()
+ 
 %7B%0A
-%09%09
+    
 this(1.0
@@ -442,20 +442,20 @@
 , 0.0);%0A
-%09
+  
 %7D%0A
-%09
 %0A  /**%0A 
@@ -572,16 +572,17 @@
  factor)
+ 
 %7B%0A    th
@@ -607,14 +607,16 @@
  %7D%0A%0A
-%09
+  
 /**%0A
-%09
+  
  * F
@@ -636,14 +636,16 @@
 or.%0A
-%09
+  
  * %0A
-%09
+  
  * @
@@ -672,17 +672,18 @@
  factor%0A
-%09
+  
  * @para
@@ -706,14 +706,16 @@
 lue%0A
-%09
+  
  */%0A
-%09
+  
 publ
@@ -759,20 +759,23 @@
 e shift)
+ 
 %7B%0A
-%09%09
+    
 this.fac
@@ -788,18 +788,20 @@
 factor;%0A
-%09%09
+    
 this.shi
@@ -816,13 +816,271 @@
 ft;%0A
-%09%7D%0A%0A%09
+  %7D%0A%0A  /**%0A   * Constructor from a double minmax.%0A   *%0A   * @param minmax Minimum and Maximum%0A   */%0A  public LinearScaling(DoubleMinMax minmax) %7B%0A    this.factor = 1.0 / (minmax.getMax() - minmax.getMin());%0A    this.shift = -minmax.getMin() / this.factor;%0A  %7D%0A%0A  
 @Ove
@@ -1085,17 +1085,18 @@
 verride%0A
-%09
+  
 public d
@@ -1127,10 +1127,12 @@
 ) %7B%0A
-%09%09
+    
 retu
@@ -1140,17 +1140,19 @@
 n factor
-*
+ * 
 d + shif
@@ -1158,12 +1158,12 @@
 ft;%0A
-%09
+  
 %7D%0A
-%09
 %0A  @
@@ -1239,18 +1239,16 @@
 TY;%0A  %7D%0A
-  
 %0A  @Over
@@ -1320,10 +1320,388 @@
 TY;%0A  %7D%0A
-%7D
 %0A
+  /**%0A   * Make a linear scaling from a given minimum and maximum. The minimum will be%0A   * mapped to zero, the maximum to one.%0A   * %0A   * @param min Minimum%0A   * @param max Maximum%0A   * @return New linear scaling.%0A   */%0A  public static LinearScaling fromMinMax(double min, double max) %7B%0A    double zoom = 1.0 / (max - min);%0A    return new LinearScaling(zoom, -min / zoom);%0A  %7D%0A%7D

Enhance linear scaling API.