/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2011 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
package com.sandwell.JavaSimulation;

/**
 * A Time-Varying-Value implementation to bridge the discrete->continuous value
 * gap.
 */
public class TVV {

private double datumTime = 0.0d;
private double datumVal = 0.0d;
private double datumRate = 0.0d;

public TVV() {}

public double getValueAtTime(double time) {
	double dt = time - datumTime;

	// Required for a rate of infinity
	if( dt == 0.0 )
		return datumVal;

	return datumVal + dt * datumRate;
}

public void setValue(double time, double val) {
	// Clear the value if it is essentially 0.0
	if (Tester.equalCheckTolerance(val, 0.0d))
		val = 0.0;
	this.set(time, val, datumRate);
}

public void setRate(double time, double rate) {

	// Check if we're essentially 0
	if( Tester.equalCheckTolerance(rate, 0.0d) )
	    rate = 0;

	double newDatum = getValueAtTime(time);
	if (Tester.equalCheckTolerance(newDatum, 0.0d))
		newDatum = 0.0;

	set(time, newDatum, rate);
}

public void set(double time, double val, double rate) {
	datumVal = val;
	datumRate = rate;
	datumTime = time;
}

public double getRate() {
	return datumRate;
}

}

@@ -1105,397 +1105,131 @@
  %7B%0A%09
-// Clear the value if it is essentially 0.0%0A%09if (Tester.equalCheckTolerance(val, 0.0d))%0A%09%09val = 0.0;%0A%09this.set(time, val, datumRate);%0A%7D%0A%0Apublic void setRate(double time, double rate) %7B%0A%0A%09// Check if we're essentially 0%0A%09if( Tester.equalCheckTolerance(rate, 0.0d) )%0A%09    rate = 0;%0A%0A%09double newDatum = getValueAtTime(time);%0A%09if (Tester.equalCheckTolerance(newDatum, 0.0d))%0A%09%09newDatum = 0.0;%0A
+this.set(time, val, datumRate);%0A%7D%0A%0Apublic void setRate(double time, double rate) %7B%0A%09double newDatum = getValueAtTime(time);
 %0A%09se

remove tolerance checking from TVV, rely on callers to do so if they wish