@@ -1584,8 +1584,8 @@ struct JavascriptEngine::RootObject : public DynamicObject | |||||
static var Math_range (Args a) { return isInt (a, 0) ? var (jlimit (getInt (a, 1), getInt (a, 2), getInt (a, 0))) : var (jlimit (getDouble (a, 1), getDouble (a, 2), getDouble (a, 0))); } | static var Math_range (Args a) { return isInt (a, 0) ? var (jlimit (getInt (a, 1), getInt (a, 2), getInt (a, 0))) : var (jlimit (getDouble (a, 1), getDouble (a, 2), getDouble (a, 0))); } | ||||
static var Math_min (Args a) { return (isInt (a, 0) && isInt (a, 1)) ? var (jmin (getInt (a, 0), getInt (a, 1))) : var (jmin (getDouble (a, 0), getDouble (a, 1))); } | static var Math_min (Args a) { return (isInt (a, 0) && isInt (a, 1)) ? var (jmin (getInt (a, 0), getInt (a, 1))) : var (jmin (getDouble (a, 0), getDouble (a, 1))); } | ||||
static var Math_max (Args a) { return (isInt (a, 0) && isInt (a, 1)) ? var (jmax (getInt (a, 0), getInt (a, 1))) : var (jmax (getDouble (a, 0), getDouble (a, 1))); } | static var Math_max (Args a) { return (isInt (a, 0) && isInt (a, 1)) ? var (jmax (getInt (a, 0), getInt (a, 1))) : var (jmax (getDouble (a, 0), getDouble (a, 1))); } | ||||
static var Math_toDegrees (Args a) { return (180.0 / double_Pi) * getDouble (a, 0); } | |||||
static var Math_toRadians (Args a) { return (double_Pi / 180.0) * getDouble (a, 0); } | |||||
static var Math_toDegrees (Args a) { return radiansToDegrees (getDouble (a, 0)); } | |||||
static var Math_toRadians (Args a) { return degreesToRadians (getDouble (a, 0)); } | |||||
static var Math_sin (Args a) { return sin (getDouble (a, 0)); } | static var Math_sin (Args a) { return sin (getDouble (a, 0)); } | ||||
static var Math_asin (Args a) { return asin (getDouble (a, 0)); } | static var Math_asin (Args a) { return asin (getDouble (a, 0)); } | ||||
static var Math_cos (Args a) { return cos (getDouble (a, 0)); } | static var Math_cos (Args a) { return cos (getDouble (a, 0)); } | ||||
@@ -354,6 +354,15 @@ const double double_Pi = 3.1415926535897932384626433832795; | |||||
const float float_Pi = 3.14159265358979323846f; | const float float_Pi = 3.14159265358979323846f; | ||||
/** Converts an angle in degrees to radians. */ | |||||
template <typename FloatType> | |||||
inline FloatType degreesToRadians (FloatType degrees) noexcept { return degrees * static_cast<FloatType> (double_Pi / 180.0); } | |||||
/** Converts an angle in radians to degrees. */ | |||||
template <typename FloatType> | |||||
inline FloatType radiansToDegrees (FloatType radians) noexcept { return radians * static_cast<FloatType> (180.0 / double_Pi); } | |||||
//============================================================================== | //============================================================================== | ||||
/** The isfinite() method seems to vary between platforms, so this is a | /** The isfinite() method seems to vary between platforms, so this is a | ||||
platform-independent function for it. | platform-independent function for it. | ||||
@@ -477,16 +486,14 @@ inline int roundFloatToInt (const float value) noexcept | |||||
} | } | ||||
//============================================================================== | //============================================================================== | ||||
/** Returns true if the specified integer is a power-of-two. | |||||
*/ | |||||
/** Returns true if the specified integer is a power-of-two. */ | |||||
template <typename IntegerType> | template <typename IntegerType> | ||||
bool isPowerOfTwo (IntegerType value) | bool isPowerOfTwo (IntegerType value) | ||||
{ | { | ||||
return (value & (value - 1)) == 0; | return (value & (value - 1)) == 0; | ||||
} | } | ||||
/** Returns the smallest power-of-two which is equal to or greater than the given integer. | |||||
*/ | |||||
/** Returns the smallest power-of-two which is equal to or greater than the given integer. */ | |||||
inline int nextPowerOfTwo (int n) noexcept | inline int nextPowerOfTwo (int n) noexcept | ||||
{ | { | ||||
--n; | --n; | ||||
@@ -533,6 +540,7 @@ NumericType square (NumericType n) noexcept | |||||
return n * n; | return n * n; | ||||
} | } | ||||
//============================================================================== | //============================================================================== | ||||
#if JUCE_INTEL || defined (DOXYGEN) | #if JUCE_INTEL || defined (DOXYGEN) | ||||
/** This macro can be applied to a float variable to check whether it contains a denormalised | /** This macro can be applied to a float variable to check whether it contains a denormalised | ||||
@@ -272,7 +272,7 @@ public: | |||||
if (parseNextNumber (d, num, false)) | if (parseNextNumber (d, num, false)) | ||||
{ | { | ||||
const float angle = num.getFloatValue() * (180.0f / float_Pi); | |||||
const float angle = degreesToRadians (num.getFloatValue()); | |||||
if (parseNextNumber (d, num, false)) | if (parseNextNumber (d, num, false)) | ||||
{ | { | ||||
@@ -1221,15 +1221,15 @@ private: | |||||
} | } | ||||
else if (t.startsWithIgnoreCase ("rotate")) | else if (t.startsWithIgnoreCase ("rotate")) | ||||
{ | { | ||||
trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi), numbers[1], numbers[2]); | |||||
trans = AffineTransform::rotation (degreesToRadians (numbers[0]), numbers[1], numbers[2]); | |||||
} | } | ||||
else if (t.startsWithIgnoreCase ("skewX")) | else if (t.startsWithIgnoreCase ("skewX")) | ||||
{ | { | ||||
trans = AffineTransform::shear (std::tan (numbers[0] * (float_Pi / 180.0f)), 0.0f); | |||||
trans = AffineTransform::shear (std::tan (degreesToRadians (numbers[0])), 0.0f); | |||||
} | } | ||||
else if (t.startsWithIgnoreCase ("skewY")) | else if (t.startsWithIgnoreCase ("skewY")) | ||||
{ | { | ||||
trans = AffineTransform::shear (0.0f, std::tan (numbers[0] * (float_Pi / 180.0f))); | |||||
trans = AffineTransform::shear (0.0f, std::tan (degreesToRadians (numbers[0]))); | |||||
} | } | ||||
result = trans.followedBy (result); | result = trans.followedBy (result); | ||||