OLD | NEW |
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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 195 } |
196 | 196 |
197 /** Linearly interpolate between A and B, based on t. | 197 /** Linearly interpolate between A and B, based on t. |
198 If t is 0, return A | 198 If t is 0, return A |
199 If t is 1, return B | 199 If t is 1, return B |
200 else interpolate. | 200 else interpolate. |
201 t must be [0..SK_Scalar1] | 201 t must be [0..SK_Scalar1] |
202 */ | 202 */ |
203 static inline SkScalar SkScalarInterp(SkScalar A, SkScalar B, SkScalar t) { | 203 static inline SkScalar SkScalarInterp(SkScalar A, SkScalar B, SkScalar t) { |
204 SkASSERT(t >= 0 && t <= SK_Scalar1); | 204 SkASSERT(t >= 0 && t <= SK_Scalar1); |
205 return A + SkScalarMul(B - A, t); | 205 return A + (B - A) * t; |
206 } | 206 } |
207 | 207 |
208 /** Interpolate along the function described by (keys[length], values[length]) | 208 /** Interpolate along the function described by (keys[length], values[length]) |
209 for the passed searchKey. SearchKeys outside the range keys[0]-keys[Length] | 209 for the passed searchKey. SearchKeys outside the range keys[0]-keys[Length] |
210 clamp to the min or max value. This function was inspired by a desire | 210 clamp to the min or max value. This function was inspired by a desire |
211 to change the multiplier for thickness in fakeBold; therefore it assumes | 211 to change the multiplier for thickness in fakeBold; therefore it assumes |
212 the number of pairs (length) will be small, and a linear search is used. | 212 the number of pairs (length) will be small, and a linear search is used. |
213 Repeated keys are allowed for discontinuous functions (so long as keys is | 213 Repeated keys are allowed for discontinuous functions (so long as keys is |
214 monotonically increasing), and if key is the value of a repeated scalar in | 214 monotonically increasing), and if key is the value of a repeated scalar in |
215 keys, the first one will be used. However, that may change if a binary | 215 keys, the first one will be used. However, that may change if a binary |
216 search is used. | 216 search is used. |
217 */ | 217 */ |
218 SkScalar SkScalarInterpFunc(SkScalar searchKey, const SkScalar keys[], | 218 SkScalar SkScalarInterpFunc(SkScalar searchKey, const SkScalar keys[], |
219 const SkScalar values[], int length); | 219 const SkScalar values[], int length); |
220 | 220 |
221 /* | 221 /* |
222 * Helper to compare an array of scalars. | 222 * Helper to compare an array of scalars. |
223 */ | 223 */ |
224 static inline bool SkScalarsEqual(const SkScalar a[], const SkScalar b[], int n)
{ | 224 static inline bool SkScalarsEqual(const SkScalar a[], const SkScalar b[], int n)
{ |
225 SkASSERT(n >= 0); | 225 SkASSERT(n >= 0); |
226 for (int i = 0; i < n; ++i) { | 226 for (int i = 0; i < n; ++i) { |
227 if (a[i] != b[i]) { | 227 if (a[i] != b[i]) { |
228 return false; | 228 return false; |
229 } | 229 } |
230 } | 230 } |
231 return true; | 231 return true; |
232 } | 232 } |
233 | 233 |
234 #endif | 234 #endif |
OLD | NEW |