incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cframp...@apache.org
Subject svn commit: r1403836 - /incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/supportClasses/Range.as
Date Tue, 30 Oct 2012 19:33:40 GMT
Author: cframpton
Date: Tue Oct 30 19:33:39 2012
New Revision: 1403836

URL: http://svn.apache.org/viewvc?rev=1403836&view=rev
Log:
Fix for floating point errors showing up in NumericStepper. The errors stemmed from adding/subtracting
the offset (the minimum value) from the value that's being validated. We avoided float errors
in the rounding by scaling, but didn't account for errors when adjusting by the offset. Now,
we scale the offset as well to remove these errors.  Shouldn't round the offset value if the
interval is an integer. Only round when we are  scaling the values to remove the unneeded
precision. [SDK-31416][SDK-31417]

Modified:
    incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/supportClasses/Range.as

Modified: incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/supportClasses/Range.as
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/supportClasses/Range.as?rev=1403836&r1=1403835&r2=1403836&view=diff
==============================================================================
--- incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/supportClasses/Range.as
(original)
+++ incubator/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/supportClasses/Range.as
Tue Oct 30 19:33:39 2012
@@ -451,8 +451,7 @@ public class Range extends SkinnableComp
         
         var maxValue:Number = maximum - minimum;
         var scale:Number = 1;
-        
-        value -= minimum;
+        var offset:Number = minimum; // the offset from 0.
         
         // If interval isn't an integer, there's a possibility that the floating point 
         // approximation of value or value/interval will be slightly larger or smaller 
@@ -463,20 +462,26 @@ public class Range extends SkinnableComp
         // we scale by the implicit precision of the interval and then round.  For 
         // example if interval=0.01, then we scale by 100.    
         
-        if (interval != Math.round(interval)) 
-        { 
+        if (interval != Math.round(interval))
+        {
+            // calculate scale and compute new scaled values.
             const parts:Array = (new String(1 + interval)).split("."); 
             scale = Math.pow(10, parts[1].length);
             maxValue *= scale;
-            value = Math.round(value * scale);
+            offset *= scale;
             interval = Math.round(interval * scale);
-        }   
-        
+            value = Math.round((value * scale) - offset);
+        }
+        else
+        {
+            value -= offset;
+        }
+
         var lower:Number = Math.max(0, Math.floor(value / interval) * interval);
         var upper:Number = Math.min(maxValue, Math.floor((value + interval) / interval) *
interval);
         var validValue:Number = ((value - lower) >= ((upper - lower) / 2)) ? upper : lower;
         
-        return (validValue / scale) + minimum;
+        return (validValue + offset) / scale;
     }
     
     /**



Mime
View raw message