Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix getPointColor().
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 21 Oct 2014 18:48:31 +0000 (20:48 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 21 Oct 2014 18:48:31 +0000 (20:48 +0200)
DrawingWindow.java
Test.java
overview.html

index 957f5ff..e7766d0 100644 (file)
@@ -34,7 +34,7 @@ import javax.swing.JPanel;
  * possible de fermer la fenêtre via le gestionnaire de fenêtres.
  *
  * @author Arnaud Giersch &lt;arnaud.giersch@univ-fcomte.fr&gt;
- * @version 20141021a
+ * @version 20141021b
  */
 public class DrawingWindow {
 
@@ -406,7 +406,8 @@ public class DrawingWindow {
      * @see #setBgColor(int)
      */
     public int getPointColor(int x, int y) {
-        return image.getRGB(x, y);
+        return (x < 0 || y < 0 || x >= width || y >= height) ?
+            0 : image.getRGB(x, y) & 0x00ffffff;
     }
 
     /**
index d68d8a4..9737b9c 100644 (file)
--- a/Test.java
+++ b/Test.java
@@ -1,6 +1,6 @@
 class Test{
     public static void main(String[] args) {
-        DrawingWindow w1 = new DrawingWindow("Test!", 400, 400);
+        DrawingWindow w1 = new DrawingWindow("Test!", 400, 300);
 
         w1.setColor("lawngreen");
         for (int i = 0; i < 12; i++) {
@@ -28,10 +28,25 @@ class Test{
         w1.drawLine(-10, w1.height - 10, w1.width + 10, w1.height - 10);
         w1.drawLine(w1.width - 10, -10, w1.width - 10, w1.height + 10);
         w1.setColor("red");
-        for (int x = -10; x <= w1.width + 10; x++)
-            w1.drawPoint(x, w1.height - 20);
-        for (int y = -10; y <= w1.height + 10; y++)
-            w1.drawPoint(w1.width - 20, y);
+        for (int x = -10; x <= w1.width + 10; x++) {
+            int y = w1.height - 20;
+            w1.drawPoint(x, y);
+            int c = w1.getPointColor(x, y);
+            if (c != (x < 0 || x >= w1.width ? 0 : 0x00ff0000))
+                throw new AssertionError("Error with getPointColor(): " +
+                                         "(" + x + ", " + y + "): " +
+                                         String.format("%#010x", c));
+        }
+        for (int y = -10; y <= w1.height + 10; y++) {
+            int x = w1.width - 20;
+            w1.drawPoint(x, y);
+            w1.getPointColor(x, y);
+            int c = w1.getPointColor(x, y);
+            if (c != (y < 0 || y >= w1.height ? 0 : 0x00ff0000))
+                throw new AssertionError("Error with getPointColor(): " +
+                                         "(" + x + ", " + y + "): " +
+                                         String.format("%#010x", c));
+        }
 
         DrawingWindow w2 = new DrawingWindow("Test!", 800, 600);
         w2.setBgColor("red");
index 69ce0b5..c5058e8 100644 (file)
@@ -42,6 +42,7 @@
 -- mar. 21 oct. 2014
         * Les méthodes *sleep() sont `public'.
         * Vérification des coordonnées dans drawPoint().
+        * Correction de getPointColor().
 
 -- ven. 17 oct. 2014
         * Correction d'un décalage avec getMouse{X,Y}.