Update git submodules
[LibreOffice.git] / android / source / src / java / org / mozilla / gecko / util / FloatUtils.java
bloba48266c573d8d30762e4d2a853a142a922ba3f3e
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 package org.mozilla.gecko.util;
8 import android.graphics.PointF;
10 public final class FloatUtils {
11 private FloatUtils() {}
13 public static boolean fuzzyEquals(float a, float b) {
14 return (Math.abs(a - b) < 1e-6);
17 public static boolean fuzzyEquals(PointF a, PointF b) {
18 return fuzzyEquals(a.x, b.x) && fuzzyEquals(a.y, b.y);
22 * Returns the value that represents a linear transition between `from` and `to` at time `t`,
23 * which is on the scale [0, 1). Thus with t = 0.0f, this returns `from`; with t = 1.0f, this
24 * returns `to`; with t = 0.5f, this returns the value halfway from `from` to `to`.
26 public static float interpolate(float from, float to, float t) {
27 return from + (to - from) * t;
30 /**
31 * Returns 'value', clamped so that it isn't any lower than 'low', and it
32 * isn't any higher than 'high'.
34 public static float clamp(float value, float low, float high) {
35 if (high < low) {
36 throw new IllegalArgumentException(
37 "clamp called with invalid parameters (" + high + " < " + low + ")" );
39 return Math.max(low, Math.min(high, value));