diff options
author | Chris Craik <ccraik@google.com> | 2015-05-27 18:17:03 -0700 |
---|---|---|
committer | Chris Craik <ccraik@google.com> | 2015-05-27 18:17:55 -0700 |
commit | ff29b5a5b9b991868051f0fa065a4ac668e7fa0b (patch) | |
tree | 3b3ea1b5ebac47aeff99a2df8c74ce69caba74ca /libs/hwui/utils | |
parent | 60bf94e3bef8da0adb4f42043770cef7a608d07d (diff) | |
download | frameworks_base-ff29b5a5b9b991868051f0fa065a4ac668e7fa0b.zip frameworks_base-ff29b5a5b9b991868051f0fa065a4ac668e7fa0b.tar.gz frameworks_base-ff29b5a5b9b991868051f0fa065a4ac668e7fa0b.tar.bz2 |
Fix round cap approximation to understand scale
bug:19772120
Change-Id: I7b944faed1d1e8d5f55453802da57679217d9d9a
Diffstat (limited to 'libs/hwui/utils')
-rw-r--r-- | libs/hwui/utils/MathUtils.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libs/hwui/utils/MathUtils.h b/libs/hwui/utils/MathUtils.h index d89859b..9c3787c 100644 --- a/libs/hwui/utils/MathUtils.h +++ b/libs/hwui/utils/MathUtils.h @@ -16,6 +16,8 @@ #ifndef MATHUTILS_H #define MATHUTILS_H +#include <math.h> + namespace android { namespace uirenderer { @@ -62,6 +64,19 @@ public: return scale; } + /** + * Returns the number of points (beyond two, the start and end) needed to form a polygonal + * approximation of an arc, with a given threshold value. + */ + inline static int divisionsNeededToApproximateArc(float radius, + float angleInRads, float threshold) { + const float errConst = (-threshold / radius + 1); + const float targetCosVal = 2 * errConst * errConst - 1; + + // needed divisions are rounded up from approximation + return (int)(ceilf(angleInRads / acos(targetCosVal)/2)) * 2; + } + inline static bool areEqual(float valueA, float valueB) { return isZero(valueA - valueB); } |