Bug 624781. When converting from app units to pixels use an intermediate double to do the calculation so no precision is lost. r=roc a=blocking
authorTimothy Nikkel <tnikkel@gmail.com>
Tue, 08 Feb 2011 13:29:26 -0600
changeset 62159 78778779f3706333863ffcbe44ff2b35a57fe5ab
parent 62158 a3a568807d829f04722d5bb9e2be1fa846f40058
child 62160 ffe65159d361f313c2f7dbf83e498acf112b0edd
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersroc, blocking
bugs624781
milestone2.0b12pre
Bug 624781. When converting from app units to pixels use an intermediate double to do the calculation so no precision is lost. r=roc a=blocking
gfx/src/nsCoord.h
gfx/src/nsPoint.h
gfx/src/nsRect.h
--- a/gfx/src/nsCoord.h
+++ b/gfx/src/nsCoord.h
@@ -406,16 +406,21 @@ inline PRInt32 NSToIntRound(float aValue
   return NS_lroundf(aValue);
 }
 
 inline PRInt32 NSToIntRoundUp(float aValue)
 {
   return PRInt32(NS_floorf(aValue + 0.5f));
 }
 
+inline PRInt32 NSToIntRoundUp(double aValue)
+{
+  return PRInt32(NS_floor(aValue + 0.5));
+}
+
 /* 
  * App Unit/Pixel conversions
  */
 inline nscoord NSFloatPixelsToAppUnits(float aPixels, float aAppUnitsPerPixel)
 {
   return NSToCoordRoundWithClamp(aPixels * aAppUnitsPerPixel);
 }
 
@@ -428,16 +433,21 @@ inline nscoord NSIntPixelsToAppUnits(PRI
   return r;
 }
 
 inline float NSAppUnitsToFloatPixels(nscoord aAppUnits, float aAppUnitsPerPixel)
 {
   return (float(aAppUnits) / aAppUnitsPerPixel);
 }
 
+inline double NSAppUnitsToDoublePixels(nscoord aAppUnits, nscoord aAppUnitsPerPixel)
+{
+  return (double(aAppUnits) / double(aAppUnitsPerPixel));
+}
+
 inline PRInt32 NSAppUnitsToIntPixels(nscoord aAppUnits, float aAppUnitsPerPixel)
 {
   return NSToIntRound(float(aAppUnits) / aAppUnitsPerPixel);
 }
 
 inline float NSCoordScale(nscoord aCoord, PRInt32 aFromAPP, PRInt32 aToAPP)
 {
   return (NSCoordToFloat(aCoord) * aToAPP) / aFromAPP;
--- a/gfx/src/nsPoint.h
+++ b/gfx/src/nsPoint.h
@@ -122,18 +122,18 @@ struct nsIntPoint {
     return nsIntPoint(-x, -y);
   }
   void MoveTo(PRInt32 aX, PRInt32 aY) {x = aX; y = aY;}
 };
 
 inline nsIntPoint
 nsPoint::ToNearestPixels(nscoord aAppUnitsPerPixel) const {
   return nsIntPoint(
-      NSToIntRoundUp(NSAppUnitsToFloatPixels(x, float(aAppUnitsPerPixel))),
-      NSToIntRoundUp(NSAppUnitsToFloatPixels(y, float(aAppUnitsPerPixel))));
+      NSToIntRoundUp(NSAppUnitsToDoublePixels(x, aAppUnitsPerPixel)),
+      NSToIntRoundUp(NSAppUnitsToDoublePixels(y, aAppUnitsPerPixel)));
 }
 
 inline nsPoint
 nsPoint::ConvertAppUnits(PRInt32 aFromAPP, PRInt32 aToAPP) const {
   if (aFromAPP != aToAPP) {
     nsPoint point;
     point.x = NSToCoordRound(NSCoordScale(x, aFromAPP, aToAPP));
     point.y = NSToCoordRound(NSCoordScale(y, aFromAPP, aToAPP));
--- a/gfx/src/nsRect.h
+++ b/gfx/src/nsRect.h
@@ -386,22 +386,22 @@ nsRect::ConvertAppUnitsRoundIn(PRInt32 a
   return rect;
 }
 
 // scale the rect but round to preserve centers
 inline nsIntRect
 nsRect::ToNearestPixels(nscoord aAppUnitsPerPixel) const
 {
   nsIntRect rect;
-  rect.x = NSToIntRoundUp(NSAppUnitsToFloatPixels(x, float(aAppUnitsPerPixel)));
-  rect.y = NSToIntRoundUp(NSAppUnitsToFloatPixels(y, float(aAppUnitsPerPixel)));
-  rect.width  = NSToIntRoundUp(NSAppUnitsToFloatPixels(XMost(),
-                               float(aAppUnitsPerPixel))) - rect.x;
-  rect.height = NSToIntRoundUp(NSAppUnitsToFloatPixels(YMost(),
-                               float(aAppUnitsPerPixel))) - rect.y;
+  rect.x = NSToIntRoundUp(NSAppUnitsToDoublePixels(x, aAppUnitsPerPixel));
+  rect.y = NSToIntRoundUp(NSAppUnitsToDoublePixels(y, aAppUnitsPerPixel));
+  rect.width  = NSToIntRoundUp(NSAppUnitsToDoublePixels(XMost(),
+                               aAppUnitsPerPixel)) - rect.x;
+  rect.height = NSToIntRoundUp(NSAppUnitsToDoublePixels(YMost(),
+                               aAppUnitsPerPixel)) - rect.y;
   return rect;
 }
 
 // scale the rect but round to smallest containing rect
 inline nsIntRect
 nsRect::ToOutsidePixels(nscoord aAppUnitsPerPixel) const
 {
   nsIntRect rect;