diff --git a/src/main/java/edu/ntnu/stud/chaosgame/Main.java b/src/main/java/edu/ntnu/stud/chaosgame/Main.java index 7d603612851f459fa6c3e07d4207b2b0fb814140..146a72822ca3c3f4c80543ba13f4530cc79d9747 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/Main.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/Main.java @@ -1,10 +1,9 @@ package edu.ntnu.stud.chaosgame; -import edu.ntnu.stud.chaosgame.controller.ChaosGameButtonController; -import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription; -import edu.ntnu.stud.chaosgame.model.game.ChaosGameFileHandler; -import edu.ntnu.stud.chaosgame.model.game.ChaosCanvas; -import edu.ntnu.stud.chaosgame.model.game.ChaosGame; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGameFileHandler; +import edu.ntnu.stud.chaosgame.controller.game.ChaosCanvas; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGame; import edu.ntnu.stud.chaosgame.model.generators.ChaosGameDescriptionFactory; import edu.ntnu.stud.chaosgame.view.ChaosGameGUIView; import javafx.application.Application; diff --git a/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameObserver.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameObserver.java index d558acb57546382eaa22b192fd1471938b980287..f9a259e6bcca19721ba2ef1efc2cfcdff97c9673 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameObserver.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameObserver.java @@ -1,7 +1,7 @@ package edu.ntnu.stud.chaosgame.controller; -import edu.ntnu.stud.chaosgame.model.game.ChaosCanvas; -import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription; +import edu.ntnu.stud.chaosgame.controller.game.ChaosCanvas; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription; /** * Observer class for monitoring changes to the active diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosCanvas.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosCanvas.java similarity index 98% rename from src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosCanvas.java rename to src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosCanvas.java index d8d4afa03250bdae735cdb1cd70d0863031920f5..6cb462f21eb64e5d635c778e831e724f776dde4e 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosCanvas.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosCanvas.java @@ -1,4 +1,4 @@ -package edu.ntnu.stud.chaosgame.model.game; +package edu.ntnu.stud.chaosgame.controller.game; import edu.ntnu.stud.chaosgame.model.data.Matrix2x2; import edu.ntnu.stud.chaosgame.model.data.Vector2D; diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGame.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGame.java similarity index 97% rename from src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGame.java rename to src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGame.java index c9e34d378a86ad8e1994c9069e0ea14c58164d8b..925b698b9cf20149c957024a91d24886ff065ba5 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGame.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGame.java @@ -1,4 +1,4 @@ -package edu.ntnu.stud.chaosgame.model.game; +package edu.ntnu.stud.chaosgame.controller.game; import edu.ntnu.stud.chaosgame.model.data.Vector2D; import java.util.Random; diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGameDescription.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameDescription.java similarity index 97% rename from src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGameDescription.java rename to src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameDescription.java index eb54ec4320662359c25585f520738652b89be836..069109a1ce3ebd0f767e2778040de08ae4452b8f 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGameDescription.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameDescription.java @@ -1,4 +1,4 @@ -package edu.ntnu.stud.chaosgame.model.game; +package edu.ntnu.stud.chaosgame.controller.game; import edu.ntnu.stud.chaosgame.model.data.Vector2D; diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGameFileHandler.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameFileHandler.java similarity index 97% rename from src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGameFileHandler.java rename to src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameFileHandler.java index 9bd2532e5c196734e9fae6697f5b3bcb3acb3a69..8af2091c7366daf24d1de20a1ad8b6d8c211627f 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGameFileHandler.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameFileHandler.java @@ -1,4 +1,4 @@ -package edu.ntnu.stud.chaosgame.model.game; +package edu.ntnu.stud.chaosgame.controller.game; import edu.ntnu.stud.chaosgame.model.data.Complex; import edu.ntnu.stud.chaosgame.model.data.Matrix2x2; @@ -34,11 +34,15 @@ public class ChaosGameFileHandler { scanner.useLocale(Locale.ENGLISH); // Use a delimiter that splits on commas and new lines, and ignores comment lines. - scanner.useDelimiter("\\s*,\\s*|\\s*\\r?\\n+\\s*|(?m)^#.*$"); +scanner.useDelimiter(",\\s*|\\r?\\n|(\\s*#.*\\s*)"); + String firstLine = scanner.next().trim(); + + - String firstLine = scanner.nextLine().trim(); if (firstLine.equals("Affine2D")) { + + // Read the minimum vector if (scanner.hasNextDouble()) { double x0min = scanner.nextDouble(); diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/data/Matrix2x2.java b/src/main/java/edu/ntnu/stud/chaosgame/model/data/Matrix2x2.java index 8b5e1de1d3f64ce848ab1d6d9d6e65679226d184..945ee4d4b1868439189f08a15a2b7cafa9221d42 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/data/Matrix2x2.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/model/data/Matrix2x2.java @@ -1,6 +1,6 @@ package edu.ntnu.stud.chaosgame.model.data; -import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription; /** * Class representing a 2x2 matrix. diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/generators/ChaosGameDescriptionFactory.java b/src/main/java/edu/ntnu/stud/chaosgame/model/generators/ChaosGameDescriptionFactory.java index 78a77384cd499d5b9efc8fd58d4783f6c5786cc7..a83986b1a4e732231ad3b43942915b068256d7aa 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/generators/ChaosGameDescriptionFactory.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/model/generators/ChaosGameDescriptionFactory.java @@ -1,7 +1,7 @@ package edu.ntnu.stud.chaosgame.model.generators; -import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription; -import edu.ntnu.stud.chaosgame.model.game.ChaosGameFileHandler; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGameFileHandler; import java.io.File; import java.io.IOException; import java.util.ArrayList; diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/transformations/AffineTransform2D.java b/src/main/java/edu/ntnu/stud/chaosgame/model/transformations/AffineTransform2D.java index 65a871df227eddf344cf43b92c214df0cd1530f1..5d519ba0a1ee07cc0cfe9807e5a3ba7551cb5d2f 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/transformations/AffineTransform2D.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/model/transformations/AffineTransform2D.java @@ -2,7 +2,7 @@ package edu.ntnu.stud.chaosgame.model.transformations; import edu.ntnu.stud.chaosgame.model.data.Matrix2x2; import edu.ntnu.stud.chaosgame.model.data.Vector2D; -import edu.ntnu.stud.chaosgame.model.game.ChaosGameFileHandler; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGameFileHandler; /** * Represents affine transformations in a 2D-plane by extending the abstract diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/transformations/JuliaTransform.java b/src/main/java/edu/ntnu/stud/chaosgame/model/transformations/JuliaTransform.java index 909c4f9ad64fbf37357a2e044aef484e948602ac..d5ccef27706789e30c9bf34eecbeb235d51322ce 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/transformations/JuliaTransform.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/model/transformations/JuliaTransform.java @@ -2,7 +2,7 @@ package edu.ntnu.stud.chaosgame.model.transformations; import edu.ntnu.stud.chaosgame.model.data.Complex; import edu.ntnu.stud.chaosgame.model.data.Vector2D; -import edu.ntnu.stud.chaosgame.model.game.ChaosGameFileHandler; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGameFileHandler; public class JuliaTransform extends Transform2D { diff --git a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java index 0cbf217f6171dfd759053e65a8e4301ffc1d10c1..91b7b6a8bda0f468dff183bf7f23fb512d8b9e35 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java @@ -1,9 +1,9 @@ package edu.ntnu.stud.chaosgame.view; import edu.ntnu.stud.chaosgame.controller.ChaosGameButtonController; -import edu.ntnu.stud.chaosgame.model.game.ChaosCanvas; -import edu.ntnu.stud.chaosgame.model.game.ChaosGame; -import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription; +import edu.ntnu.stud.chaosgame.controller.game.ChaosCanvas; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGame; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription; import edu.ntnu.stud.chaosgame.model.generators.ChaosGameDescriptionFactory; import javafx.scene.Scene; @@ -64,7 +64,7 @@ public class ChaosGameGUIView { //TEMPORARY CODE to test Chaos Games in GUI ChaosGameDescriptionFactory factory = new ChaosGameDescriptionFactory(); - ChaosGameDescription description = factory.getDescriptions().get(1); + ChaosGameDescription description = factory.getDescriptions().get(2); ChaosCanvas canvas = new ChaosCanvas(1000, 1000, description.getMinCoords(), description.getMaxCoords()); game = new ChaosGame(description, canvas); @@ -74,7 +74,7 @@ public class ChaosGameGUIView { public void drawChaosGame(){ ChaosCanvas canvas = game.getCanvas(); - game.runSteps(100000); + game.runSteps(1000); // Test implementation for drawing fractals int[][] betaArray = canvas.getCanvasArray(); @@ -88,6 +88,7 @@ public class ChaosGameGUIView { } + } public int getWidth(){ diff --git a/src/main/resources/descriptions/factory/desc_1.txt b/src/main/resources/descriptions/factory/desc_1.txt index e98ca28363edecbfbb6f8cd7b0f4b3a80b6a3006..210beba38322c5ce1c9aed050845189b47f1e182 100644 --- a/src/main/resources/descriptions/factory/desc_1.txt +++ b/src/main/resources/descriptions/factory/desc_1.txt @@ -1,6 +1,6 @@ -Affine2D -0.0, 0.0 -1.0, 1.0 -0.5, 0.0, 0.0, 0.5, 0.0, 0.0 -0.5, 0.0, 0.0, 0.5, 0.25, 0.5 -0.5, 0.0, 0.0, 0.5, 0.5, 0.0 +Affine2D # Comment +0.0, 0.0 # Comment +1.0, 1.0 # Comment +0.5, 0.0, 0.0, 0.5, 0.0, 0.0 # Comment +0.5, 0.0, 0.0, 0.5, 0.25, 0.5 # Comment +0.5, 0.0, 0.0, 0.5, 0.5, 0.0 # Comment diff --git a/src/main/resources/descriptions/factory/desc_2.txt b/src/main/resources/descriptions/factory/desc_2.txt index 6985707d20e4faf7b2e3b0959ceccbc4ca6bd632..a925c12a55316243573e46e989bac99c16e6f75e 100644 --- a/src/main/resources/descriptions/factory/desc_2.txt +++ b/src/main/resources/descriptions/factory/desc_2.txt @@ -1,7 +1,7 @@ -Affine2D --2.65, 0 -2.65, 10 -0, 0, 0, .16, 0, 0 -.85, .04, -.04, .85, 0, 1.6 -.2, -.26, .23, .22, 0, 1.6 --.15, .28, .26, .24, 0, .44 \ No newline at end of file +Affine2D # Comment +-2.65, 0 # Comment +2.65, 10 # Comment +0, 0, 0, .16, 0, 0 # Comment +.85, .04, -.04, .85, 0, 1.6 # Comment +.2, -.26, .23, .22, 0, 1.6 # Comment +-.15, .28, .26, .24, 0, .44 # Comment \ No newline at end of file diff --git a/src/main/resources/descriptions/factory/desc_3.txt b/src/main/resources/descriptions/factory/desc_3.txt index ed3fd5ad62576dc39c8ba5fe1f30bc2780a02381..29d7802a8739a494da63e6ef614a159de708851d 100644 --- a/src/main/resources/descriptions/factory/desc_3.txt +++ b/src/main/resources/descriptions/factory/desc_3.txt @@ -1,4 +1,4 @@ -Julia --1.6, -1 -1.6, 1 --.74543, .11301 \ No newline at end of file +Julia # Comment +-1.6, -1 # Comment +1.6, 1 # Comment +-.74543, .11301 # Comment \ No newline at end of file diff --git a/src/test/java/edu/ntnu/stud/chaosgame/game/ChaosGameDescriptionTest.java b/src/test/java/edu/ntnu/stud/chaosgame/game/ChaosGameDescriptionTest.java index 027010f97991560f3ba4ff46cb8999a5500a8094..fdd360b47c2ffa60396c68901f925199a289ef82 100644 --- a/src/test/java/edu/ntnu/stud/chaosgame/game/ChaosGameDescriptionTest.java +++ b/src/test/java/edu/ntnu/stud/chaosgame/game/ChaosGameDescriptionTest.java @@ -3,7 +3,7 @@ package edu.ntnu.stud.chaosgame.game; import edu.ntnu.stud.chaosgame.model.data.Complex; import edu.ntnu.stud.chaosgame.model.data.Matrix2x2; import edu.ntnu.stud.chaosgame.model.data.Vector2D; -import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription; import edu.ntnu.stud.chaosgame.model.transformations.AffineTransform2D; import edu.ntnu.stud.chaosgame.model.transformations.JuliaTransform; import edu.ntnu.stud.chaosgame.model.transformations.Transform2D; diff --git a/src/test/java/edu/ntnu/stud/chaosgame/game/ChaosGameFileHandlerTest.java b/src/test/java/edu/ntnu/stud/chaosgame/game/ChaosGameFileHandlerTest.java index b220186db8cc94ca68f16c1780963341565a7462..e283320c491417dc7a8c614a3931016bc423655c 100644 --- a/src/test/java/edu/ntnu/stud/chaosgame/game/ChaosGameFileHandlerTest.java +++ b/src/test/java/edu/ntnu/stud/chaosgame/game/ChaosGameFileHandlerTest.java @@ -4,8 +4,8 @@ package edu.ntnu.stud.chaosgame.game; import edu.ntnu.stud.chaosgame.model.data.Complex; import edu.ntnu.stud.chaosgame.model.data.Matrix2x2; import edu.ntnu.stud.chaosgame.model.data.Vector2D; -import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription; -import edu.ntnu.stud.chaosgame.model.game.ChaosGameFileHandler; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGameFileHandler; import edu.ntnu.stud.chaosgame.model.transformations.AffineTransform2D; import edu.ntnu.stud.chaosgame.model.transformations.JuliaTransform; import edu.ntnu.stud.chaosgame.model.transformations.Transform2D; @@ -28,12 +28,12 @@ class ChaosGameFileHandlerTest { @Test void testReadFromFileAffine2D() throws IOException { String fileContent = """ - Affine2D - 0.0, 0.0 - 1.0, 1.0 - 0.5, 1.0, 1.0, 0.5, 3.0, 1.0 - 0.5, 1.0, 1.0, 0.5, 3.0, 1.0 - 0.5, 1.0, 1.0, 0.5, 3.0, 1.0 + Affine2D # Comment + 0.0, 0.0 # Comment + 1.0, 1.0 # Comment + 0.5, 1.0, 1.0, 0.5, 3.0, 1.0 # Comment + 0.5, 1.0, 1.0, 0.5, 3.0, 1.0 # Comment + 0.5, 1.0, 1.0, 0.5, 3.0, 1.0 # Comment """; Path tempFile = Files.createTempFile("test", ".txt"); @@ -44,6 +44,8 @@ class ChaosGameFileHandlerTest { Vector2D minCoords = description.getMinCoords(); Vector2D maxCoords = description.getMaxCoords(); + + assertEquals(0.0, minCoords.getX0()); assertEquals(0.0, minCoords.getX1()); assertEquals(1.0, maxCoords.getX0()); @@ -67,10 +69,10 @@ class ChaosGameFileHandlerTest { @Test void testReadFromFileJulia() throws IOException { String fileContent = """ - Julia - -1.6, -1 - 1.6, 1 - -.74543, .11301 + Julia # Comment \n + -1.6, -1 # Comment \n + 1.6, 1 # Comment \n + -.74543, .11301 # Comment """; Path tempFile = Files.createTempFile("test", ".txt");