private void addEle(double tmin, double tmax,
SortedMap<Double, BigDecimal> elev) throws MathException {
final int ne = elev.size();
if (ne == 0) {
// no elevation info
fEle.addSegmentFunction(new SegmentFunction(tmin, tmax,
new ConstantFunction(BigDecimal.ZERO)));
return;
}
final double ti0 = elev.firstKey().doubleValue();
final double tin = elev.lastKey().doubleValue();
if (elev.get(tmin) == null) {
// elevation data missing at start
fEle.addSegmentFunction(new SegmentFunction(tmin, ti0,
new ConstantFunction(elev.get(ti0))));
}
if (elev.get(tmax) == null) {
// elevation data missing at end
fEle.addSegmentFunction(new SegmentFunction(tin, tmax,
new ConstantFunction(elev.get(tin))));
}
switch (ne) {
case 1:
// only one point with elevation data
// nothing more to do
break;
case 2:
// two points with elevation data
fEle.addSegmentFunction(ti0, tin,
new LinearFunction(ti0, elev.get(ti0).doubleValue(), tin,
elev.get(tin).doubleValue()));
break;
default:
final double[] eleTime = new double[ne];
final double[] eleVal = new double[ne];
int i = 0;
for (Double d : elev.keySet()) {
eleTime[i] = d;
eleVal[i] = elev.get(d).doubleValue();
i++;
}
fEle.addSegmentFunction(new SegmentFunction(ti0, tin, interpolator
.interpolate(eleTime, eleVal)));
}
}