classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] Patch: don't use integer division in color calculation


From: Anthony Green
Subject: [cp-patches] Patch: don't use integer division in color calculation
Date: Wed, 14 Sep 2005 17:43:20 -0700

There are really two patches here.  The first is an integer division
problem.  I think the intent was really to perform floating point
divition when computing saturation.

The second just adds some clarifying comments for the next person who
looks at this code with FindBugs.


2005-09-14  Anthony Green  <address@hidden>

        * java/awt/Color.java (RGBtoHSB): Don't use integer division when
        calculating saturation.
        * java/awt/Rectangle.java (equals): Explain why hashCode() isn't
        required.
        * java/awt/Point.java (equals): Ditto.


Index: java/awt/Color.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Color.java,v
retrieving revision 1.12
diff -u -r1.12 Color.java
--- java/awt/Color.java 2 Jul 2005 20:32:23 -0000       1.12
+++ java/awt/Color.java 14 Sep 2005 23:49:18 -0000
@@ -762,7 +762,7 @@
     if (max == 0)
       array[1] = 0;
     else
-      array[1] = (max - min) / max;
+      array[1] = ((float) (max - min)) / ((float) max);
     // Calculate hue.
     if (array[1] == 0)
       array[0] = 0;
Index: java/awt/Point.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Point.java,v
retrieving revision 1.10
diff -u -r1.10 Point.java
--- java/awt/Point.java 2 Jul 2005 20:32:25 -0000       1.10
+++ java/awt/Point.java 14 Sep 2005 23:49:24 -0000
@@ -226,6 +226,10 @@
   */
   public boolean equals(Object obj)
   {
+    // NOTE: No special hashCode() method is required for this class,
+    // as this equals() implementation is functionally equivalent to
+    // super.equals(), which does define a proper hashCode().
+
     if (! (obj instanceof Point2D))
       return false;
     Point2D p = (Point2D) obj;
Index: java/awt/Rectangle.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Rectangle.java,v
retrieving revision 1.15
diff -u -r1.15 Rectangle.java
--- java/awt/Rectangle.java     2 Jul 2005 20:32:25 -0000       1.15
+++ java/awt/Rectangle.java     14 Sep 2005 23:49:24 -0000
@@ -727,6 +727,10 @@
    */
   public boolean equals(Object obj)
   {
+    // NOTE: No special hashCode() method is required for this class,
+    // as this equals() implementation is functionally equivalent to
+    // super.equals(), which does define a proper hashCode().
+
     if (! (obj instanceof Rectangle2D))
       return false;
     Rectangle2D r = (Rectangle2D) obj;






reply via email to

[Prev in Thread] Current Thread [Next in Thread]