mobile/android/base/gfx/FloatSize.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial