diff options
author | Pablo Guardiola <guardiola31337@gmail.com> | 2018-02-13 12:23:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-13 12:23:17 +0100 |
commit | b8240f725cbfdb4b5369b050c933acdd4e42b705 (patch) | |
tree | 09e475b8a66c020e6eedd13ea7e196e78626e242 /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils | |
parent | ff747a8c53805a270451cd6052d02073e45546a7 (diff) | |
download | qtlocation-mapboxgl-b8240f725cbfdb4b5369b050c933acdd4e42b705.tar.gz |
[android] Integration of the new events library (#10999) (#11183)
* [android] integration of the new events library
* JNI Bug
- current build with JNI bug
* fix #10999 comments
* Clean-up
- clean-up timbers and test code
* [android] fix sdk identifier and sdk version
* [android] merge from master (MAS 3.0)
* [android] bump events lib version to 3.0.0-beta.1 and remove never used methods from math utils class
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java new file mode 100644 index 0000000000..0c90e4b244 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java @@ -0,0 +1,49 @@ +package com.mapbox.mapboxsdk.utils; + +// TODO Remove this class if we finally include it within MAS 3.x (GeoJSON) +public class MathUtils { + + /** + * Test a value in specified range, returning minimum if it's below, and maximum if it's above + * + * @param value Value to test + * @param min Minimum value of range + * @param max Maximum value of range + * @return value if it's between min and max, min if it's below, max if it's above + */ + public static double clamp(double value, double min, double max) { + return Math.max(min, Math.min(max, value)); + } + + /** + * Test a value in specified range, returning minimum if it's below, and maximum if it's above + * + * @param value Value to test + * @param min Minimum value of range + * @param max Maximum value of range + * @return value if it's between min and max, min if it's below, max if it's above + */ + public static float clamp(float value, float min, float max) { + return Math.max(min, Math.min(max, value)); + } + + /** + * Constrains value to the given range (including min, excluding max) via modular arithmetic. + * <p> + * Same formula as used in Core GL (wrap.hpp) + * std::fmod((std::fmod((value - min), d) + d), d) + min; + * + * @param value Value to wrap + * @param min Minimum value + * @param max Maximum value + * @return Wrapped value + */ + public static double wrap(double value, double min, double max) { + double delta = max - min; + + double firstMod = (value - min) % delta; + double secondMod = (firstMod + delta) % delta; + + return secondMod + min; + } +} |