Bug 1325487 - Improve SVGContentUtils::ComputeNormalizedHypotenuse and use it more r=dholbert
authorRobert Longson <longsonr@gmail.com>
Fri, 23 Dec 2016 17:28:13 +0000
changeset 453568 f520551796df689734fa8c0c02eeab4e0eb2e3da
parent 453567 fb7b4a449847ab2e0149a4a3b1d9f7b511414cca
child 453569 88b62488ca303fea0b7ceebc04e5a59c138ebafe
push id39711
push userdmitchell@mozilla.com
push dateFri, 23 Dec 2016 21:59:47 +0000
reviewersdholbert
bugs1325487
milestone53.0a1
Bug 1325487 - Improve SVGContentUtils::ComputeNormalizedHypotenuse and use it more r=dholbert
dom/svg/SVGContentUtils.cpp
layout/svg/nsCSSClipPathInstance.cpp
--- a/dom/svg/SVGContentUtils.cpp
+++ b/dom/svg/SVGContentUtils.cpp
@@ -16,16 +16,17 @@
 #include "mozilla/dom/SVGSVGElement.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/SVGContextPaint.h"
 #include "nsComputedDOMStyle.h"
 #include "nsFontMetrics.h"
 #include "nsIFrame.h"
 #include "nsIScriptError.h"
 #include "nsLayoutUtils.h"
+#include "nsMathUtils.h"
 #include "SVGAnimationElement.h"
 #include "SVGAnimatedPreserveAspectRatio.h"
 #include "nsContentUtils.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Types.h"
 #include "mozilla/FloatingPoint.h"
 #include "nsStyleContext.h"
 #include "nsSVGPathDataParser.h"
@@ -504,17 +505,17 @@ SVGContentUtils::RectilinearGetStrokeBou
   }
 
   aBounds->Inflate(dx, dy);
 }
 
 double
 SVGContentUtils::ComputeNormalizedHypotenuse(double aWidth, double aHeight)
 {
-  return sqrt((aWidth*aWidth + aHeight*aHeight)/2);
+  return NS_hypot(aWidth, aHeight) / M_SQRT2;
 }
 
 float
 SVGContentUtils::AngleBisect(float a1, float a2)
 {
   float delta = fmod(a2 - a1, static_cast<float>(2*M_PI));
   if (delta < 0) {
     delta += static_cast<float>(2*M_PI);
--- a/layout/svg/nsCSSClipPathInstance.cpp
+++ b/layout/svg/nsCSSClipPathInstance.cpp
@@ -8,17 +8,16 @@
 
 #include "gfx2DGlue.h"
 #include "gfxPlatform.h"
 #include "mozilla/dom/SVGSVGElement.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/PathHelpers.h"
 #include "nsCSSRendering.h"
 #include "nsIFrame.h"
-#include "nsMathUtils.h"
 #include "nsRenderingContext.h"
 #include "nsRuleNode.h"
 #include "nsSVGElement.h"
 #include "nsSVGUtils.h"
 #include "nsSVGViewBox.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
@@ -149,18 +148,19 @@ nsCSSClipPathInstance::CreateClipPathCir
     if (styleShapeRadius == StyleShapeRadius::FarthestSide) {
       r = horizontal > vertical ? horizontal : vertical;
     } else {
       r = horizontal < vertical ? horizontal : vertical;
     }
   } else {
     // We resolve percent <shape-radius> value for circle() as defined here:
     // https://drafts.csswg.org/css-shapes/#funcdef-circle
-    const double sqrt2 = std::sqrt(2.0);
-    double referenceLength = NS_hypot(aRefBox.width, aRefBox.height) / sqrt2;
+    double referenceLength =
+      SVGContentUtils::ComputeNormalizedHypotenuse(aRefBox.width,
+                                                   aRefBox.height);
     r = nsRuleNode::ComputeCoordPercentCalc(coords[0],
                                             NSToCoordRound(referenceLength));
   }
 
   nscoord appUnitsPerDevPixel =
     mTargetFrame->PresContext()->AppUnitsPerDevPixel();
   builder->Arc(center / appUnitsPerDevPixel, r / appUnitsPerDevPixel,
                0, Float(2 * M_PI));