Bug 630052, part a: Add NS_finite API to nsMathUtils; r=bz
authorMs2ger <ms2ger@gmail.com>
Sat, 02 Apr 2011 14:18:40 -0400
changeset 64654 8e8e6f2f737d05f45be52bff6d36171a96b927af
parent 64653 109dde7bb3f936fd7fea3510b19452f2eb5c621c
child 64655 2676052e13a8236bff374b3c8d35e8c65b7b746f
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs630052
milestone2.2a1pre
Bug 630052, part a: Add NS_finite API to nsMathUtils; r=bz
content/canvas/src/nsCanvasRenderingContext2D.cpp
xpcom/ds/nsMathUtils.h
--- a/content/canvas/src/nsCanvasRenderingContext2D.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp
@@ -39,36 +39,30 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifdef MOZ_IPC
 #  include "base/basictypes.h"
 #endif
 
 #include "nsIDOMXULElement.h"
 
-#ifdef _MSC_VER
-#define _USE_MATH_DEFINES
-#endif
-#include <math.h>
-#if defined(XP_WIN) || defined(XP_OS2)
-#include <float.h>
-#endif
-
 #include "prmem.h"
 #include "prenv.h"
 
 #include "nsIServiceManager.h"
+#include "nsMathUtils.h"
 
 #include "nsContentUtils.h"
 
 #include "nsIDOMDocument.h"
 #include "nsIDocument.h"
 #include "nsIDOMCanvasRenderingContext2D.h"
 #include "nsICanvasRenderingContextInternal.h"
 #include "nsHTMLCanvasElement.h"
+#include "nsSVGEffects.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsIVariant.h"
 
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIFrame.h"
 #include "nsDOMError.h"
 #include "nsIScriptError.h"
@@ -128,48 +122,22 @@
 #  include "mozilla/ipc/DocumentRendererParent.h"
 
 // windows.h (included by chromium code) defines this, in its infinite wisdom
 #  undef DrawText
 
 using namespace mozilla::ipc;
 #endif
 
-#ifdef MOZ_SVG
-#include "nsSVGEffects.h"
-#endif
-
 using namespace mozilla;
 using namespace mozilla::layers;
 using namespace mozilla::dom;
 
-#ifndef M_PI
-#define M_PI		3.14159265358979323846
-#define M_PI_2		1.57079632679489661923
-#endif
-
 /* Float validation stuff */
-
-static inline bool
-DoubleIsFinite(double d)
-{
-#ifdef WIN32
-    // NOTE: '!!' casts an int to bool without spamming MSVC warning C4800.
-    return !!_finite(d);
-#else
-    return finite(d);
-#endif
-}
-
-#define VALIDATE(_f)  if (!DoubleIsFinite(_f)) return PR_FALSE
-
-/* These must take doubles as args, because JSDOUBLE_IS_FINITE expects
- * to take the address of its argument; we can't cast/convert in the
- * macro.
- */
+#define VALIDATE(_f)  if (!NS_finite(_f)) return PR_FALSE
 
 static PRBool FloatValidate (double f1) {
     VALIDATE(f1);
     return PR_TRUE;
 }
 
 static PRBool FloatValidate (double f1, double f2) {
     VALIDATE(f1); VALIDATE(f2);
--- a/xpcom/ds/nsMathUtils.h
+++ b/xpcom/ds/nsMathUtils.h
@@ -159,9 +159,19 @@ inline NS_HIDDEN_(double) NS_hypot(doubl
     return __builtin_hypot(x, y);
 #elif defined _WIN32
     return _hypot(x, y);
 #else
     return hypot(x, y);
 #endif
 }
 
+inline NS_HIDDEN_(bool) NS_finite(double d)
+{
+#ifdef WIN32
+    // NOTE: '!!' casts an int to bool without spamming MSVC warning C4800.
+    return !!_finite(d);
+#else
+    return finite(d);
 #endif
+}
+
+#endif