view src/samer/maths/FunctionMap.java @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
line wrap: on
line source
/*
 *	Copyright (c) 2000, Samer Abdallah, King's College London.
 *	All rights reserved.
 *
 *	This software is provided AS iS and WITHOUT ANY WARRANTY;
 *	without even the implied warranty of MERCHANTABILITY or
 *	FITNESS FOR A PARTICULAR PURPOSE.
 */

package samer.maths;
import samer.core.util.*;

/**
	This class maps a given interval of real numbers
	to the interval [0,1], returning either the real
	number, or converting it to an integer between 0
	and a given value (defaults to 256).
 */

public class FunctionMap extends IMap
{
	Function f, finv;

	public FunctionMap(int m, Function fn) {
		setIntRange(m);
		f=fn; finv=fn.inverse();
		setDomain(0,1);
	}

	public void setFunction(Function fn) {
		double t1=getDomainMin();
		double t2=getDomainMax();
		f=fn; finv=fn.inverse();
		setDomain(t1,t2);
	}

	public double getDomainMin() { return finv.apply(super.getDomainMin()); }
	public double getDomainMax() { return finv.apply(super.getDomainMax()); }
	public void setDomain( double t1, double t2)	{
		super.setDomain( f.apply(t1), f.apply(t2));
	}

	public final double map( double t) { return super.map(f.apply(t)); }
	public final int clipInt( double t) { return super.clipInt(f.apply(t)); }
	public final int toInt( double t) { return super.toInt(f.apply(t)); }
	public double inverse(double t) { return finv.apply(super.inverse(t)); }
	public double inverseFromInt(int i) { return finv.apply(super.inverseFromInt(i)); }
}