/*
 * 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) {
	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;

	set(time, getValueAtTime(time), rate);
}

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

	// Clear the value if it is essentially 0.0
	if( Tester.equalCheckTolerance(datumVal, 0.0d) ) {
		datumVal = 0.0;
	}
}

public double getRate() {
	return datumRate;
}

}

@@ -862,17 +862,16 @@
  TVV() %7B
-%0A
 %7D%0A%0Apubli
@@ -1100,16 +1100,118 @@
  val) %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.se
@@ -1383,25 +1383,33 @@
  = 0;%0A%0A%09
-set(time,
+double newDatum =
  getValu
@@ -1421,16 +1421,105 @@
 me(time)
+;%0A%09if (Tester.equalCheckTolerance(newDatum, 0.0d))%0A%09%09newDatum = 0.0;%0A%0A%09set(time, newDatum
 , rate);
@@ -1636,127 +1636,8 @@
 ime;
-%0A%0A%09// Clear the value if it is essentially 0.0%0A%09if( Tester.equalCheckTolerance(datumVal, 0.0d) ) %7B%0A%09%09datumVal = 0.0;%0A%09%7D
 %0A%7D%0A%0A

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