(no commit message)
authorErik Brakkee <erik@brakkee.org>
Sat, 26 Sep 2009 13:50:09 +0000 (13:50 +0000)
committerErik Brakkee <erik@brakkee.org>
Sat, 26 Sep 2009 13:50:09 +0000 (13:50 +0000)
gps/src/main/java/org/wamblee/gps/track/FilteredTrack.java
gps/src/main/java/org/wamblee/gps/track/TrackImpl.java
gps/src/main/java/org/wamblee/gpx/TrackStatistics.java

index ddcaa4964adb40b09098e8f8d3060948dd68af77..46e969d83ed08adcf469de8bfe2d0b68a16eabdd 100644 (file)
@@ -1,5 +1,6 @@
 package org.wamblee.gps.track;
 
+import java.io.Serializable;
 import java.util.List;
 
 import org.wamblee.gps.geometry.Point;
@@ -8,7 +9,7 @@ import org.wamblee.gps.geometry.Point;
  * Filtered track provides a filtered view on a track. 
  * Changes in the filter are also represented by the filtered track. 
  */
-public class FilteredTrack implements Track {
+public class FilteredTrack implements Track, Serializable {
     
     private TrackFilter _filter; 
     private Track _originalTrack;
index 12513f3e1c09c258da460f890049911346b374bc..ce8e23e3f38ee40917ed8dcc2f746e2d8ac1f459 100644 (file)
@@ -1,12 +1,13 @@
 package org.wamblee.gps.track;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
 import org.wamblee.gps.geometry.Point;
 
-public class TrackImpl implements Track {
+public class TrackImpl implements Track, Serializable {
 
     private String _description; 
     private List<TrackSegment> _segments; 
@@ -50,7 +51,7 @@ public class TrackImpl implements Track {
                 result = Math.min(result, segment.getMinCoordinate(i));
             }
         }
-        return 0;
+        return result;
     }
     
     @Override
@@ -64,7 +65,7 @@ public class TrackImpl implements Track {
                 result = Math.max(result, segment.getMaxCoordinate(i));
             }
         }
-        return 0;
+        return result;
     }
     
     @Override
index 455ca985c0b5c245fe6a9bd40d5986a99a3eaf6e..964ac6eb639ae9195e9cd70fe162b1b303942a46 100644 (file)
@@ -20,70 +20,74 @@ import org.wamblee.gps.geometry.ReferenceCoordinateSystem;
 import org.wamblee.gps.track.TrackSegment;
 
 public class TrackStatistics implements Serializable {
-    
-    private TrackSegment _track; 
-    
+
+    private TrackSegment _track;
+
     public TrackStatistics(TrackSegment aTrack) {
-        _track = aTrack; 
+        _track = aTrack;
     }
-    
-    public void writeHeightProfilePng(OutputStream aStream, int aWidth, int aHeight) throws IOException {
-        List<Pair<Double,Double>> data = computeElevationProfile();
+
+    public void writeHeightProfilePng(OutputStream aStream, int aWidth,
+            int aHeight) throws IOException {
+        List<Pair<Double, Double>> data = computeElevationProfile();
         XYSeriesCollection dataset = createDataset(data, "height");
-        JFreeChart chart = ChartFactory.createXYLineChart(
-                "Height Profile", 
-                "Distance(km)",
-                "Height(m)",
-                dataset,
-                PlotOrientation.VERTICAL,
-                true,
-                true,
-                false);
+        JFreeChart chart = ChartFactory.createXYLineChart("Height Profile",
+                "Distance(km)", "Height(m)", dataset, PlotOrientation.VERTICAL,
+                true, true, false);
         chart.setBackgroundPaint(Color.WHITE);
         ChartUtilities.writeChartAsPNG(aStream, chart, aWidth, aHeight);
     }
-    
-    private static XYSeriesCollection createDataset(List<Pair<Double, Double>> aHeightProfile, String aName) {
+
+    private static XYSeriesCollection createDataset(
+            List<Pair<Double, Double>> aHeightProfile, String aName) {
         XYSeries series = new XYSeries(aName, false);
-        for (Pair<Double,Double> point: aHeightProfile) { 
-            series.add(point.getFirst()/1000.0, point.getSecond());
+        for (Pair<Double, Double> point : aHeightProfile) {
+            series.add(point.getFirst() / 1000.0, point.getSecond());
         }
         XYSeriesCollection dataset = new XYSeriesCollection(series);
         return dataset;
     }
-    
+
     public List<Pair<Double, Double>> computeElevationProfile() {
-        List<Pair<Double,Double>> results = new ArrayList<Pair<Double,Double>>();
-        double distance = 0.0; 
-        for (int i = 0; i < _track.size(); i++) { 
+        List<Pair<Double, Double>> results = new ArrayList<Pair<Double, Double>>();
+        double distance = 0.0;
+        for (int i = 0; i < _track.size(); i++) {
             Point point = _track.getPoint(i);
-            results.add(new Pair<Double,Double>(distance, point.getCoordinates().getX3()));
-            if ( i+1 < _track.size()) { 
-                Point nextPoint = _track.getPoint(i+1); 
-                distance += ReferenceCoordinateSystem.distance(point, nextPoint);
+            results.add(new Pair<Double, Double>(distance, point
+                    .getCoordinates().getX3()));
+            if (i + 1 < _track.size()) {
+                Point nextPoint = _track.getPoint(i + 1);
+                distance += ReferenceCoordinateSystem
+                        .distance(point, nextPoint);
             }
         }
-        return results; 
+        return results;
     }
-    
+
     public double getTotalClimb() {
-        
-        List<Pair<Double,Double>> data = computeElevationProfile(); 
+
+        List<Pair<Double, Double>> data = computeElevationProfile();
         double result = 0.0;
-        
+        if ( data.size() == 0 ) { 
+            return result; 
+        }
+
         double lastHeight = data.get(0).getSecond();
-        for ( int i = 1; i < data.size(); i++) { 
+        for (int i = 1; i < data.size(); i++) {
             double height = data.get(i).getSecond();
-            if ( height > lastHeight) { 
-                result += (height-lastHeight); 
+            if (height > lastHeight) {
+                result += (height - lastHeight);
             }
-            lastHeight = height; 
+            lastHeight = height;
         }
-        return result; 
+        return result;
     }
-    
-    public double getDistance() { 
-        List<Pair<Double,Double>> data = computeElevationProfile(); 
-        return data.get(data.size()-1).getFirst();
+
+    public double getDistance() {
+        List<Pair<Double, Double>> data = computeElevationProfile();
+        if (data.size() == 0) {
+            return 0.0;
+        }
+        return data.get(data.size() - 1).getFirst();
     }
 }