- int endValue = inEnd.getValue(altFormat);
- int newValue = startValue
- + (int) ((endValue - startValue) * 1.0 / (inNumSteps + 1) * (inIndex + 1));
- return new Altitude(newValue, altFormat);
+ int endValue = inEnd.getValue(altUnit);
+ // interpolate between start and end
+ int newValue = startValue + (int) ((endValue - startValue) * inFrac);
+ return new Altitude(newValue, altUnit);
+ }
+
+ /**
+ * Add the given offset to the current altitude
+ * @param inOffset offset as double
+ * @param inUnit unit of offset, feet or metres
+ * @param inDecimals number of decimal places
+ */
+ public void addOffset(double inOffset, Unit inUnit, int inDecimals)
+ {
+ // Use the maximum number of decimal places from current value and offset
+ int numDecimals = NumberUtils.getDecimalPlaces(_stringValue);
+ if (numDecimals < inDecimals) {numDecimals = inDecimals;}
+ // Convert offset to correct units
+ double offset = inOffset;
+ if (inUnit != _unit && inUnit != null)
+ {
+ offset = inOffset / inUnit.getMultFactorFromStd() * _unit.getMultFactorFromStd();
+ }
+ // FIXME: The following will fail if _stringValue is null - not sure how it can get in that state!
+ if (_stringValue == null) System.err.println("*** Altitude.addOffset - how did the string value get to be null?");
+ // Add the offset
+ double newValue = Double.parseDouble(_stringValue.trim()) + offset;
+ _value = (int) newValue;
+ _stringValue = NumberUtils.formatNumberUk(newValue, numDecimals);