Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Check bounds in drawPoint().
[graphlib_java.git] / Test.java
index 65a891f..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);
+
         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);
         }
 
+        // 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");
@@ -45,9 +56,17 @@ class Test{
         }
         w2.closeGraph();
 
-        while (w1.waitMousePress(5 * 1000))
-            System.out.println("[ " + w1.getMouseX() + " ; " + w1.getMouseY() +
-                               " ] -- button " + w1.getMouseButton());
+        System.out.println("Click anywhere on w1...");
+
+        w1.setColor("black");
+        while (w1.waitMousePress(5 * 1000)) {
+            int x = w1.getMouseX();
+            int y = w1.getMouseY();
+            System.out.println("[ " + x + " ; " + y + " ] - " +
+                               w1.getMouseButton());
+            w1.drawLine(x - 5, y, x + 5, y);
+            w1.drawLine(x, y - 5, x, y + 5);
+        }
 
         System.out.println("Done!");
     }