Bug 714874 - Fix Java warnings about redundant casts (changes that touch PointUtils only, for aurora). r=pcwalton r=dougt a=bustage
authorChris Peterson <cpeterson@mozilla.com>
Thu, 19 Jan 2012 17:06:59 -0500
changeset 85005 e3fd154d60383e4c24498816ef2bb7748508b8d0
parent 85004 bb8d14637ea525faf62cfec98e8add6bd733b31d
child 85006 922795c904e8d22643d245c823e06329dbe41437
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspcwalton, dougt, bustage
bugs714874
milestone11.0a2
Bug 714874 - Fix Java warnings about redundant casts (changes that touch PointUtils only, for aurora). r=pcwalton r=dougt a=bustage
mobile/android/base/gfx/PointUtils.java
--- a/mobile/android/base/gfx/PointUtils.java
+++ b/mobile/android/base/gfx/PointUtils.java
@@ -32,19 +32,23 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 package org.mozilla.gecko.gfx;
 
-import org.mozilla.gecko.FloatUtils;
 import android.graphics.Point;
 import android.graphics.PointF;
+
+import org.json.JSONObject;
+import org.json.JSONException;
+import org.mozilla.gecko.FloatUtils;
+
 import java.lang.Math;
 
 public final class PointUtils {
     public static PointF add(PointF one, PointF two) {
         return new PointF(one.x + two.x, one.y + two.y);
     }
 
     public static PointF subtract(PointF one, PointF two) {
@@ -67,10 +71,20 @@ public final class PointUtils {
        float y = FloatUtils.interpolate(startPoint.y, endPoint.y, weight);
        return new PointF(x, y);
    }
 
    /* Computes the magnitude of the given vector. */
    public static float distance(PointF point) {
         return (float)Math.sqrt(point.x * point.x + point.y * point.y);
    }
+
+    public static JSONObject toJSON(PointF point) throws JSONException {
+        // Ensure we put ints, not longs, because Gecko message handlers call getInt().
+        int x = Math.round(point.x);
+        int y = Math.round(point.y);
+        JSONObject json = new JSONObject();
+        json.put("x", x);
+        json.put("y", y);
+        return json;
+    }
 }