Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | package org.mozilla.gecko.gfx; |
michael@0 | 7 | |
michael@0 | 8 | import org.mozilla.gecko.util.FloatUtils; |
michael@0 | 9 | |
michael@0 | 10 | import org.json.JSONException; |
michael@0 | 11 | import org.json.JSONObject; |
michael@0 | 12 | |
michael@0 | 13 | public class FloatSize { |
michael@0 | 14 | public final float width, height; |
michael@0 | 15 | |
michael@0 | 16 | public FloatSize(FloatSize size) { width = size.width; height = size.height; } |
michael@0 | 17 | public FloatSize(IntSize size) { width = size.width; height = size.height; } |
michael@0 | 18 | public FloatSize(float aWidth, float aHeight) { width = aWidth; height = aHeight; } |
michael@0 | 19 | |
michael@0 | 20 | public FloatSize(JSONObject json) { |
michael@0 | 21 | try { |
michael@0 | 22 | width = (float)json.getDouble("width"); |
michael@0 | 23 | height = (float)json.getDouble("height"); |
michael@0 | 24 | } catch (JSONException e) { |
michael@0 | 25 | throw new RuntimeException(e); |
michael@0 | 26 | } |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | @Override |
michael@0 | 30 | public String toString() { return "(" + width + "," + height + ")"; } |
michael@0 | 31 | |
michael@0 | 32 | public boolean isPositive() { |
michael@0 | 33 | return (width > 0 && height > 0); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | public boolean fuzzyEquals(FloatSize size) { |
michael@0 | 37 | return (FloatUtils.fuzzyEquals(size.width, width) && |
michael@0 | 38 | FloatUtils.fuzzyEquals(size.height, height)); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | public FloatSize scale(float factor) { |
michael@0 | 42 | return new FloatSize(width * factor, height * factor); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | /* |
michael@0 | 46 | * Returns the size that represents a linear transition between this size and `to` at time `t`, |
michael@0 | 47 | * which is on the scale [0, 1). |
michael@0 | 48 | */ |
michael@0 | 49 | public FloatSize interpolate(FloatSize to, float t) { |
michael@0 | 50 | return new FloatSize(FloatUtils.interpolate(width, to.width, t), |
michael@0 | 51 | FloatUtils.interpolate(height, to.height, t)); |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 |