[cp-patches] FYI: Point.setLocation() fix

David Gilbert david.gilbert at object-refinery.com
Tue Jun 27 14:04:00 UTC 2006


This patch (committed) fixes a failing test from Intel's test suite:

2006-06-27  David Gilbert  <david.gilbert at object-refinery.com>

	* java/awt/Point.java
	(setLocation(double, double)): Round to nearest integer coordinates.

Regards,

Dave
-------------- next part --------------
Index: java/awt/Point.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/Point.java,v
retrieving revision 1.11
diff -u -r1.11 Point.java
--- java/awt/Point.java	16 Sep 2005 01:11:39 -0000	1.11
+++ java/awt/Point.java	27 Jun 2006 13:59:32 -0000
@@ -1,5 +1,5 @@
 /* Point.java -- represents a point in 2-D space
-   Copyright (C) 1999, 2002 Free Software Foundation
+   Copyright (C) 1999, 2002, 2006 Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -83,7 +83,7 @@
 
   /**
    * Initializes a new instance of <code>Point</code> representing the
-   * coordiates (0,0).
+   * coordinates (0, 0).
    *
    * @since 1.1
    */
@@ -93,7 +93,7 @@
 
   /**
    * Initializes a new instance of <code>Point</code> with coordinates
-   * identical to the coordinates of the specified points.
+   * identical to the coordinates of the specified point.
    *
    * @param p the point to copy the coordinates from
    * @throws NullPointerException if p is null
@@ -178,15 +178,16 @@
 
   /**
    * Sets this object's coordinates to the specified values.  This method
-   * performs normal casting from double to int, so you may lose precision.
+   * rounds to the nearest integer coordinates by adding 0.5 and calling 
+   * {@link Math#floor(double)}.
    *
    * @param x the new X coordinate
    * @param y the new Y coordinate
    */
   public void setLocation(double x, double y)
   {
-    this.x = (int) x;
-    this.y = (int) y;
+    this.x = (int) Math.floor(x + 0.5);
+    this.y = (int) Math.floor(y + 0.5);
   }
 
   /**


More information about the Classpath-patches mailing list