blob: 65f16636794ce0edf425e144a67118c7f74c88dd [file] [log] [blame]
Chris Craike0bb87d2014-04-22 17:55:41 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef MATHUTILS_H
17#define MATHUTILS_H
18
19namespace android {
20namespace uirenderer {
21
22class MathUtils {
23private:
24 static const float gNonZeroEpsilon = 0.001f;
25public:
26 /**
27 * Check for floats that are close enough to zero.
28 */
29 inline static bool isZero(float value) {
30 return (value >= -gNonZeroEpsilon) && (value <= gNonZeroEpsilon);
31 }
Chris Craikcc39e162014-04-25 18:34:11 -070032
33 inline static bool isPositive(float value) {
34 return value >= gNonZeroEpsilon;
35 }
John Reck315c3292014-05-09 19:21:04 -070036
Chris Craikdeeda3d2014-05-05 19:09:33 -070037 inline static bool areEqual(float valueA, float valueB) {
38 return isZero(valueA - valueB);
39 }
40
Chris Craik05f3d6e2014-06-02 16:27:04 -070041 inline static int max(int a, int b) {
42 return a > b ? a : b;
43 }
44
John Reck315c3292014-05-09 19:21:04 -070045 inline static int min(int a, int b) {
46 return a < b ? a : b;
47 }
48
49 inline static float lerp(float v1, float v2, float t) {
50 return v1 + ((v2 - v1) * t);
51 }
Chris Craike0bb87d2014-04-22 17:55:41 -070052}; // class MathUtils
53
54} /* namespace uirenderer */
55} /* namespace android */
56
Chris Craike4aa95e2014-05-08 13:57:05 -070057#endif /* MATHUTILS_H */