Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Check bounds in drawPoint().
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 21 Oct 2014 15:51:43 +0000 (17:51 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 21 Oct 2014 15:51:43 +0000 (17:51 +0200)
DrawingWindow.java
Test.java
overview.html

index 1b93c57..957f5ff 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;
  * possible de fermer la fenêtre via le gestionnaire de fenêtres.
  *
  * @author Arnaud Giersch &lt;arnaud.giersch@univ-fcomte.fr&gt;
- * @version 20141021
+ * @version 20141021a
  */
 public class DrawingWindow {
 
  */
 public class DrawingWindow {
 
@@ -242,6 +242,8 @@ public class DrawingWindow {
      * @see #setColor
      */
     public void drawPoint(int x, int y) {
      * @see #setColor
      */
     public void drawPoint(int x, int y) {
+        if (x < 0 || y < 0 || x >= width || y >= height)
+            return;
         synchronized (image) {
             image.setRGB(x, y, graphics.getColor().getRGB());
         }
         synchronized (image) {
             image.setRGB(x, y, graphics.getColor().getRGB());
         }
index d3e4e62..d68d8a4 100644 (file)
--- a/Test.java
+++ b/Test.java
@@ -1,6 +1,7 @@
 class Test{
     public static void main(String[] args) {
         DrawingWindow w1 = new DrawingWindow("Test!", 400, 400);
 class Test{
     public static void main(String[] args) {
         DrawingWindow w1 = new DrawingWindow("Test!", 400, 400);
+
         w1.setColor("lawngreen");
         for (int i = 0; i < 12; i++) {
             int p = 10 * i + 10;
         w1.setColor("lawngreen");
         for (int i = 0; i < 12; i++) {
             int p = 10 * i + 10;
@@ -22,6 +23,16 @@ class Test{
             w1.fillTriangle(p, 150, p + i, 150 + i/2, p, 150 + i);
         }
 
             w1.fillTriangle(p, 150, p + i, 150 + i/2, p, 150 + i);
         }
 
+        // Try out of bounds drawings
+        w1.setColor("blue");
+        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);
+
         DrawingWindow w2 = new DrawingWindow("Test!", 800, 600);
         w2.setBgColor("red");
         w2.setColor("blue");
         DrawingWindow w2 = new DrawingWindow("Test!", 800, 600);
         w2.setBgColor("red");
         w2.setColor("blue");
@@ -47,6 +58,7 @@ class Test{
 
         System.out.println("Click anywhere on w1...");
 
 
         System.out.println("Click anywhere on w1...");
 
+        w1.setColor("black");
         while (w1.waitMousePress(5 * 1000)) {
             int x = w1.getMouseX();
             int y = w1.getMouseY();
         while (w1.waitMousePress(5 * 1000)) {
             int x = w1.getMouseX();
             int y = w1.getMouseY();
index 4b85e16..69ce0b5 100644 (file)
     <h2>Modifications</h2>
 
     <p><pre>
     <h2>Modifications</h2>
 
     <p><pre>
--- mar. 21 oct. 2014 14:52:46 +0200
+-- mar. 21 oct. 2014
         * Les méthodes *sleep() sont `public'.
         * Les méthodes *sleep() sont `public'.
+        * Vérification des coordonnées dans drawPoint().
 
 
--- ven. 17 oct. 2014 14:09:50 +0200
+-- ven. 17 oct. 2014
         * Correction d'un décalage avec getMouse{X,Y}.
 
         * Correction d'un décalage avec getMouse{X,Y}.
 
--- lun. 14 oct. 2014 22:10:45 +0200
+-- lun. 14 oct. 2014
         * Ajout des méthodes setColor(int) et setBgColor(int).
         * Liste de noms de couleurs plus complète.
         * Ne termine l'application que lorsque la dernière fenêtre est fermée.
         * Ajout des méthodes setColor(int) et setBgColor(int).
         * Liste de noms de couleurs plus complète.
         * Ne termine l'application que lorsque la dernière fenêtre est fermée.