]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/data/Coordinate.java
Version 3, August 2007
[GpsPrune.git] / tim / prune / data / Coordinate.java
index e297a8d7036fdf7209f6ad15635d70b3c12f26bf..8a81850cba90e7c429696a3062dc3e5f96681a66 100644 (file)
@@ -15,6 +15,9 @@ public abstract class Coordinate
        public static final int FORMAT_DEG_MIN = 11;
        public static final int FORMAT_DEG = 12;
        public static final int FORMAT_DEG_WITHOUT_CARDINAL = 13;
+       public static final int FORMAT_DEG_WHOLE_MIN = 14;
+       public static final int FORMAT_DEG_MIN_SEC_WITH_SPACES = 15;
+       public static final int FORMAT_CARDINAL = 16;
        public static final int FORMAT_NONE = 19;
 
        // Instance variables
@@ -128,22 +131,25 @@ public abstract class Coordinate
         * Constructor
         * @param inValue value of coordinate
         * @param inFormat format to use
+        * @param inCardinal cardinal
         */
-       protected Coordinate(double inValue, int inFormat)
+       protected Coordinate(double inValue, int inFormat, int inCardinal)
        {
                _asDouble = inValue;
                // Calculate degrees, minutes, seconds
-               _degrees = (int) inValue;
-               double numMins = (Math.abs(_asDouble)-Math.abs(_degrees)) * 60.0;
+               _degrees = (int) Math.abs(inValue);
+               double numMins = (Math.abs(_asDouble)-_degrees) * 60.0;
                _minutes = (int) numMins;
                double numSecs = (numMins - _minutes) * 60.0;
                _seconds = (int) numSecs;
                _fracs = (int) ((numSecs - _seconds) * 10);
                // Make a string to display on screen
+               _cardinal = inCardinal;
                _originalFormat = FORMAT_NONE;
                if (inFormat == FORMAT_NONE) inFormat = FORMAT_DEG_WITHOUT_CARDINAL;
                _originalString = output(inFormat);
                _originalFormat = inFormat;
+               _valid = true;
        }
 
 
@@ -193,20 +199,46 @@ public abstract class Coordinate
                        // format as specified
                        switch (inFormat)
                        {
-                               case FORMAT_DEG_MIN_SEC: {
+                               case FORMAT_DEG_MIN_SEC:
+                               {
                                        StringBuffer buffer = new StringBuffer();
                                        buffer.append(PRINTABLE_CARDINALS[_cardinal])
                                                .append(threeDigitString(_degrees)).append('°')
                                                .append(twoDigitString(_minutes)).append('\'')
                                                .append(twoDigitString(_seconds)).append('.')
                                                .append(_fracs);
-                                       answer = buffer.toString(); break;
+                                       answer = buffer.toString();
+                                       break;
+                               }
+                               case FORMAT_DEG_MIN:
+                               {
+                                       answer = "" + PRINTABLE_CARDINALS[_cardinal] + threeDigitString(_degrees) + "°"
+                                               + (_minutes + _seconds / 60.0 + _fracs / 600.0) + "'";
+                                       break;
+                               }
+                               case FORMAT_DEG_WHOLE_MIN:
+                               {
+                                       answer = "" + PRINTABLE_CARDINALS[_cardinal] + threeDigitString(_degrees) + "°"
+                                               + (int) Math.floor(_minutes + _seconds / 60.0 + _fracs / 600.0 + 0.5) + "'";
+                                       break;
                                }
-                               case FORMAT_DEG_MIN: answer = "" + PRINTABLE_CARDINALS[_cardinal] + threeDigitString(_degrees) + "°"
-                                       + (_minutes + _seconds / 60.0 + _fracs / 600.0); break;
                                case FORMAT_DEG:
-                               case FORMAT_DEG_WITHOUT_CARDINAL: answer = (_asDouble<0.0?"-":"")
-                               + (_degrees + _minutes / 60.0 + _seconds / 3600.0 + _fracs / 36000.0); break;
+                               case FORMAT_DEG_WITHOUT_CARDINAL:
+                               {
+                                       answer = (_asDouble<0.0?"-":"")
+                                               + (_degrees + _minutes / 60.0 + _seconds / 3600.0 + _fracs / 36000.0);
+                                       break;
+                               }
+                               case FORMAT_DEG_MIN_SEC_WITH_SPACES:
+                               {
+                                       answer = "" + _degrees + " " + _minutes + " " + _seconds + "." + _fracs;
+                                       break;
+                               }
+                               case FORMAT_CARDINAL:
+                               {
+                                       answer = "" + PRINTABLE_CARDINALS[_cardinal];
+                                       break;
+                               }
                        }
                }
                return answer;