LibreOffice Module android (master) 1
PointUtils.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 android.graphics.Point;
9import android.graphics.PointF;
10
11import org.json.JSONException;
12import org.json.JSONObject;
13
14public final class PointUtils {
15 public static PointF add(PointF one, PointF two) {
16 return new PointF(one.x + two.x, one.y + two.y);
17 }
18
19 public static PointF subtract(PointF one, PointF two) {
20 return new PointF(one.x - two.x, one.y - two.y);
21 }
22
23 public static PointF scale(PointF point, float factor) {
24 return new PointF(point.x * factor, point.y * factor);
25 }
26
27 public static Point round(PointF point) {
28 return new Point(Math.round(point.x), Math.round(point.y));
29 }
30
31 /* Computes the magnitude of the given vector. */
32 public static float distance(PointF point) {
33 return (float)Math.sqrt(point.x * point.x + point.y * point.y);
34 }
35
37 public static float distance(PointF one, PointF two) {
38 return PointF.length(one.x - two.x, one.y - two.y);
39 }
40
41 public static JSONObject toJSON(PointF point) throws JSONException {
42 // Ensure we put ints, not longs, because Gecko message handlers call getInt().
43 int x = Math.round(point.x);
44 int y = Math.round(point.y);
45 JSONObject json = new JSONObject();
46 json.put("x", x);
47 json.put("y", y);
48 return json;
49 }
50}
51
static float distance(PointF one, PointF two)
Computes the scalar distance between two points.
Definition: PointUtils.java:37
static Point round(PointF point)
Definition: PointUtils.java:27
static JSONObject toJSON(PointF point)
Definition: PointUtils.java:41
static float distance(PointF point)
Definition: PointUtils.java:32
static PointF subtract(PointF one, PointF two)
Definition: PointUtils.java:19
static PointF add(PointF one, PointF two)
Definition: PointUtils.java:15
static PointF scale(PointF point, float factor)
Definition: PointUtils.java:23
float y
float x
def point()
sal_Int32 two
sal_Int32 one