8 #ifndef SkScalar_DEFINED
9 #define SkScalar_DEFINED
11 #include "include/private/base/SkAssert.h"
12 #include "include/private/base/SkFloatingPoint.h"
16 #define SK_Scalar1 1.0f
17 #define SK_ScalarHalf 0.5f
18 #define SK_ScalarSqrt2 SK_FloatSqrt2
19 #define SK_ScalarPI SK_FloatPI
20 #define SK_ScalarTanPIOver8 0.414213562f
21 #define SK_ScalarRoot2Over2 0.707106781f
22 #define SK_ScalarMax 3.402823466e+38f
23 #define SK_ScalarMin (-SK_ScalarMax)
24 #define SK_ScalarInfinity SK_FloatInfinity
25 #define SK_ScalarNegativeInfinity SK_FloatNegativeInfinity
26 #define SK_ScalarNaN SK_FloatNaN
28 #define SkScalarFloorToScalar(x) sk_float_floor(x)
29 #define SkScalarCeilToScalar(x) sk_float_ceil(x)
30 #define SkScalarRoundToScalar(x) sk_float_round(x)
31 #define SkScalarTruncToScalar(x) sk_float_trunc(x)
33 #define SkScalarFloorToInt(x) sk_float_floor2int(x)
34 #define SkScalarCeilToInt(x) sk_float_ceil2int(x)
35 #define SkScalarRoundToInt(x) sk_float_round2int(x)
37 #define SkScalarAbs(x) sk_float_abs(x)
38 #define SkScalarCopySign(x, y) sk_float_copysign(x, y)
39 #define SkScalarMod(x, y) sk_float_mod(x,y)
40 #define SkScalarSqrt(x) sk_float_sqrt(x)
41 #define SkScalarPow(b, e) sk_float_pow(b, e)
43 #define SkScalarSin(radians) (float)sk_float_sin(radians)
44 #define SkScalarCos(radians) (float)sk_float_cos(radians)
45 #define SkScalarTan(radians) (float)sk_float_tan(radians)
46 #define SkScalarASin(val) (float)sk_float_asin(val)
47 #define SkScalarACos(val) (float)sk_float_acos(val)
48 #define SkScalarATan2(y, x) (float)sk_float_atan2(y,x)
49 #define SkScalarExp(x) (float)sk_float_exp(x)
50 #define SkScalarLog(x) (float)sk_float_log(x)
51 #define SkScalarLog2(x) (float)sk_float_log2(x)
55 #define SkIntToScalar(x) static_cast<SkScalar>(x)
56 #define SkIntToFloat(x) static_cast<float>(x)
57 #define SkScalarTruncToInt(x) sk_float_saturate2int(x)
59 #define SkScalarToFloat(x) static_cast<float>(x)
60 #define SkFloatToScalar(x) static_cast<SkScalar>(x)
61 #define SkScalarToDouble(x) static_cast<double>(x)
62 #define SkDoubleToScalar(x) sk_double_to_float(x)
71 return sk_floats_are_finite(a, b);
75 return sk_floats_are_finite(array, count);
85 #define SkScalarInvert(x) (SK_Scalar1 / (x))
86 #define SkScalarAve(a, b) (((a) + (b)) * SK_ScalarHalf)
87 #define SkScalarHalf(a) ((a) * SK_ScalarHalf)
89 #define SkDegreesToRadians(degrees) ((degrees) * (SK_ScalarPI / 180))
90 #define SkRadiansToDegrees(radians) ((radians) * (180 / SK_ScalarPI))
103 return x < 0 ? -1 : (x > 0);
111 #define SK_ScalarNearlyZero (SK_Scalar1 / (1 << 12))
115 SkASSERT(tolerance >= 0);
121 SkASSERT(tolerance >= 0);
125 #define SK_ScalarSinCosNearlyZero (SK_Scalar1 / (1 << 16))
145 return A + (B - A) * t;
158 const SkScalar values[],
int length);
165 for (
int i = 0; i < n; ++i) {
static SkScalar SkScalarSignAsScalar(SkScalar x)
Definition: SkScalar.h:107
#define SkScalarTruncToScalar(x)
Definition: SkScalar.h:31
#define SK_ScalarSinCosNearlyZero
Definition: SkScalar.h:125
#define SkScalarFloorToScalar(x)
Definition: SkScalar.h:28
static float SkScalarSinSnapToZero(SkScalar radians)
Definition: SkScalar.h:127
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:113
static int SkScalarSignAsInt(SkScalar x)
Returns -1 || 0 || 1 depending on the sign of value: -1 if x < 0 0 if x == 0 1 if x > 0.
Definition: SkScalar.h:102
static bool SkScalarsAreFinite(SkScalar a, SkScalar b)
Definition: SkScalar.h:70
#define SkScalarSin(radians)
Definition: SkScalar.h:43
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:119
#define SK_Scalar1
Definition: SkScalar.h:16
static bool SkScalarIsFinite(SkScalar x)
Returns true if x is not NaN and not infinite.
Definition: SkScalar.h:68
#define SK_ScalarNearlyZero
Definition: SkScalar.h:111
static bool SkScalarIsNaN(SkScalar x)
Definition: SkScalar.h:64
#define SkScalarCos(radians)
Definition: SkScalar.h:44
static bool SkScalarIsInt(SkScalar x)
Definition: SkScalar.h:92
static SkScalar SkScalarInterp(SkScalar A, SkScalar B, SkScalar t)
Linearly interpolate between A and B, based on t.
Definition: SkScalar.h:143
SkScalar SkScalarInterpFunc(SkScalar searchKey, const SkScalar keys[], const SkScalar values[], int length)
Interpolate along the function described by (keys[length], values[length]) for the passed searchKey.
float SkScalar
Definition: SkScalar.h:14
static SkScalar SkScalarFraction(SkScalar x)
Returns the fractional part of the scalar.
Definition: SkScalar.h:79
static SkScalar SkScalarSquare(SkScalar x)
Definition: SkScalar.h:83
#define SkScalarAbs(x)
Definition: SkScalar.h:37
static float SkScalarCosSnapToZero(SkScalar radians)
Definition: SkScalar.h:132
static bool SkScalarsEqual(const SkScalar a[], const SkScalar b[], int n)
Definition: SkScalar.h:163