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

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

Issue 270883002: Upstream base implementations of TabModel, TabModelSelector, and TabModelObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync 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
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
new file mode 100644
index 0000000000000000000000000000000000000000..67d8e9ae18afeef54a30753d0d83685e4ddc431c
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/util/MathUtils.java
@@ -0,0 +1,49 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.util;
+
+/**
+ * Contains various math utilities used throughout Chrome Mobile.
+ */
+public class MathUtils {
+
+ private MathUtils() {}
+
+ /**
+ * 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 int clamp(int value, int a, int b) {
+ int min = (a > b) ? b : a;
+ int 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;
+ if (value < min) value = min;
+ else if (value > max) value = max;
+ return value;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698