Skip to content

Commit

Permalink
Fixed decimal formatting in GPX 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mrihtar committed Oct 16, 2017
1 parent a776e49 commit 5798597
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
Expand Up @@ -322,14 +322,14 @@ public static String formatElevationAsString(Double elevation) {
return formatDoubleAsString(elevation, maximumFractionDigits);
}

public static String formatAccuracyAsString(Double elevation) {
public static String formatAccuracyAsString(Double accuracy) {
int maximumFractionDigits = preferences.getInt("accuracyAsStringMaximumFractionDigits", 6);
return formatDoubleAsString(elevation, maximumFractionDigits);
return formatDoubleAsString(accuracy, maximumFractionDigits);
}

public static String formatHeadingAsString(Double elevation) {
public static String formatHeadingAsString(Double heading) {
int maximumFractionDigits = preferences.getInt("headingAsStringMaximumFractionDigits", 1);
return formatDoubleAsString(elevation, maximumFractionDigits);
return formatDoubleAsString(heading, maximumFractionDigits);
}

public static String formatSpeedAsString(Double speed) {
Expand All @@ -348,10 +348,15 @@ public static BigDecimal formatPosition(Double longitudeOrLatitude) {
}

public static BigDecimal formatElevation(Double elevation) {
int maximumFractionDigits = preferences.getInt("elevationMaximumFractionDigits", 1);
int maximumFractionDigits = preferences.getInt("elevationMaximumFractionDigits", 2);
return formatBigDecimal(elevation, maximumFractionDigits);
}

public static BigDecimal formatAccuracy(Double accuracy) {
int maximumFractionDigits = preferences.getInt("accuracyMaximumFractionDigits", 6);
return formatBigDecimal(accuracy, maximumFractionDigits);
}

public static BigDecimal formatHeading(Double heading) {
int maximumFractionDigits = preferences.getInt("headingMaximumFractionDigits", 1);
return formatBigDecimal(heading, maximumFractionDigits);
Expand All @@ -362,6 +367,11 @@ public static BigDecimal formatSpeed(Double speed) {
return formatBigDecimal(speed, maximumFractionDigits);
}

public static BigDecimal formatTemperature(Double temperature) {
int maximumFractionDigits = preferences.getInt("temperatureMaximumFractionDigits", 1);
return formatBigDecimal(temperature, maximumFractionDigits);
}

public static double formatSpeedAsDouble(Double speed) {
int maximumFractionDigits = preferences.getInt("speedAsDoubleMaximumFractionDigits", 2);
return formatDouble(speed, maximumFractionDigits);
Expand Down
Expand Up @@ -166,7 +166,7 @@ private Double getSpeed(BigDecimal speed, String description, boolean hasSpeedIn
return result;
}

private String formatSpeed(String description, Double speed) {
private String formatSpeedDesc(String description, Double speed) {
if (isEmpty(speed) || parseSpeed(description) != null)
return description;
return (description != null ? description + " " : "") +
Expand Down Expand Up @@ -198,16 +198,16 @@ private List<Gpx.Wpt> createWayPoints(GpxRoute route, int startIndex, int endInd
wpt.setTime(isWriteTime() ? formatXMLTime(position.getTime()) : null);
wpt.setEle(isWriteElevation() ? formatElevation(position.getElevation()) : null);
wpt.setCourse(isWriteHeading() ? formatHeading(position.getHeading()) : null);
wpt.setSpeed(isWriteSpeed() && position.getSpeed() != null ? formatBigDecimal(kmhToMs(position.getSpeed()), 3) : null);
wpt.setSpeed(isWriteSpeed() && position.getSpeed() != null ? formatSpeed(kmhToMs(position.getSpeed())) : null);
if (isWriteSpeed() && reuseReadObjectsForWriting)
wpt.setCmt(formatSpeed(wpt.getCmt(), position.getSpeed()));
wpt.setCmt(formatSpeedDesc(wpt.getCmt(), position.getSpeed()));
if (isWriteHeading() && reuseReadObjectsForWriting)
wpt.setCmt(addHeading(wpt.getCmt(), position.getHeading()));
wpt.setName(isWriteName() ? splitNameAndDesc ? asName(position.getDescription()) : trim(position.getDescription()) : null);
wpt.setDesc(isWriteName() && splitNameAndDesc ? asDesc(position.getDescription(), wpt.getDesc()) : null);
wpt.setHdop(isWriteAccuracy() && position.getHdop() != null ? formatBigDecimal(position.getHdop(), 6) : null);
wpt.setPdop(isWriteAccuracy() && position.getPdop() != null ? formatBigDecimal(position.getPdop(), 6) : null);
wpt.setVdop(isWriteAccuracy() && position.getVdop() != null ? formatBigDecimal(position.getVdop(), 6) : null);
wpt.setHdop(isWriteAccuracy() && position.getHdop() != null ? formatAccuracy(position.getHdop()) : null);
wpt.setPdop(isWriteAccuracy() && position.getPdop() != null ? formatAccuracy(position.getPdop()) : null);
wpt.setVdop(isWriteAccuracy() && position.getVdop() != null ? formatAccuracy(position.getVdop()) : null);
wpt.setSat(isWriteAccuracy() && position.getSatellites() != null ? formatInt(position.getSatellites()) : null);
wpts.add(wpt);
}
Expand Down Expand Up @@ -244,16 +244,16 @@ private List<Gpx.Rte> createRoute(GpxRoute route, int startIndex, int endIndex)
rtept.setTime(isWriteTime() ? formatXMLTime(position.getTime()) : null);
rtept.setEle(isWriteElevation() ? formatElevation(position.getElevation()) : null);
rtept.setCourse(isWriteHeading() ? formatHeading(position.getHeading()) : null);
rtept.setSpeed(isWriteSpeed() && position.getSpeed() != null ? formatBigDecimal(kmhToMs(position.getSpeed()), 3) : null);
rtept.setSpeed(isWriteSpeed() && position.getSpeed() != null ? formatSpeed(kmhToMs(position.getSpeed())) : null);
if (isWriteSpeed() && reuseReadObjectsForWriting)
rtept.setCmt(formatSpeed(rtept.getCmt(), position.getSpeed()));
rtept.setCmt(formatSpeedDesc(rtept.getCmt(), position.getSpeed()));
if (isWriteHeading() && reuseReadObjectsForWriting)
rtept.setCmt(addHeading(rtept.getCmt(), position.getHeading()));
rtept.setName(isWriteName() ? splitNameAndDesc ? asName(position.getDescription()) : trim(position.getDescription()) : null);
rtept.setDesc(isWriteName() && splitNameAndDesc ? asDesc(position.getDescription(), rtept.getDesc()) : null);
rtept.setHdop(isWriteAccuracy() && position.getHdop() != null ? formatBigDecimal(position.getHdop(), 6) : null);
rtept.setPdop(isWriteAccuracy() && position.getPdop() != null ? formatBigDecimal(position.getPdop(), 6) : null);
rtept.setVdop(isWriteAccuracy() && position.getVdop() != null ? formatBigDecimal(position.getVdop(), 6) : null);
rtept.setHdop(isWriteAccuracy() && position.getHdop() != null ? formatAccuracy(position.getHdop()) : null);
rtept.setPdop(isWriteAccuracy() && position.getPdop() != null ? formatAccuracy(position.getPdop()) : null);
rtept.setVdop(isWriteAccuracy() && position.getVdop() != null ? formatAccuracy(position.getVdop()) : null);
rtept.setSat(isWriteAccuracy() && position.getSatellites() != null ? formatInt(position.getSatellites()) : null);
rte.getRtept().add(rtept);
}
Expand Down Expand Up @@ -292,12 +292,12 @@ private List<Gpx.Trk> createTrack(GpxRoute route, int startIndex, int endIndex)
trkpt.setEle(isWriteElevation() ? formatElevation(position.getElevation()) : null);
trkpt.setCourse(isWriteHeading() ? formatHeading(position.getHeading()) : null);
trkpt.setSpeed(isWriteSpeed() && position.getSpeed() != null ?
formatBigDecimal(kmhToMs(position.getSpeed()), 3) : null);
formatSpeed(kmhToMs(position.getSpeed())) : null);
trkpt.setName(isWriteName() ? splitNameAndDesc ? asName(position.getDescription()) : trim(position.getDescription()) : null);
trkpt.setDesc(isWriteName() && splitNameAndDesc ? asDesc(position.getDescription(), trkpt.getDesc()) : null);
trkpt.setHdop(isWriteAccuracy() && position.getHdop() != null ? formatBigDecimal(position.getHdop(), 6) : null);
trkpt.setPdop(isWriteAccuracy() && position.getPdop() != null ? formatBigDecimal(position.getPdop(), 6) : null);
trkpt.setVdop(isWriteAccuracy() && position.getVdop() != null ? formatBigDecimal(position.getVdop(), 6) : null);
trkpt.setHdop(isWriteAccuracy() && position.getHdop() != null ? formatAccuracy(position.getHdop()) : null);
trkpt.setPdop(isWriteAccuracy() && position.getPdop() != null ? formatAccuracy(position.getPdop()) : null);
trkpt.setVdop(isWriteAccuracy() && position.getVdop() != null ? formatAccuracy(position.getVdop()) : null);
trkpt.setSat(isWriteAccuracy() && position.getSatellites() != null ? formatInt(position.getSatellites()) : null);
trkseg.getTrkpt().add(trkpt);
}
Expand Down

0 comments on commit 5798597

Please sign in to comment.