Bug 445081. Factor out code to create nsSVGUtils::ComputeNormalizedHypotenuse. r=longsonr,sr=mats
authorRobert O'Callahan <robert@ocallahan.org>
Tue, 15 Jul 2008 15:12:40 +1200
changeset 15937 4624fef36355572e0e4ce040cef34f6f378da39c
parent 15936 8ffe8a29e52b0c9a74dcb868e6ed6e0581475503
child 15938 6c8c95fcaf9b3178ca046452d0041d7595eb19d8
push id619
push userrocallahan@mozilla.com
push dateTue, 15 Jul 2008 03:12:49 +0000
treeherderautoland@4624fef36355 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr, mats
bugs445081
milestone1.9.1a1pre
Bug 445081. Factor out code to create nsSVGUtils::ComputeNormalizedHypotenuse. r=longsonr,sr=mats
content/svg/content/src/nsSVGSVGElement.cpp
layout/svg/base/src/nsSVGGlyphFrame.cpp
layout/svg/base/src/nsSVGUtils.cpp
layout/svg/base/src/nsSVGUtils.h
--- a/content/svg/content/src/nsSVGSVGElement.cpp
+++ b/content/svg/content/src/nsSVGSVGElement.cpp
@@ -1396,17 +1396,17 @@ nsSVGSVGElement::GetLength(PRUint8 aCtxT
   }
 
   switch (aCtxType) {
   case nsSVGUtils::X:
     return w;
   case nsSVGUtils::Y:
     return h;
   case nsSVGUtils::XY:
-    return (float)sqrt((w*w+h*h)/2.0);
+    return nsSVGUtils::ComputeNormalizedHypotenuse(w, h);
   }
   return 0;
 }
 
 float
 nsSVGSVGElement::GetMMPerPx(PRUint8 aCtxType)
 {
   if (mCoordCtxMmPerPx == 0.0f) {
--- a/layout/svg/base/src/nsSVGGlyphFrame.cpp
+++ b/layout/svg/base/src/nsSVGGlyphFrame.cpp
@@ -1225,17 +1225,17 @@ nsSVGGlyphFrame::EnsureTextRun(float *aD
       if (!GetGlobalTransform(&m))
         return PR_FALSE;
     }
 
     // The context scale is the ratio of the length of the transformed
     // diagonal vector (1,1) to the length of the untransformed diagonal
     // (which is sqrt(2)).
     gfxPoint p = m.Transform(gfxPoint(1, 1)) - m.Transform(gfxPoint(0, 0));
-    double contextScale = sqrt((p.x*p.x + p.y*p.y)/2);
+    double contextScale = nsSVGUtils::ComputeNormalizedHypotenuse(p.x, p.y);
 
     nsCAutoString langGroup;
     nsIAtom *langGroupAtom = presContext->GetLangGroup();
     if (langGroupAtom) {
       const char* lg;
       langGroupAtom->GetUTF8String(&lg);
       langGroup.Assign(lg);
     }
--- a/layout/svg/base/src/nsSVGUtils.cpp
+++ b/layout/svg/base/src/nsSVGUtils.cpp
@@ -940,33 +940,39 @@ nsSVGUtils::NotifyAncestorsOfFilterRegio
                             (aFrame->GetProperty(nsGkAtoms::filter));
       property->Invalidate();
     }
     aFrame = aFrame->GetParent();
   }
 }
 
 float
+nsSVGUtils::ComputeNormalizedHypotenuse(float aWidth, float aHeight)
+{
+  return sqrt((aWidth*aWidth + aHeight*aHeight)/2);
+}
+
+float
 nsSVGUtils::ObjectSpace(nsIDOMSVGRect *aRect, nsSVGLength2 *aLength)
 {
   float fraction, axis;
 
   switch (aLength->GetCtxType()) {
   case X:
     aRect->GetWidth(&axis);
     break;
   case Y:
     aRect->GetHeight(&axis);
     break;
   case XY:
   {
     float width, height;
     aRect->GetWidth(&width);
     aRect->GetHeight(&height);
-    axis = sqrt(width * width + height * height)/sqrt(2.0f);
+    axis = ComputeNormalizedHypotenuse(width, height);
   }
   }
 
   if (aLength->IsPercentage()) {
     fraction = aLength->GetAnimValInSpecifiedUnits() / 100;
   } else
     fraction = aLength->GetAnimValue(static_cast<nsSVGSVGElement*>
                                                 (nsnull));
--- a/layout/svg/base/src/nsSVGUtils.h
+++ b/layout/svg/base/src/nsSVGUtils.h
@@ -278,16 +278,21 @@ public:
   /*
    * Update the filter invalidation region for ancestor frames, if relevant.
    */
   static void NotifyAncestorsOfFilterRegionChange(nsIFrame *aFrame);
 
   /* enum for specifying coordinate direction for ObjectSpace/UserSpace */
   enum ctxDirection { X, Y, XY };
 
+  /**
+   * Computes sqrt((aWidth^2 + aHeight^2)/2);
+   */
+  static float ComputeNormalizedHypotenuse(float aWidth, float aHeight);
+
   /* Computes the input length in terms of object space coordinates.
      Input: rect - bounding box
             length - length to be converted
   */
   static float ObjectSpace(nsIDOMSVGRect *aRect, nsSVGLength2 *aLength);
 
   /* Computes the input length in terms of user space coordinates.
      Input: content - object to be used for determining user space