From 7c33efc8d84b5d13890975b3c3428fce6244a610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Daleng?= <142524365+MrMarHVD@users.noreply.github.com> Date: Mon, 20 May 2024 12:14:19 +0200 Subject: [PATCH] Preparing to pull. --- .../chaosgame/controller/game/ChaosGame.java | 10 +---- .../chaosgame/model/game/ChaosCanvas.java | 8 ++-- .../model/transformations/JuliaTransform.java | 45 +++++++++---------- .../chaosgame/view/ChaosGameImageView.java | 4 +- 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGame.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGame.java index 2c6366a..e910e17 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGame.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGame.java @@ -171,11 +171,6 @@ public class ChaosGame { for (int i = 0; i < n; i++) { int j = this.random.nextInt( this.numOfTransforms); - - //System.out.println(j); - //System.out.println(this.description.getTransforms().size()); - - //System.out.println("Before transform: " + currentPoint.getX0() + " " + currentPoint.getX1()); Vector2D newPoint = this.description.getTransforms().get(j).transform(currentPoint); this.currentPoint = this.findValidPoint(newPoint); @@ -185,14 +180,13 @@ public class ChaosGame { } /** - * If the point is out of bounds, iterate until it is within bounds. Used - * if the useColor boolean is set to false. + * If the point is out of bounds, iterate until it is within bounds. * * @param point the starting point. * @return the resulting valid point within bounds. */ public Vector2D findValidPoint(Vector2D point) { - if (!this.canvas.isPointInCanvasRange(point) || this.canvas.getPixel(point) == 1) { + if (!this.canvas.isPointInCanvasRange(point)) { while (!this.canvas.isPointInCanvasRange(point)) { int j = this.random.nextInt(this.numOfTransforms); System.out.println("Before transform: " + point.getX0() + " " + point.getX1()); // Test diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosCanvas.java b/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosCanvas.java index bb5094e..e344c15 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosCanvas.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosCanvas.java @@ -71,10 +71,10 @@ public class ChaosCanvas { // Convert the coordinates to indices in the canvas this.transformCoordsToIndices = new AffineTransform2D( - new Matrix2x2(0, (height-1) / (minCoords.getX1() - maxCoords.getX1()), - (width-1) / (maxCoords.getX0() - minCoords.getX0()), 0), - new Vector2D(((height-1)* maxCoords.getX1()) / (maxCoords.getX1() - minCoords.getX1()), - (width-1)* minCoords.getX0() / (minCoords.getX0() - maxCoords.getX0()))); + new Matrix2x2(0, (height-1) / (minCoords.getX1() - maxCoords.getX1()), + (width-1) / (maxCoords.getX0() - minCoords.getX0()), 0), + new Vector2D(((height-1)* maxCoords.getX1()) / (maxCoords.getX1() - minCoords.getX1()), + (width-1)* minCoords.getX0() / (minCoords.getX0() - maxCoords.getX0()))); } /** 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 9bd740d..3dc2996 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 @@ -23,8 +23,8 @@ public class JuliaTransform extends Transform2D { * @param sign An integer which determines if c1 is added or subtracted in the transformation. */ public JuliaTransform(Complex point,int sign) { - this.c1 = point; - this.sign = sign; + this.c1 = point; + this.sign = sign; } @@ -37,31 +37,28 @@ public class JuliaTransform extends Transform2D { * @return The transformed point, represented by a vector {@link Vector2D} */ public Vector2D transform(Vector2D point){ - if (point == null) { - throw new IllegalArgumentException("Point should not be null"); - } - Vector2D temp1; + if (point == null) { + throw new IllegalArgumentException("Point should not be null"); + } + Vector2D temp1; - if (sign > 0){ + if (sign > 0){ + temp1 = point.subtract(c1); + return new Complex(temp1.getX0(), temp1.getX1()).sqrt(); + } + else if (sign < 0){ temp1 = point.subtract(c1); - Complex sqrtResult = new Complex(temp1.getX0(), temp1.getX1()).sqrt(); - return sqrtResult; - } - else if (sign < 0){ - temp1 = point.subtract(c1); - Complex sqrtResult = new Complex(temp1.getX0(), temp1.getX1()).sqrt(); - sqrtResult = new Complex(-sqrtResult.getX0(),-sqrtResult.getX1()); - return sqrtResult; - - } else { - // Maybe replace with logger based on SolarLint - System.out.println("Sign is zero. No transformation performed"); - return new Complex(point.getX0(),point.getX1()); - } - //Complex sqrtResult = new Complex(temp1.getX0(), temp1.getX1()).sqrt(); - //System.out.println("Input to sqrt: " + temp1.getX0() + temp1.getX1() + ", Output: " + sqrtResult.getX0() + sqrtResult.getX1()); // Debug line - + Complex sqrtResult = new Complex(temp1.getX0(), temp1.getX1()).sqrt(); + sqrtResult = new Complex(-sqrtResult.getX0(),-sqrtResult.getX1()); + return sqrtResult; + } else { + // Maybe replace with logger based on SolarLint + System.out.println("Sign is zero. No transformation performed"); + return new Complex(point.getX0(),point.getX1()); + } + //Complex sqrtResult = new Complex(temp1.getX0(), temp1.getX1()).sqrt(); + //System.out.println("Input to sqrt: " + temp1.getX0() + temp1.getX1() + ", Output: " + sqrtResult.getX0() + sqrtResult.getX1()); // Debug line } diff --git a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameImageView.java b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameImageView.java index bdc3d28..579b7c6 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameImageView.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameImageView.java @@ -50,7 +50,7 @@ public class ChaosGameImageView extends ImageView { * @param controller the GUI which controls this image view. */ public ChaosGameImageView(ChaosGameGui controller) { - this.setOnScroll(this::userZoom); + this.setOnScroll(this::affineZoom); this.setOnMousePressed(this::mousePressed); this.setOnMouseDragged(this::mouseDragged); //this.setOnMouseReleased(this::mouseReleased); @@ -74,7 +74,7 @@ public class ChaosGameImageView extends ImageView { * * @param event the event. */ - private synchronized void userZoom(ScrollEvent event) { + private synchronized void affineZoom(ScrollEvent event) { double newZoomFactor = event.getDeltaY() > 0 ? 1.05 : 1 / 1.05; try { // Get the old values -- GitLab