Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: include/core/SkScalar.h

Issue 1783583003: Add SkScalarTruncToScalar and speed up SkScalarFraction. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include/private/SkFloatingPoint.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkScalar_DEFINED 8 #ifndef SkScalar_DEFINED
9 #define SkScalar_DEFINED 9 #define SkScalar_DEFINED
10 10
(...skipping 20 matching lines...) Expand all
31 #define SK_ScalarInfinity SK_FloatInfinity 31 #define SK_ScalarInfinity SK_FloatInfinity
32 #define SK_ScalarNegativeInfinity SK_FloatNegativeInfinity 32 #define SK_ScalarNegativeInfinity SK_FloatNegativeInfinity
33 #define SK_ScalarNaN SK_FloatNaN 33 #define SK_ScalarNaN SK_FloatNaN
34 34
35 #define SkFixedToScalar(x) SkFixedToFloat(x) 35 #define SkFixedToScalar(x) SkFixedToFloat(x)
36 #define SkScalarToFixed(x) SkFloatToFixed(x) 36 #define SkScalarToFixed(x) SkFloatToFixed(x)
37 37
38 #define SkScalarFloorToScalar(x) sk_float_floor(x) 38 #define SkScalarFloorToScalar(x) sk_float_floor(x)
39 #define SkScalarCeilToScalar(x) sk_float_ceil(x) 39 #define SkScalarCeilToScalar(x) sk_float_ceil(x)
40 #define SkScalarRoundToScalar(x) sk_float_floor((x) + 0.5f) 40 #define SkScalarRoundToScalar(x) sk_float_floor((x) + 0.5f)
41 #define SkScalarTruncToScalar(x) sk_float_trunc(x)
41 42
42 #define SkScalarFloorToInt(x) sk_float_floor2int(x) 43 #define SkScalarFloorToInt(x) sk_float_floor2int(x)
43 #define SkScalarCeilToInt(x) sk_float_ceil2int(x) 44 #define SkScalarCeilToInt(x) sk_float_ceil2int(x)
44 #define SkScalarRoundToInt(x) sk_float_round2int(x) 45 #define SkScalarRoundToInt(x) sk_float_round2int(x)
45 46
46 #define SkScalarAbs(x) sk_float_abs(x) 47 #define SkScalarAbs(x) sk_float_abs(x)
47 #define SkScalarCopySign(x, y) sk_float_copysign(x, y) 48 #define SkScalarCopySign(x, y) sk_float_copysign(x, y)
48 #define SkScalarMod(x, y) sk_float_mod(x,y) 49 #define SkScalarMod(x, y) sk_float_mod(x,y)
49 #define SkScalarFraction(x) sk_float_mod(x, 1.0f)
50 #define SkScalarSqrt(x) sk_float_sqrt(x) 50 #define SkScalarSqrt(x) sk_float_sqrt(x)
51 #define SkScalarPow(b, e) sk_float_pow(b, e) 51 #define SkScalarPow(b, e) sk_float_pow(b, e)
52 52
53 #define SkScalarSin(radians) (float)sk_float_sin(radians) 53 #define SkScalarSin(radians) (float)sk_float_sin(radians)
54 #define SkScalarCos(radians) (float)sk_float_cos(radians) 54 #define SkScalarCos(radians) (float)sk_float_cos(radians)
55 #define SkScalarTan(radians) (float)sk_float_tan(radians) 55 #define SkScalarTan(radians) (float)sk_float_tan(radians)
56 #define SkScalarASin(val) (float)sk_float_asin(val) 56 #define SkScalarASin(val) (float)sk_float_asin(val)
57 #define SkScalarACos(val) (float)sk_float_acos(val) 57 #define SkScalarACos(val) (float)sk_float_acos(val)
58 #define SkScalarATan2(y, x) (float)sk_float_atan2(y,x) 58 #define SkScalarATan2(y, x) (float)sk_float_atan2(y,x)
59 #define SkScalarExp(x) (float)sk_float_exp(x) 59 #define SkScalarExp(x) (float)sk_float_exp(x)
(...skipping 14 matching lines...) Expand all
74 #define SK_ScalarInfinity SK_DoubleInfinity 74 #define SK_ScalarInfinity SK_DoubleInfinity
75 #define SK_ScalarNegativeInfinity SK_DoubleNegativeInfinity 75 #define SK_ScalarNegativeInfinity SK_DoubleNegativeInfinity
76 #define SK_ScalarNaN SK_DoubleNaN 76 #define SK_ScalarNaN SK_DoubleNaN
77 77
78 #define SkFixedToScalar(x) SkFixedToDouble(x) 78 #define SkFixedToScalar(x) SkFixedToDouble(x)
79 #define SkScalarToFixed(x) SkDoubleToFixed(x) 79 #define SkScalarToFixed(x) SkDoubleToFixed(x)
80 80
81 #define SkScalarFloorToScalar(x) floor(x) 81 #define SkScalarFloorToScalar(x) floor(x)
82 #define SkScalarCeilToScalar(x) ceil(x) 82 #define SkScalarCeilToScalar(x) ceil(x)
83 #define SkScalarRoundToScalar(x) floor((x) + 0.5) 83 #define SkScalarRoundToScalar(x) floor((x) + 0.5)
84 #define SkScalarTruncToScalar(x) trunc(x)
84 85
85 #define SkScalarFloorToInt(x) (int)floor(x) 86 #define SkScalarFloorToInt(x) (int)floor(x)
86 #define SkScalarCeilToInt(x) (int)ceil(x) 87 #define SkScalarCeilToInt(x) (int)ceil(x)
87 #define SkScalarRoundToInt(x) (int)floor((x) + 0.5) 88 #define SkScalarRoundToInt(x) (int)floor((x) + 0.5)
88 89
89 #define SkScalarAbs(x) abs(x) 90 #define SkScalarAbs(x) abs(x)
90 #define SkScalarCopySign(x, y) copysign(x, y) 91 #define SkScalarCopySign(x, y) copysign(x, y)
91 #define SkScalarMod(x, y) fmod(x,y) 92 #define SkScalarMod(x, y) fmod(x,y)
92 #define SkScalarFraction(x) fmod(x, 1.0)
93 #define SkScalarSqrt(x) sqrt(x) 93 #define SkScalarSqrt(x) sqrt(x)
94 #define SkScalarPow(b, e) pow(b, e) 94 #define SkScalarPow(b, e) pow(b, e)
95 95
96 #define SkScalarSin(radians) sin(radians) 96 #define SkScalarSin(radians) sin(radians)
97 #define SkScalarCos(radians) cos(radians) 97 #define SkScalarCos(radians) cos(radians)
98 #define SkScalarTan(radians) tan(radians) 98 #define SkScalarTan(radians) tan(radians)
99 #define SkScalarASin(val) asin(val) 99 #define SkScalarASin(val) asin(val)
100 #define SkScalarACos(val) acos(val) 100 #define SkScalarACos(val) acos(val)
101 #define SkScalarATan2(y, x) atan2(y,x) 101 #define SkScalarATan2(y, x) atan2(y,x)
102 #define SkScalarExp(x) exp(x) 102 #define SkScalarExp(x) exp(x)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 * SkASSERT(0 == ix); // <--- fails 161 * SkASSERT(0 == ix); // <--- fails
162 * ix = SkDScalarRoundToInt(x); 162 * ix = SkDScalarRoundToInt(x);
163 * SkASSERT(0 == ix); // <--- succeeds 163 * SkASSERT(0 == ix); // <--- succeeds
164 */ 164 */
165 static inline int SkDScalarRoundToInt(SkScalar x) { 165 static inline int SkDScalarRoundToInt(SkScalar x) {
166 double xx = x; 166 double xx = x;
167 xx += 0.5; 167 xx += 0.5;
168 return (int)floor(xx); 168 return (int)floor(xx);
169 } 169 }
170 170
171 /** Returns the fractional part of the scalar. */
172 static inline SkScalar SkScalarFraction(SkScalar x) {
173 return x - SkScalarTruncToScalar(x);
174 }
175
171 static inline SkScalar SkScalarClampMax(SkScalar x, SkScalar max) { 176 static inline SkScalar SkScalarClampMax(SkScalar x, SkScalar max) {
172 x = SkTMin(x, max); 177 x = SkTMin(x, max);
173 x = SkTMax<SkScalar>(x, 0); 178 x = SkTMax<SkScalar>(x, 0);
174 return x; 179 return x;
175 } 180 }
176 181
177 static inline SkScalar SkScalarPin(SkScalar x, SkScalar min, SkScalar max) { 182 static inline SkScalar SkScalarPin(SkScalar x, SkScalar min, SkScalar max) {
178 return SkTPin(x, min, max); 183 return SkTPin(x, min, max);
179 } 184 }
180 185
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 SkASSERT(n >= 0); 265 SkASSERT(n >= 0);
261 for (int i = 0; i < n; ++i) { 266 for (int i = 0; i < n; ++i) {
262 if (a[i] != b[i]) { 267 if (a[i] != b[i]) {
263 return false; 268 return false;
264 } 269 }
265 } 270 }
266 return true; 271 return true;
267 } 272 }
268 273
269 #endif 274 #endif
OLDNEW
« no previous file with comments | « no previous file | include/private/SkFloatingPoint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698