Debian Codegraph @

android/source/src/java/org/mozilla/gecko/gfx/FloatSize.java

raw
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/. */
5
6 package org.mozilla.gecko.gfx;
7
8 import org.json.JSONException;
9 import org.json.JSONObject;
10 import org.mozilla.gecko.util.FloatUtils;
11
12 public class FloatSize {
13 public final float width, height;
14
15 public FloatSize(FloatSize size) { width = size.width; height = size.height; }
16 public FloatSize(IntSize size) { width = size.width; height = size.height; }
17 public FloatSize(float aWidth, float aHeight) { width = aWidth; height = aHeight; }
18
19 public FloatSize(JSONObject json) {
20 try {
21 width = (float)json.getDouble("width");
22 height = (float)json.getDouble("height");
23 } catch (JSONException e) {
24 throw new RuntimeException(e);
25 }
26 }
27
28 @Override
29 public String toString() { return "(" + width + "," + height + ")"; }
30
31 public boolean isPositive() {
32 return (width > 0 && height > 0);
33 }
34
35 public boolean fuzzyEquals(FloatSize size) {
36 return (FloatUtils.fuzzyEquals(size.width, width) &&
37 FloatUtils.fuzzyEquals(size.height, height));
38 }
39
40 public FloatSize scale(float factor) {
41 return new FloatSize(width * factor, height * factor);
42 }
43
44 /*
45 * Returns the size that represents a linear transition between this size and `to` at time `t`,
46 * which is on the scale [0, 1).
47 */
48 public FloatSize interpolate(FloatSize to, float t) {
49 return new FloatSize(FloatUtils.interpolate(width, to.width, t),
50 FloatUtils.interpolate(height, to.height, t));
51 }
52 }
53