X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FAltitude.java;h=3328817fa6cccdb0dfb88e36c228412c0239fa33;hp=495e84491746f4c1c011cb4b0d64cb1c7b0bde91;hb=112bb0c9b46894adca9a33ed8c99ea712b253185;hpb=54b9d8bc8f0025ccf97a67d9dd217ef1f9cf082f diff --git a/tim/prune/data/Altitude.java b/tim/prune/data/Altitude.java index 495e844..3328817 100644 --- a/tim/prune/data/Altitude.java +++ b/tim/prune/data/Altitude.java @@ -61,6 +61,24 @@ public class Altitude _valid = true; } + /** + * @return an exact copy of this Altitude object + */ + public Altitude clone() + { + return new Altitude(_stringValue, _format); + } + + /** + * Reset the altitude parameters to the same as the given object + * @param inClone clone object to copy + */ + public void reset(Altitude inClone) + { + _value = inClone._value; + _format = inClone._format; + _valid = inClone._valid; + } /** * @return true if the value could be parsed @@ -114,7 +132,9 @@ public class Altitude public String getStringValue(Format inFormat) { if (!_valid) {return "";} - if (inFormat == _format && _stringValue != null && !_stringValue.equals("")) { + // Return string value if the same format or "no format" was requested + if ((inFormat == _format || inFormat == Format.NO_FORMAT) + && _stringValue != null && !_stringValue.equals("")) { return _stringValue; } return "" + getValue(inFormat); @@ -155,4 +175,30 @@ public class Altitude int newValue = startValue + (int) ((endValue - startValue) * inFrac); return new Altitude(newValue, altFormat); } + + /** + * Add the given offset to the current altitude + * @param inOffset offset as double + * @param inFormat format of offset, feet or metres + * @param inDecimals number of decimal places + */ + public void addOffset(double inOffset, Format inFormat, 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 (inFormat != _format) + { + if (inFormat == Format.FEET) + offset = inOffset * CONVERT_FEET_TO_METRES; + else + offset = inOffset * CONVERT_METRES_TO_FEET; + } + // Add the offset + double newValue = Double.parseDouble(_stringValue.trim()) + offset; + _value = (int) newValue; + _stringValue = NumberUtils.formatNumber(newValue, numDecimals); + } }