Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3533)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/util/MathUtils.java

Issue 295283003: Adding support for long values in MathUtils.clamp() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/util/MathUtils.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/util/MathUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/util/MathUtils.java
index 67d8e9ae18afeef54a30753d0d83685e4ddc431c..5ff9b32d23734db5a7ba76ebe66bbf4965bf632b 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/util/MathUtils.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/util/MathUtils.java
@@ -39,6 +39,24 @@ public class MathUtils {
* @param b Second boundary range value.
* @return The passed in value if it is within the range, otherwise the closest boundary value.
*/
+ public static long clamp(long value, long a, long b) {
+ long min = (a > b) ? b : a;
+ long max = (a > b) ? a : b;
+ if (value < min) value = min;
+ else if (value > max) value = max;
+ return value;
+ }
+
+ /**
+ * Returns the passed in value if it resides within the specified range (inclusive). If not,
+ * it will return the closest boundary from the range. The ordering of the boundary values does
+ * not matter.
+ *
+ * @param value The value to be compared against the range.
+ * @param a First boundary range value.
+ * @param b Second boundary range value.
+ * @return The passed in value if it is within the range, otherwise the closest boundary value.
+ */
public static float clamp(float value, float a, float b) {
float min = (a > b) ? b : a;
float max = (a > b) ? a : b;
@@ -46,4 +64,4 @@ public class MathUtils {
else if (value > max) value = max;
return value;
}
-}
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698