From 8f38d22e5ea9e7bf0d84f825debd710b69e62be8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?H=C3=A5vard=20Daleng?=
 <142524365+MrMarHVD@users.noreply.github.com>
Date: Tue, 26 Mar 2024 13:21:11 +0100
Subject: [PATCH] Rebased magnus and havard

---
 .idea/vcs.xml                                 |   1 -
 .../transformations/AffineTransform2D.java    |   3 +
 .../transformations/ChaosCanvas.java          | 101 ++++++++++++++++++
 3 files changed, 104 insertions(+), 1 deletion(-)
 create mode 100644 src/main/java/edu/ntnu/stud/chaosgame/transformations/ChaosCanvas.java

diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 574de45..7ddfc9e 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -8,6 +8,5 @@
   </component>
   <component name="VcsDirectoryMappings">
     <mapping directory="" vcs="Git" />
-    <mapping directory="$PROJECT_DIR$/idatt2003" vcs="Git" />
   </component>
 </project>
\ No newline at end of file
diff --git a/src/main/java/edu/ntnu/stud/chaosgame/transformations/AffineTransform2D.java b/src/main/java/edu/ntnu/stud/chaosgame/transformations/AffineTransform2D.java
index a3ff094..1df2ee4 100644
--- a/src/main/java/edu/ntnu/stud/chaosgame/transformations/AffineTransform2D.java
+++ b/src/main/java/edu/ntnu/stud/chaosgame/transformations/AffineTransform2D.java
@@ -14,6 +14,9 @@ public class AffineTransform2D extends Transform2D {
      * The matrix{@link Matrix2x2} which performs the matrix-multiplication part of the affine transformation.
      */
     private Matrix2x2 matrix;
+
+
+
     /**
      * The vector{@link Vector2D} which is added as part of the affine transformation.
      */
diff --git a/src/main/java/edu/ntnu/stud/chaosgame/transformations/ChaosCanvas.java b/src/main/java/edu/ntnu/stud/chaosgame/transformations/ChaosCanvas.java
new file mode 100644
index 0000000..c0836a7
--- /dev/null
+++ b/src/main/java/edu/ntnu/stud/chaosgame/transformations/ChaosCanvas.java
@@ -0,0 +1,101 @@
+package edu.ntnu.stud.chaosgame.transformations;
+
+import edu.ntnu.stud.chaosgame.model.Matrix2x2;
+import edu.ntnu.stud.chaosgame.model.Vector2D;
+
+
+/**
+ * Class representing the canvas for the display of the chaos game.
+ */
+public class ChaosCanvas {
+
+  /**
+   * Table representing the canvas.
+   */
+  private int[][] canvas;
+
+  /**
+   * Width of the canvas
+   */
+  private int width;
+
+  /**
+   * Height of the canvas
+   */
+  private int height;
+
+  /**
+   * The minimum coordinates of the canvas.
+   */
+  private Vector2D minCoords;
+
+  /**
+   * The maximum coordinates of the canvas.
+   */
+  private Vector2D maxCoords;
+
+  /**
+   * Affine transformation for converting coordinates to canvas indices.
+   */
+  private AffineTransform2D transformCoordsToIndices;
+
+  /**
+   * Parameterized constructor for the class.
+   *
+   * @param width width of the canvas
+   * @param height height of the canvas
+   * @param minCoords minimum coordinates of the canvas
+   * @param maxCoords maximum coordinates of the canvas
+   */
+  public ChaosCanvas(int width, int height, Vector2D minCoords, Vector2D maxCoords) {
+    this.width = width;
+    this.height = height;
+    this.minCoords = minCoords;
+    this.maxCoords = maxCoords;
+
+    this.canvas = new int[width][height];
+
+    // Define the affine transformation that maps coordinates to indices in the canvas.
+    this.transformCoordsToIndices = new AffineTransform2D(
+        new Matrix2x2(0, height - 1, width - 1, 0),
+        new Vector2D((((height - 1) * maxCoords.getX0()) / maxCoords.getX1()),
+        ((width - 1) * minCoords.getX1()) / maxCoords.getX1())
+    );
+  }
+
+  /**
+   * Get a pixel located at a point.
+   *
+   * @param point point at which the pixel is located
+   * @return the pixel
+   */
+  public int getPixel(Vector2D point) {
+    return canvas[(int) transformCoordsToIndices.transform(point).getX0()]
+        [(int) transformCoordsToIndices.transform(point).getX1()];
+  }
+
+  public void putPixel(Vector2D point) {
+    canvas[(int) transformCoordsToIndices.transform(point).getX0()]
+        [(int) transformCoordsToIndices.transform(point).getX1()] = 1;
+  }
+
+  /**
+   * Get the canvas array.
+   * @return the canvas array
+   */
+  public int[][] getCanvasArray() {
+    return canvas;
+  }
+
+  /**
+   * Clear the canvas of all content.
+   */
+  public void clearCanvas() {
+    for (int i = 0; i < width; i++) {
+      for (int j = 0; j < height; j++) {
+        canvas[i][j] = 0;
+      }
+    }
+  }
+
+}
-- 
GitLab