sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1513625 - in /sis/branches/0.3/core/sis-utility/src: main/java/org/apache/sis/measure/AngleFormat.java test/java/org/apache/sis/measure/AngleFormatTest.java
Date Tue, 13 Aug 2013 19:49:00 GMT
Author: desruisseaux
Date: Tue Aug 13 19:49:00 2013
New Revision: 1513625

URL: http://svn.apache.org/r1513625
Log:
Ported bug fix for SIS-120.

Modified:
    sis/branches/0.3/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java
    sis/branches/0.3/core/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java

Modified: sis/branches/0.3/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/0.3/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java?rev=1513625&r1=1513624&r2=1513625&view=diff
==============================================================================
--- sis/branches/0.3/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java
[UTF-8] (original)
+++ sis/branches/0.3/core/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java
[UTF-8] Tue Aug 13 19:49:00 2013
@@ -833,8 +833,16 @@ scan:   for (int i=0; i<length;) {
                 minutes = rint(minutes * puissance) / puissance;
             }
             final double correction = truncate(minutes / 60);
-            minutes -= correction * 60;
-            degrees += correction;
+            if (correction != 0) {
+                /*
+                 * We really need to NOT perform the addition if correction == 0, even if
its look like
+                 * mathematically equivalent, because we want to preserve the sign of 'degrees'
in case
+                 * of negative zero. This is because in Java, -0.0 + 0 == +0.0 while we really
need to
+                 * keep the negative sign in -0.0.
+                 */
+                minutes -= correction * 60;
+                degrees += correction;
+            }
         }
         /*
          * At this point the 'degrees', 'minutes' and 'seconds' variables contain the final
values

Modified: sis/branches/0.3/core/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/0.3/core/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java?rev=1513625&r1=1513624&r2=1513625&view=diff
==============================================================================
--- sis/branches/0.3/core/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
[UTF-8] (original)
+++ sis/branches/0.3/core/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
[UTF-8] Tue Aug 13 19:49:00 2013
@@ -73,6 +73,7 @@ public final strictfp class AngleFormatT
         assertEquals("-12.247°",  formatAndParse(f, new Angle   (-12.247)));
         assertEquals( "13.214°N", formatAndParse(f, new Latitude( 13.214)));
         assertEquals( "12.782°S", formatAndParse(f, new Latitude(-12.782)));
+        assertEquals("-00.010°",  formatAndParse(f, new Angle   (-0.01)));
     }
 
     /**
@@ -83,9 +84,10 @@ public final strictfp class AngleFormatT
         final AngleFormat f = new AngleFormat("DD.ddd°", Locale.FRANCE);
         assertEquals(3, f.getMinimumFractionDigits());
         assertEquals(3, f.getMaximumFractionDigits());
-        assertEquals( "DD.ddd°", f.toPattern());
-        assertEquals("19,457°E", formatAndParse(f, new Longitude( 19.457)));
-        assertEquals("78,124°S", formatAndParse(f, new Latitude (-78.124)));
+        assertEquals( "DD.ddd°",  f.toPattern());
+        assertEquals( "19,457°E", formatAndParse(f, new Longitude( 19.457)));
+        assertEquals( "78,124°S", formatAndParse(f, new Latitude (-78.124)));
+        assertEquals("-00,010°",  formatAndParse(f, new Angle    (-0.01)));
     }
 
     /**
@@ -96,9 +98,10 @@ public final strictfp class AngleFormatT
         final AngleFormat f = new AngleFormat("DDddd", Locale.CANADA);
         assertEquals(3, f.getMinimumFractionDigits());
         assertEquals(3, f.getMaximumFractionDigits());
-        assertEquals("DDddd",  f.toPattern());
-        assertEquals("19457E", formatAndParse(f, new Longitude( 19.457)));
-        assertEquals("78124S", formatAndParse(f, new Latitude (-78.124)));
+        assertEquals( "DDddd",  f.toPattern());
+        assertEquals( "19457E", formatAndParse(f, new Longitude( 19.457)));
+        assertEquals( "78124S", formatAndParse(f, new Latitude (-78.124)));
+        assertEquals("-00010",  formatAndParse(f, new Angle    (-0.01)));
     }
 
     /**
@@ -113,6 +116,7 @@ public final strictfp class AngleFormatT
         assertEquals( "DD°MM.m", f.toPattern());
         assertEquals( "12°30.0", formatAndParse(f, new Angle( 12.50)));
         assertEquals("-10°15.0", formatAndParse(f, new Angle(-10.25)));
+        assertEquals("-00°00.6", formatAndParse(f, new Angle( -0.01)));
     }
 
     /**
@@ -127,6 +131,7 @@ public final strictfp class AngleFormatT
         assertEquals( "DD°MM′SS.sss″", f.toPattern());
         assertEquals( "12°30′56.250″", formatAndParse(f, new Angle( 12.515625)));
         assertEquals("-12°30′56.250″", formatAndParse(f, new Angle(-12.515625)));
+        assertEquals("-00°00′36.000″", formatAndParse(f, new Angle( -0.01)));
     }
 
     /**



Mime
View raw message