LibreOffice Module android (master) 1
IntSize.java
Go to the documentation of this file.
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
6package org.mozilla.gecko.gfx;
7
8import org.json.JSONException;
9import org.json.JSONObject;
10
11public class IntSize {
12 public final int width, height;
13
14 public IntSize(IntSize size) { width = size.width; height = size.height; }
15 public IntSize(int inWidth, int inHeight) { width = inWidth; height = inHeight; }
16
17 public IntSize(FloatSize size) {
18 width = Math.round(size.width);
19 height = Math.round(size.height);
20 }
21
22 public IntSize(JSONObject json) {
23 try {
24 width = json.getInt("width");
25 height = json.getInt("height");
26 } catch (JSONException e) {
27 throw new RuntimeException(e);
28 }
29 }
30
31 public int getArea() {
32 return width * height;
33 }
34
35 public boolean equals(IntSize size) {
36 return ((size.width == width) && (size.height == height));
37 }
38
39 public boolean isPositive() {
40 return (width > 0 && height > 0);
41 }
42
43 @Override
44 public String toString() { return "(" + width + "," + height + ")"; }
45
46 public IntSize scale(float factor) {
47 return new IntSize(Math.round(width * factor),
48 Math.round(height * factor));
49 }
50
51 /* Returns the power of two that is greater than or equal to value */
52 public static int nextPowerOfTwo(int value) {
53 // code taken from http://acius2.blogspot.com/2007/11/calculating-next-power-of-2.html
54 if (0 == value--) {
55 return 1;
56 }
57 value = (value >> 1) | value;
58 value = (value >> 2) | value;
59 value = (value >> 4) | value;
60 value = (value >> 8) | value;
61 value = (value >> 16) | value;
62 return value + 1;
63 }
64
65 public static int nextPowerOfTwo(float value) {
66 return nextPowerOfTwo((int) value);
67 }
68
71 }
72}
73
static int nextPowerOfTwo(float value)
Definition: IntSize.java:65
IntSize(JSONObject json)
Definition: IntSize.java:22
boolean equals(IntSize size)
Definition: IntSize.java:35
IntSize(FloatSize size)
Definition: IntSize.java:17
static int nextPowerOfTwo(int value)
Definition: IntSize.java:52
IntSize scale(float factor)
Definition: IntSize.java:46
IntSize(int inWidth, int inHeight)
Definition: IntSize.java:15
Any value
size