From ef6537b3b75f3bbab8ae208f8a4690f690fda409 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 2 Apr 2011 14:18:40 -0400 Subject: [PATCH] Bug 630052, part a: Add NS_finite API to nsMathUtils; r=bz --- .../canvas/src/nsCanvasRenderingContext2D.cpp | 38 ++----------------- xpcom/ds/nsMathUtils.h | 10 +++++ 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index 56927aa042fa..1b30f4dbbfb0 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -44,18 +44,11 @@ #include "nsIDOMXULElement.h" -#ifdef _MSC_VER -#define _USE_MATH_DEFINES -#endif -#include -#if defined(XP_WIN) || defined(XP_OS2) -#include -#endif - #include "prmem.h" #include "prenv.h" #include "nsIServiceManager.h" +#include "nsMathUtils.h" #include "nsContentUtils.h" @@ -64,6 +57,7 @@ #include "nsIDOMCanvasRenderingContext2D.h" #include "nsICanvasRenderingContextInternal.h" #include "nsHTMLCanvasElement.h" +#include "nsSVGEffects.h" #include "nsPresContext.h" #include "nsIPresShell.h" #include "nsIVariant.h" @@ -133,38 +127,12 @@ 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); diff --git a/xpcom/ds/nsMathUtils.h b/xpcom/ds/nsMathUtils.h index 6b97ba7b07f6..87b52554d969 100644 --- a/xpcom/ds/nsMathUtils.h +++ b/xpcom/ds/nsMathUtils.h @@ -164,4 +164,14 @@ inline NS_HIDDEN_(double) NS_hypot(double x, double 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