Hello Miguel,

This is the halfway point - 9 classes down, 9 to go.

I would like for you to review the attached patch which converts the Bounds
object to a JavaScript overlay.  I changed the behavior of the 'extends()'
method to just mirror the JavaScript method instead of cloning the bounds
object.  I also added a new factory method which takes 4 int arguments.

Since I made those changes and there were no references to this object I
could test with, I added a unit test.

A      maps/maps/test/com/google/gwt/maps/client/geom/BoundsTest.java
M      maps/maps/src/com/google/gwt/maps/client/geom/Bounds.java
D      maps/maps/src/com/google/gwt/maps/client/impl/BoundsImpl.java
M      maps/maps/test/com/google/gwt/maps/MapsTestSuite.java

-Eric.
-- 
Eric Z. Ayers - GWT Team - Atlanta, GA USA
http://code.google.com/webtoolkit/

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

A      maps/maps/test/com/google/gwt/maps/client/geom/BoundsTest.java
M      maps/maps/src/com/google/gwt/maps/client/geom/Bounds.java
D      maps/maps/src/com/google/gwt/maps/client/impl/BoundsImpl.java
M      maps/maps/test/com/google/gwt/maps/MapsTestSuite.java

Index: maps/maps/test/com/google/gwt/maps/client/geom/BoundsTest.java
===================================================================
--- maps/maps/test/com/google/gwt/maps/client/geom/BoundsTest.java	(revision 0)
+++ maps/maps/test/com/google/gwt/maps/client/geom/BoundsTest.java	(revision 0)
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2008 Google Inc.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.maps.client.geom;
+
+import com.google.gwt.core.client.JsArray;
+import com.google.gwt.junit.client.GWTTestCase;
+
+/**
+ * Tests the Bounds class.
+ */
+public class BoundsTest extends GWTTestCase {
+
+  @Override
+  public String getModuleName() {
+    return "com.google.gwt.maps.GoogleMapsTest";
+  }
+
+  public void testContainsBounds() {
+    Bounds b1 = Bounds.newInstance(0,0,10,10);
+    Bounds b2 = Bounds.newInstance(2,2, 8, 8);
+    assertTrue("b1 contains b2", b1.containsBounds(b2));
+    assertFalse("b2 contains b1", b2.containsBounds(b1));
+  }
+  
+  public void testContainsPoint() {
+    Bounds b = Bounds.newInstance(0,0,10,10);
+    assertTrue("Contains 5,5",  b.containsPoint(Point.newInstance(5,5)));
+    assertFalse("Contains 15,5", b.containsPoint(Point.newInstance(15,5)));
+  }
+  
+  @SuppressWarnings("unchecked")
+  public void testCorners() {
+    JsArray<Point> points = (JsArray<Point>) Point.createArray();
+    points.set(0, Point.newInstance(10, 20));
+    points.set(1, Point.newInstance(30, 40));
+    Bounds b = Bounds.newInstance(points);
+    assertEquals("upper left X", 10, b.getUpperLeft().getX());
+    assertEquals("upper left Y", 20, b.getUpperLeft().getY());
+    assertEquals("lower right X", 30, b.getLowerRight().getX());
+    assertEquals("lower right Y", 40, b.getLowerRight().getY());
+  }
+  
+  @SuppressWarnings("unchecked")
+  public void testExtend() {
+    JsArray<Point> points = (JsArray<Point>) Point.createArray();
+    points.set(0, Point.newInstance(0, 0));
+    points.set(1, Point.newInstance(45, 45));
+    Bounds b = Bounds.newInstance(points);
+    b.extend(Point.newInstance(45,50));
+  
+    assertEquals("min x out of bounds", 0, b.getMinX());
+    assertEquals("min y out of bounds", 0, b.getMinY());
+    assertEquals("max x out of bounds", 45, b.getMaxX());
+    assertEquals("max y out of bounds", 50, b.getMaxY());
+  }
+  
+  @SuppressWarnings("unchecked")
+  public void testMid() {
+    JsArray<Point> points = (JsArray<Point>) Point.createArray();
+    points.set(0, Point.newInstance(0, 0));
+    points.set(1, Point.newInstance(90, 100));
+    Bounds b = Bounds.newInstance(points);
+    assertEquals("center x coordinate", 45, b.getCenter().getX());
+    assertEquals("center y coordinate", 50, b.getCenter().getY());
+  }
+  
+  public void testNewInstance() {
+    Bounds b = Bounds.newInstance(0,0,45,45);
+  }
+  
+  @SuppressWarnings("unchecked")  
+  public void testNewInstanceArray() {
+    JsArray<Point> points = (JsArray<Point>) Point.createArray();
+    points.set(0, Point.newInstance(0, 0));
+    points.set(1, Point.newInstance(45, 45));
+    Bounds b = Bounds.newInstance(points);
+  }
+}

Property changes on: maps/maps/test/com/google/gwt/maps/client/geom/BoundsTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Author Id Revision HeadURL
Name: svn:eol-style
   + native

Index: maps/maps/src/com/google/gwt/maps/client/geom/Bounds.java
===================================================================
--- maps/maps/src/com/google/gwt/maps/client/geom/Bounds.java	(revision 766)
+++ maps/maps/src/com/google/gwt/maps/client/geom/Bounds.java	(working copy)
@@ -17,92 +17,74 @@
 
 import com.google.gwt.core.client.JavaScriptObject;
 import com.google.gwt.core.client.JsArray;
-import com.google.gwt.maps.client.impl.BoundsImpl;
 
 /**
  * Represents a rectangular bound. A Bounds is defined by minimum and maximum X
  * and Y coordinates on a plane.
  * 
  */
-public final class Bounds {
+public class Bounds extends JavaScriptObject {
 
-  static Bounds createPeer(JavaScriptObject jsoPeer) {
-    return new Bounds(jsoPeer);
-  }
-
-  private final JavaScriptObject jsoPeer;
-
   /**
    * A Bounds is defined by minimum and maximum X and Y coordinates on a plane.
    * 
    * @param points
    */
-  public Bounds(JsArray<Point> points) {
-    jsoPeer = BoundsImpl.impl.construct(points);
-  }
+  public static final native Bounds newInstance(JsArray<Point> points) /*-{
+    return new $wnd.GBounds(points);
+  }-*/;
 
-  /**
-   * Wrap an existing GBounds object.
-   * 
-   * @param jsoPeer object to wrap.
-   */
-  private Bounds(JavaScriptObject jsoPeer) {
-    this.jsoPeer = jsoPeer;
+  public static final native Bounds newInstance(int minX, int minY, int maxX,
+      int maxY) /*-{
+    return new $wnd.GBounds([new $wnd.GPoint(minX, minY), 
+      new $wnd.GPoint(maxX, maxY)]);
+  }-*/;
+
+  protected Bounds() {
+    // A protected constructor is required in a JS overlay.
   }
 
   /**
-   * Returns <code>true</code> if the passed rectangular area is entirely contained in this
-   * rectangular area.
+   * Returns <code>true</code> if the passed rectangular area is entirely
+   * contained in this rectangular area.
    * 
    * @param other the bound to compare.
-   * @return <code>true</code> if the passed rectangular area is entirely contained in this
-   *         rectangular area.
+   * @return <code>true</code> if the passed rectangular area is entirely
+   *         contained in this rectangular area.
    */
-  public boolean containsBounds(Bounds other) {
-    return BoundsImpl.impl.containsBounds(jsoPeer, other);
-  }
+  public final native boolean containsBounds(Bounds other) /*-{
+    return this.containsBounds(other);
+  }-*/;
 
   /**
-   * Returns <code>true</code> if the rectangular area (inclusively) contains the pixel
-   * coordinates.
+   * Returns <code>true</code> if the rectangular area (inclusively) contains
+   * the pixel coordinates.
    * 
    * @param p the point to compare.
-   * @return <code>true</code> if the rectangular area (inclusively) contains the pixel
-   *         coordinates.
+   * @return <code>true</code> if the rectangular area (inclusively) contains
+   *         the pixel coordinates.
    */
-  public boolean containsPoint(Point p) {
-    return BoundsImpl.impl.containsPoint(jsoPeer, p);
-  }
+  public final native boolean containsPoint(Point p) /*-{
+    return this.containsPoint(p);
+  }-*/;
 
   /**
    * Enlarges this box so that the point is also contained in this box.
    * 
    * @param point the point to add to the bound.
-   * @return a new bounds object that encloses the previous bounds plus the
-   *         supplied point.
    */
-  @SuppressWarnings("unchecked")
-  public Bounds extend(Point point) {
-    JsArray<Point> pointArgs = (JsArray<Point>) JavaScriptObject.createArray();
-    pointArgs.set(0, this.getUpperLeft());
-    pointArgs.set(1, this.getLowerRight());
+  public final native void extend(Point point) /*-{
+    return this.extend(point);
+  }-*/;
 
-    // The JavaScript API enlarges the existing Bounds object. This API creates
-    // a new object, so we need to clone this Bounds instance first.
-    Bounds b = new Bounds(pointArgs);
-    BoundsImpl.impl.extend(b.jsoPeer, point);
-    
-    return b;
-  }
-
   /**
    * Returns the pixel coordinates of the center of the rectangular area.
    * 
    * @return the pixel coordinates of the center of the rectangular area.
    */
-  public Point getCenter() {
-    return BoundsImpl.impl.mid(jsoPeer);
-  }
+  public final native Point getCenter() /*-{
+    return this.mid();
+  }-*/;
 
   /**
    * Returns the pixel coordinates of the lower right corner of the rectangular
@@ -111,45 +93,45 @@
    * @return the pixel coordinates of the lower right corner of the rectangular
    *         area.
    */
-  public Point getLowerRight() {
-    return BoundsImpl.impl.max(jsoPeer);
-  }
+  public final native Point getLowerRight() /*-{
+    return this.max();
+  }-*/;
 
   /**
    * Returns the x coordinate of the right edge of the rectangle.
    * 
    * @return the x coordinate of the right edge of the rectangle.
    */
-  public int getMaxX() {
-    return BoundsImpl.impl.getMaxX(jsoPeer);
-  }
+  public final native int getMaxX() /*-{
+    return this.maxX;
+  }-*/;
 
   /**
    * Returns the y coordinate of the bottom edge of the rectangle.
    * 
    * @return the y coordinate of the bottom edge of the rectangle.
    */
-  public int getMaxY() {
-    return BoundsImpl.impl.getMaxY(jsoPeer);
-  }
+  public final native int getMaxY() /*-{
+    return this.maxY;
+  }-*/;
 
   /**
    * Returns the x coordinate of the left edge of the rectangle.
    * 
    * @return the x coordinate of the left edge of the rectangle.
    */
-  public int getMinX() {
-    return BoundsImpl.impl.getMinX(jsoPeer);
-  }
+  public final native int getMinX() /*-{
+    return this.minX;
+  }-*/;
 
   /**
    * Returns the y coordinate of the top edge of the rectangle.
    * 
    * @return the y coordinate of the top edge of the rectangle.
    */
-  public int getMinY() {
-    return BoundsImpl.impl.getMinY(jsoPeer);
-  }
+  public final native int getMinY() /*-{
+    return this.minY;
+  }-*/;
 
   /**
    * Returns the pixel coordinates of the upper left corner of the rectangular
@@ -158,12 +140,8 @@
    * @return the pixel coordinates of the upper left corner of the rectangular
    *         area.
    */
-  public Point getUpperLeft() {
-    return BoundsImpl.impl.min(jsoPeer);
-  }
+  public final native Point getUpperLeft() /*-{
+    return this.min();
+  }-*/;
 
-  @Override
-  public String toString() {
-    return BoundsImpl.impl.toString(jsoPeer);
-  }
 }
Index: maps/maps/src/com/google/gwt/maps/client/impl/BoundsImpl.java
===================================================================
--- maps/maps/src/com/google/gwt/maps/client/impl/BoundsImpl.java	(revision 766)
+++ maps/maps/src/com/google/gwt/maps/client/impl/BoundsImpl.java	(working copy)
@@ -1,59 +0,0 @@
-/*
- * Copyright 2008 Google Inc.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.maps.client.impl;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.core.client.JsArray;
-import com.google.gwt.maps.client.geom.Bounds;
-import com.google.gwt.maps.client.geom.Point;
-import com.google.gwt.maps.jsio.client.BeanProperties;
-import com.google.gwt.maps.jsio.client.Constructor;
-import com.google.gwt.maps.jsio.client.JSFlyweightWrapper;
-
-/**
- * Wraps the GBounds object in the Maps API using JSIO.
- */
[EMAIL PROTECTED]
-public interface BoundsImpl extends JSFlyweightWrapper {
-
-  BoundsImpl impl = GWT.create(BoundsImpl.class);
-
-  @Constructor("$wnd.GBounds")
-  JavaScriptObject construct(JsArray<Point> points);
-
-  boolean containsBounds(JavaScriptObject jsoPeer, Bounds other);
-
-  boolean containsPoint(JavaScriptObject jsoPeer, Point point);
-
-  void extend(JavaScriptObject jsoPeer, Point point);
-
-  int getMaxX(JavaScriptObject jsoPeer);
-
-  int getMaxY(JavaScriptObject jsoPeer);
-
-  int getMinX(JavaScriptObject jsoPeer);
-
-  int getMinY(JavaScriptObject jsoPeer);
-
-  Point max(JavaScriptObject jsoPeer);
-
-  Point mid(JavaScriptObject jsoPeer);
-
-  Point min(JavaScriptObject jsoPeer);
-
-  String toString(JavaScriptObject jsoPeer);
-}
Index: maps/maps/test/com/google/gwt/maps/MapsTestSuite.java
===================================================================
--- maps/maps/test/com/google/gwt/maps/MapsTestSuite.java	(revision 766)
+++ maps/maps/test/com/google/gwt/maps/MapsTestSuite.java	(working copy)
@@ -24,6 +24,7 @@
 import com.google.gwt.maps.client.StatusCodesTest;
 import com.google.gwt.maps.client.control.ControlTest;
 import com.google.gwt.maps.client.geocode.GeocodeTest;
+import com.google.gwt.maps.client.geom.BoundsTest;
 import com.google.gwt.maps.client.geom.ProjectionTest;
 import com.google.gwt.maps.client.impl.MinimumMapVersionTest;
 import com.google.gwt.maps.client.overlay.GeoXmlOverlayTest;
@@ -57,6 +58,7 @@
     suite.addTestSuite(StatusCodesTest.class);
     suite.addTestSuite(PolyEventsTest.class);
     suite.addTestSuite(ProjectionTest.class);
+    suite.addTestSuite(BoundsTest.class);
     suite.addTestSuite(MinimumMapVersionTest.class);
     return suite;
   }

Reply via email to