]> git.leonardobizzoni.com Git - astar-visualizer/commitdiff
Clean up
authorLeonardoBizzoni <leo2002714@gmail.com>
Sat, 20 Nov 2021 08:08:13 +0000 (09:08 +0100)
committerLeonardoBizzoni <leo2002714@gmail.com>
Sat, 20 Nov 2021 08:08:13 +0000 (09:08 +0100)
14 files changed:
src/main/java/Main/AStar.java
src/main/java/Main/Map.java
target/PathVisualizer-1.0-SNAPSHOT.jar
target/classes/Main/AStar.class
target/classes/Main/App.class
target/classes/Main/Map.class
target/classes/Main/Node.class
target/classes/Main/PathfinderUtils.class
target/maven-archiver/pom.properties
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
target/surefire-reports/Main.AppTest.txt
target/surefire-reports/TEST-Main.AppTest.xml
target/test-classes/Main/AppTest.class

index 063931291bf89b9472c377a49e40f3555929b84a..db68bbd25bf5828aa796440f3cc52e2108066bd4 100644 (file)
@@ -25,13 +25,13 @@ public class AStar implements Runnable {
                 calculateOpenNode(x, y, parent);
             }
 
+            map.repaint();
             if ((parent = getNextBestNode()) == null)
                 return;
 
             PathfinderUtils.closedNodes.add(parent);
             PathfinderUtils.openNodes.remove(parent);
 
-            map.repaint();
             try {
                 Thread.sleep(map.speed);
             } catch (InterruptedException e) {
index 5a7fdc2ed704ac1419864e3bb0bdc199e3be5587..00d4a3243e6a9a270869f5a8733cf021c3d3fdd8 100644 (file)
@@ -1,8 +1,8 @@
 package Main;
 
 import java.awt.Color;
-import java.awt.Graphics;
 import java.awt.Dimension;
+import java.awt.Graphics;
 import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
 import java.awt.event.MouseEvent;
@@ -22,10 +22,10 @@ class Map extends JPanel implements MouseListener, MouseMotionListener, KeyListe
     private boolean running = false;
 
     private int size = 20;
-    int speed = 2;
+    int speed = 5;
 
     public Map() {
-        this.setBackground(new Color(40, 40, 40));
+        setBackground(new Color(40, 40, 40));
 
         addMouseListener(this);
         addKeyListener(this);
@@ -41,8 +41,8 @@ class Map extends JPanel implements MouseListener, MouseMotionListener, KeyListe
         window.pack();
         window.setVisible(true);
 
-        this.revalidate();
-        this.repaint();
+        revalidate();
+        repaint();
     }
 
     public void paintComponent(Graphics g) {
@@ -50,8 +50,8 @@ class Map extends JPanel implements MouseListener, MouseMotionListener, KeyListe
 
         // Draws the grid
         g.setColor(new Color(50, 48, 47));
-        for (int i = 0; i < this.getWidth(); i += size) {
-            for (int j = 0; j < this.getHeight(); j += size) {
+        for (int i = 0; i < getWidth(); i += size) {
+            for (int j = 0; j < getHeight(); j += size) {
                 g.drawRect(i, j, size, size);
             }
         }
@@ -115,21 +115,18 @@ class Map extends JPanel implements MouseListener, MouseMotionListener, KeyListe
                 else if (PathfinderUtils.endNode != null && PathfinderUtils.startNode == null) {
                     if (PathfinderUtils.isSameNode(node, PathfinderUtils.endNode)) {
                         // Send an error message saying that start and end node are the same
-                        JOptionPane.showMessageDialog(null, "End node and start node can't be the same node",
-                                "Same node error", JOptionPane.ERROR_MESSAGE);
+                        JOptionPane.showMessageDialog(null, "End node and start node can't be the same node", "Same node error", JOptionPane.ERROR_MESSAGE);
                         return;
                     }
 
                     // Set the node as the start node
                     PathfinderUtils.startNode = node;
-
                 }
 
-                // If they both exist check if same node else move che start node
+                // If the start node exists check if end node exist and move the start
                 else {
                     if (PathfinderUtils.endNode != null && PathfinderUtils.isSameNode(node, PathfinderUtils.endNode)) {
-                        JOptionPane.showMessageDialog(null, "End node and start node can't be the same node",
-                                "Same node error", JOptionPane.ERROR_MESSAGE);
+                        JOptionPane.showMessageDialog(null, "End node and start node can't be the same node", "Same node error", JOptionPane.ERROR_MESSAGE);
                         return;
                     }
 
@@ -150,8 +147,7 @@ class Map extends JPanel implements MouseListener, MouseMotionListener, KeyListe
                 else if (PathfinderUtils.startNode != null && PathfinderUtils.endNode == null) {
                     if (PathfinderUtils.isSameNode(node, PathfinderUtils.startNode)) {
                         // Send an error message saying that start and end node are the same
-                        JOptionPane.showMessageDialog(null, "End node and start node can't be the same node",
-                                "Same node error", JOptionPane.ERROR_MESSAGE);
+                        JOptionPane.showMessageDialog(null, "End node and start node can't be the same node", "Same node error", JOptionPane.ERROR_MESSAGE);
                         return;
                     }
 
@@ -159,11 +155,10 @@ class Map extends JPanel implements MouseListener, MouseMotionListener, KeyListe
                     PathfinderUtils.endNode = node;
 
                 }
-                // If they both exist check if same node else move the end node
+                // If the end node exists check if start node exist and move the start
                 else {
                     if (PathfinderUtils.startNode !=null && PathfinderUtils.isSameNode(node, PathfinderUtils.startNode)) {
-                        JOptionPane.showMessageDialog(null, "End node and start node can't be the same node",
-                                "Same node error", JOptionPane.ERROR_MESSAGE);
+                        JOptionPane.showMessageDialog(null, "End node and start node can't be the same node", "Same node error", JOptionPane.ERROR_MESSAGE);
                         return;
                     }
 
@@ -184,55 +179,53 @@ class Map extends JPanel implements MouseListener, MouseMotionListener, KeyListe
 
                 PathfinderUtils.barriers.add(node);
             }
-
-            // Update the UI with barrier/start/end node
-            repaint();
         }
 
         // Deleting nodes
         else if (SwingUtilities.isRightMouseButton(e)) {
-            int posX = e.getX() - (e.getX() % size);
-            int posY = e.getY() - (e.getY() % size);
-
             if (key == 's' && PathfinderUtils.startNode != null) {
-                if (PathfinderUtils.startNode.getX() == posX && PathfinderUtils.startNode.getY() == posY) {
+                if (PathfinderUtils.isSameNode(node, PathfinderUtils.startNode)) {
                     PathfinderUtils.startNode = null;
                 }
             }
 
             else if (key == 'e' && PathfinderUtils.endNode != null) {
-                if (PathfinderUtils.endNode.getX() == posX && PathfinderUtils.endNode.getY() == posY) {
+                if (PathfinderUtils.isSameNode(node, PathfinderUtils.endNode)) {
                     PathfinderUtils.endNode = null;
                 }
             }
 
             else {
-                int nodeID = PathfinderUtils.locateBarrier(posX, posY);
+                int nodeID = PathfinderUtils.locateBarrier(node.getX(), node.getY());
 
                 if (nodeID != -1) {
                     PathfinderUtils.remove(nodeID);
                 }
             }
 
-            repaint();
         }
+
+        repaint();
     }
 
     @Override
     public void keyPressed(KeyEvent e) {
         key = e.getKeyChar();
 
+        if (key == 'q') {
+            System.exit(0);
+        }
+
         if (key == KeyEvent.VK_SPACE) {
             if (running == false && isFinished == false) {
                 if (PathfinderUtils.startNode == null || PathfinderUtils.endNode == null) {
-                    JOptionPane.showMessageDialog(null, "Missing start or end node", "Missing node",
-                            JOptionPane.ERROR_MESSAGE);
+                    JOptionPane.showMessageDialog(null, "Missing start or end node", "Missing node", JOptionPane.ERROR_MESSAGE);
                     return;
                 }
 
                 running = true;
 
-                // AStar needs to extend runnable because otherwise map.repaint() will wait to update the UI
+                // AStar needs to extend runnable because otherwise calling map.repaint() will wait for AStar to complete the pathfinding before updating the UI
                 new Thread(new AStar(this)).start();
             } else if (running == false && isFinished == true) {
                 PathfinderUtils.barriers.clear();
@@ -242,9 +235,8 @@ class Map extends JPanel implements MouseListener, MouseMotionListener, KeyListe
                 PathfinderUtils.endNode = null;
 
                 isFinished = false;
-                running = false;
 
-                this.repaint();
+                repaint();
             }
         }
     }
index b8d5142c8c67c2c6f90ed4f3cfa5df5fed7fcfc0..d3bf56fa714f3e35838ed05ce85bf78fc640f998 100644 (file)
Binary files a/target/PathVisualizer-1.0-SNAPSHOT.jar and b/target/PathVisualizer-1.0-SNAPSHOT.jar differ
index 7861da64f30328ba1b25fe820d9e6273654f0f17..5a7dca54df6e2a61ed9f8dfc42ba1dff57f1e2e5 100644 (file)
Binary files a/target/classes/Main/AStar.class and b/target/classes/Main/AStar.class differ
index 5d655f5fae37bf711c33d7669b921f5e047bb031..13e30fb49cd7e219d5a1971c5fd60b4b030bce85 100644 (file)
Binary files a/target/classes/Main/App.class and b/target/classes/Main/App.class differ
index c18b509284a356f978a21749fb994f65218aa1d3..4ddee1331c5daaed8718e4741b545c358058112a 100644 (file)
Binary files a/target/classes/Main/Map.class and b/target/classes/Main/Map.class differ
index 930f2951c3a36fe849966c6cd6a37e211530f7d2..3ec59642ea54906e9c08fe2950a1b61fdfd1aeb9 100644 (file)
Binary files a/target/classes/Main/Node.class and b/target/classes/Main/Node.class differ
index a6ec0004bc6c2aa82a17eeb2102208067abaf160..ef6af34278c55708becea6b8c7a6f6d7b5051c9c 100644 (file)
Binary files a/target/classes/Main/PathfinderUtils.class and b/target/classes/Main/PathfinderUtils.class differ
index b1908d5aae554ec18d513c35086d6ba86a3b3d68..6be0d6d483e7237fe4d14966a32ee46e65ff948b 100644 (file)
@@ -1,4 +1,4 @@
-#Created by Apache Maven 3.6.3
+#Created by Apache Maven 3.3.9
 groupId=Main
 artifactId=PathVisualizer
 version=1.0-SNAPSHOT
index cbf65bb88f1eb5ea1ba4bd4e75b93f268ad6fb0d..a00021999858409f7ae62dd6dc7d703667ad1654 100644 (file)
@@ -1,5 +1,5 @@
-/home/leo/Docs/Proj/Pathfinder/src/main/java/Main/Node.java
-/home/leo/Docs/Proj/Pathfinder/src/main/java/Main/App.java
-/home/leo/Docs/Proj/Pathfinder/src/main/java/Main/PathfinderUtils.java
-/home/leo/Docs/Proj/Pathfinder/src/main/java/Main/Map.java
-/home/leo/Docs/Proj/Pathfinder/src/main/java/Main/AStar.java
+/home/leo/Docs/Proj/pathfinding-visualizer/src/main/java/Main/PathfinderUtils.java
+/home/leo/Docs/Proj/pathfinding-visualizer/src/main/java/Main/Node.java
+/home/leo/Docs/Proj/pathfinding-visualizer/src/main/java/Main/App.java
+/home/leo/Docs/Proj/pathfinding-visualizer/src/main/java/Main/Map.java
+/home/leo/Docs/Proj/pathfinding-visualizer/src/main/java/Main/AStar.java
index 2af0a5f36e8fb758fe24bf011035915e35cf37aa..e1f0ebcdb4a4eaf0bb06834f67fc31462b9cdbd9 100644 (file)
@@ -1 +1 @@
-/home/leo/Docs/Proj/Pathfinder/src/test/java/Main/AppTest.java
+/home/leo/Docs/Proj/pathfinding-visualizer/src/test/java/Main/AppTest.java
index 3aed94744c09ae4d1bfd4c23a7def682c112096d..67bc74a54a97c8f151d43d5ef20d286d3b3e0848 100644 (file)
@@ -1,4 +1,4 @@
 -------------------------------------------------------------------------------
 Test set: Main.AppTest
 -------------------------------------------------------------------------------
-Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.025 s - in Main.AppTest
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.021 s - in Main.AppTest
index 595731f553a69bdf4da4af1359fb7ea0e55f8872..1598d02bb5ecb4299854af26bbdc8c2775029b7e 100644 (file)
@@ -1,61 +1,54 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="Main.AppTest" time="0.025" tests="1" errors="0" skipped="0" failures="0">
+<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="Main.AppTest" time="0.021" tests="1" errors="0" skipped="0" failures="0">
   <properties>
-    <property name="awt.toolkit" value="sun.awt.X11.XToolkit"/>
-    <property name="java.specification.version" value="11"/>
-    <property name="sun.cpu.isalist" value=""/>
+    <property name="java.specification.version" value="16"/>
     <property name="sun.jnu.encoding" value="ANSI_X3.4-1968"/>
-    <property name="java.class.path" value="/home/leo/Docs/Proj/Pathfinder/target/test-classes:/home/leo/Docs/Proj/Pathfinder/target/classes:/home/leo/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/leo/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:"/>
+    <property name="java.class.path" value="/home/leo/Docs/Proj/pathfinding-visualizer/target/test-classes:/home/leo/Docs/Proj/pathfinding-visualizer/target/classes:/home/leo/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/leo/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:"/>
     <property name="java.vm.vendor" value="Oracle Corporation"/>
     <property name="sun.arch.data.model" value="64"/>
-    <property name="java.vendor.url" value="http://java.oracle.com/"/>
-    <property name="user.timezone" value=""/>
-    <property name="java.vm.specification.version" value="11"/>
+    <property name="java.vendor.url" value="https://java.oracle.com/"/>
     <property name="os.name" value="Linux"/>
+    <property name="java.vm.specification.version" value="16"/>
     <property name="sun.java.launcher" value="SUN_STANDARD"/>
     <property name="user.country" value="US"/>
-    <property name="sun.boot.library.path" value="/usr/lib/jvm/openjdk11-bin/lib"/>
-    <property name="sun.java.command" value="/home/leo/Docs/Proj/Pathfinder/target/surefire/surefirebooter7497617524640717844.jar /home/leo/Docs/Proj/Pathfinder/target/surefire 2021-11-19T21-17-25_132-jvmRun1 surefire5030477053776971331tmp surefire_02397316267537071803tmp"/>
+    <property name="sun.boot.library.path" value="/home/leo/.config/jdks/openjdk-16.0.2/lib"/>
+    <property name="sun.java.command" value="/home/leo/Docs/Proj/pathfinding-visualizer/target/surefire/surefirebooter10436255508326751885.jar /home/leo/Docs/Proj/pathfinding-visualizer/target/surefire 2021-11-20T09-06-55_141-jvmRun1 surefire17825492757088903556tmp surefire_08327865763710316556tmp"/>
     <property name="jdk.debug" value="release"/>
-    <property name="surefire.test.class.path" value="/home/leo/Docs/Proj/Pathfinder/target/test-classes:/home/leo/Docs/Proj/Pathfinder/target/classes:/home/leo/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/leo/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:"/>
+    <property name="surefire.test.class.path" value="/home/leo/Docs/Proj/pathfinding-visualizer/target/test-classes:/home/leo/Docs/Proj/pathfinding-visualizer/target/classes:/home/leo/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/leo/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:"/>
     <property name="sun.cpu.endian" value="little"/>
     <property name="user.home" value="/home/leo"/>
     <property name="user.language" value="en"/>
     <property name="java.specification.vendor" value="Oracle Corporation"/>
-    <property name="java.version.date" value="2018-09-25"/>
-    <property name="java.home" value="/usr/lib/jvm/openjdk11-bin"/>
+    <property name="java.version.date" value="2021-07-20"/>
+    <property name="java.home" value="/home/leo/.config/jdks/openjdk-16.0.2"/>
     <property name="file.separator" value="/"/>
-    <property name="basedir" value="/home/leo/Docs/Proj/Pathfinder"/>
-    <property name="java.vm.compressedOopsMode" value="Zero based"/>
+    <property name="basedir" value="/home/leo/Docs/Proj/pathfinding-visualizer"/>
+    <property name="java.vm.compressedOopsMode" value="32-bit"/>
     <property name="line.separator" value="&#10;"/>
-    <property name="java.specification.name" value="Java Platform API Specification"/>
     <property name="java.vm.specification.vendor" value="Oracle Corporation"/>
-    <property name="java.awt.graphicsenv" value="sun.awt.X11GraphicsEnvironment"/>
-    <property name="surefire.real.class.path" value="/home/leo/Docs/Proj/Pathfinder/target/surefire/surefirebooter7497617524640717844.jar"/>
+    <property name="java.specification.name" value="Java Platform API Specification"/>
+    <property name="surefire.real.class.path" value="/home/leo/Docs/Proj/pathfinding-visualizer/target/surefire/surefirebooter10436255508326751885.jar"/>
     <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
-    <property name="java.runtime.version" value="11+28"/>
+    <property name="java.runtime.version" value="16.0.2+7-67"/>
     <property name="user.name" value="leo"/>
     <property name="path.separator" value=":"/>
     <property name="os.version" value="5.13.19_1"/>
     <property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
     <property name="file.encoding" value="ANSI_X3.4-1968"/>
     <property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
-    <property name="java.vendor.version" value="18.9"/>
     <property name="localRepository" value="/home/leo/.m2/repository"/>
-    <property name="java.vendor.url.bug" value="http://bugreport.java.com/bugreport/"/>
+    <property name="java.vendor.url.bug" value="https://bugreport.java.com/bugreport/"/>
     <property name="java.io.tmpdir" value="/tmp"/>
-    <property name="java.version" value="11"/>
-    <property name="user.dir" value="/home/leo/Docs/Proj/Pathfinder"/>
+    <property name="java.version" value="16.0.2"/>
+    <property name="user.dir" value="/home/leo/Docs/Proj/pathfinding-visualizer"/>
     <property name="os.arch" value="amd64"/>
     <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
-    <property name="java.awt.printerjob" value="sun.print.PSPrinterJob"/>
-    <property name="sun.os.patch.level" value="unknown"/>
     <property name="java.library.path" value="/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib"/>
+    <property name="java.vm.info" value="mixed mode, sharing"/>
     <property name="java.vendor" value="Oracle Corporation"/>
-    <property name="java.vm.info" value="mixed mode"/>
-    <property name="java.vm.version" value="11+28"/>
+    <property name="java.vm.version" value="16.0.2+7-67"/>
     <property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
-    <property name="java.class.version" value="55.0"/>
+    <property name="java.class.version" value="60.0"/>
   </properties>
   <testcase name="shouldAnswerWithTrue" classname="Main.AppTest" time="0.001"/>
 </testsuite>
\ No newline at end of file
index 6b3f4e2a47ae644aee71876320b08afdf766f7ab..a08e3e3772afae6fdfb00e95ffc185c606b4b1fa 100644 (file)
Binary files a/target/test-classes/Main/AppTest.class and b/target/test-classes/Main/AppTest.class differ