summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2019-08-15 17:34:04 +0200
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2019-08-15 20:34:29 +0300
commit8e1bd18eae73ffbe14aa9297a039e2431d40bd36 (patch)
tree50749fe9e5efddfd0852d6dd6ac828f62d00a368 /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java
parent074dba57a2405653191869fccddf19f304b03cf8 (diff)
downloadqtlocation-mapboxgl-8e1bd18eae73ffbe14aa9297a039e2431d40bd36.tar.gz
[android] execute quickzoom scale change based on the Y axis delta change
Using finger's Y axis position allows for a linear zoom additions/deductions during the quick-zoom changes. This is in contrast to the previously used scale factor, which is based on the current span (distance from the origin) to previous span ratio and increases the closer the finger is to the origin of a gesture because the values are smaller. The scale ratio based changes are also reliant on series of motion events' values and because the Android framework can skip some events, going back and forth during a quick-zoom might not have resulted in the same transformation. This was reproduced by the round-tripping test introduced in this commit.
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java15
1 files changed, 15 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
index 0c90e4b244..7ec3262c57 100644
--- 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
@@ -46,4 +46,19 @@ public class MathUtils {
return secondMod + min;
}
+
+ /**
+ * Scale a value from an arbitrary range to a normalized range.
+ *
+ * @param x The value to be normalized.
+ * @param dataLow lowest expected value from a data set
+ * @param dataHigh highest expected value from a data set
+ * @param normalizedLow normalized lowest value
+ * @param normalizedHigh normalized highest value
+ * @return The result of the normalization.
+ */
+ public static double normalize(double x, double dataLow, double dataHigh,
+ double normalizedLow, double normalizedHigh) {
+ return ((x - dataLow) / (dataHigh - dataLow)) * (normalizedHigh - normalizedLow) + normalizedLow;
+ }
}