samer@0
|
1 /*
|
samer@0
|
2 * Copyright (c) 2000, Samer Abdallah, King's College London.
|
samer@0
|
3 * All rights reserved.
|
samer@0
|
4 *
|
samer@0
|
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
|
samer@0
|
6 * without even the implied warranty of MERCHANTABILITY or
|
samer@0
|
7 * FITNESS FOR A PARTICULAR PURPOSE.
|
samer@0
|
8 */
|
samer@0
|
9
|
samer@0
|
10 package samer.maths;
|
samer@0
|
11 import samer.core.util.*;
|
samer@0
|
12
|
samer@0
|
13 /**
|
samer@0
|
14 This class maps a given interval of real numbers
|
samer@0
|
15 to the interval [0,1], returning either the real
|
samer@0
|
16 number, or converting it to an integer between 0
|
samer@0
|
17 and a given value (defaults to 256).
|
samer@0
|
18 */
|
samer@0
|
19
|
samer@0
|
20 public class FunctionMap extends IMap
|
samer@0
|
21 {
|
samer@0
|
22 Function f, finv;
|
samer@0
|
23
|
samer@0
|
24 public FunctionMap(int m, Function fn) {
|
samer@0
|
25 setIntRange(m);
|
samer@0
|
26 f=fn; finv=fn.inverse();
|
samer@0
|
27 setDomain(0,1);
|
samer@0
|
28 }
|
samer@0
|
29
|
samer@0
|
30 public void setFunction(Function fn) {
|
samer@0
|
31 double t1=getDomainMin();
|
samer@0
|
32 double t2=getDomainMax();
|
samer@0
|
33 f=fn; finv=fn.inverse();
|
samer@0
|
34 setDomain(t1,t2);
|
samer@0
|
35 }
|
samer@0
|
36
|
samer@0
|
37 public double getDomainMin() { return finv.apply(super.getDomainMin()); }
|
samer@0
|
38 public double getDomainMax() { return finv.apply(super.getDomainMax()); }
|
samer@0
|
39 public void setDomain( double t1, double t2) {
|
samer@0
|
40 super.setDomain( f.apply(t1), f.apply(t2));
|
samer@0
|
41 }
|
samer@0
|
42
|
samer@0
|
43 public final double map( double t) { return super.map(f.apply(t)); }
|
samer@0
|
44 public final int clipInt( double t) { return super.clipInt(f.apply(t)); }
|
samer@0
|
45 public final int toInt( double t) { return super.toInt(f.apply(t)); }
|
samer@0
|
46 public double inverse(double t) { return finv.apply(super.inverse(t)); }
|
samer@0
|
47 public double inverseFromInt(int i) { return finv.apply(super.inverseFromInt(i)); }
|
samer@0
|
48 }
|
samer@0
|
49
|
samer@0
|
50
|
samer@0
|
51
|
samer@0
|
52
|
samer@0
|
53
|
samer@0
|
54
|
samer@0
|
55
|
samer@0
|
56
|