1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/gfx/FloatSize.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko.gfx; 1.10 + 1.11 +import org.mozilla.gecko.util.FloatUtils; 1.12 + 1.13 +import org.json.JSONException; 1.14 +import org.json.JSONObject; 1.15 + 1.16 +public class FloatSize { 1.17 + public final float width, height; 1.18 + 1.19 + public FloatSize(FloatSize size) { width = size.width; height = size.height; } 1.20 + public FloatSize(IntSize size) { width = size.width; height = size.height; } 1.21 + public FloatSize(float aWidth, float aHeight) { width = aWidth; height = aHeight; } 1.22 + 1.23 + public FloatSize(JSONObject json) { 1.24 + try { 1.25 + width = (float)json.getDouble("width"); 1.26 + height = (float)json.getDouble("height"); 1.27 + } catch (JSONException e) { 1.28 + throw new RuntimeException(e); 1.29 + } 1.30 + } 1.31 + 1.32 + @Override 1.33 + public String toString() { return "(" + width + "," + height + ")"; } 1.34 + 1.35 + public boolean isPositive() { 1.36 + return (width > 0 && height > 0); 1.37 + } 1.38 + 1.39 + public boolean fuzzyEquals(FloatSize size) { 1.40 + return (FloatUtils.fuzzyEquals(size.width, width) && 1.41 + FloatUtils.fuzzyEquals(size.height, height)); 1.42 + } 1.43 + 1.44 + public FloatSize scale(float factor) { 1.45 + return new FloatSize(width * factor, height * factor); 1.46 + } 1.47 + 1.48 + /* 1.49 + * Returns the size that represents a linear transition between this size and `to` at time `t`, 1.50 + * which is on the scale [0, 1). 1.51 + */ 1.52 + public FloatSize interpolate(FloatSize to, float t) { 1.53 + return new FloatSize(FloatUtils.interpolate(width, to.width, t), 1.54 + FloatUtils.interpolate(height, to.height, t)); 1.55 + } 1.56 +} 1.57 +