From de8fb260a5e99922231b1d0f437916e796ec6ccb Mon Sep 17 00:00:00 2001
From: Svjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Date: Sun, 26 Feb 2023 09:49:34 +0200
Subject: [PATCH] Improved code readability.

---
 .../sixth/e3d/gui/RenderingContext.java       | 14 ++++++----
 .../sixth/e3d/gui/UserRelativityTracker.java  | 12 ++++----
 .../{GeometryCoordinate.java => Vertex.java}  | 28 +++++++++----------
 .../shapes/AbstractCoordinateShape.java       | 14 +++++-----
 4 files changed, 34 insertions(+), 34 deletions(-)
 rename src/main/java/eu/svjatoslav/sixth/e3d/math/{GeometryCoordinate.java => Vertex.java} (67%)

diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/RenderingContext.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/RenderingContext.java
index b6417e5..ce8c4a0 100644
--- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/RenderingContext.java
+++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/RenderingContext.java
@@ -4,6 +4,7 @@
  */
 package eu.svjatoslav.sixth.e3d.gui;
 
+import eu.svjatoslav.sixth.e3d.geometry.Point2D;
 import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseEvent;
 import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController;
 
@@ -19,8 +20,12 @@ public class RenderingContext {
     public final byte[] pixels;
     public final int width;
     public final int height;
-    public final int xCenter;
-    public final int yCenter;
+    /**
+     * Center of the screen in screen space (pixels).
+     * This is the point where (0,0) coordinate of the world space is rendered.
+     */
+    public final Point2D centerCoordinate;
+
     public final double zoom;
     final BufferedImage bufferedImage;
     public int frameNumber = 0;
@@ -65,10 +70,7 @@ public class RenderingContext {
     public RenderingContext(final int width, final int height) {
         this.width = width;
         this.height = height;
-
-        this.xCenter = width / 2;
-        this.yCenter = height / 2;
-
+        this.centerCoordinate = new Point2D(width / 2d, height / 2d);
         this.zoom = width / 3d;
 
         bufferedImage = new BufferedImage(width, height, bufferedImageType);
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java
index 4ebca1a..06363ea 100644
--- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java
+++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java
@@ -5,15 +5,15 @@
 package eu.svjatoslav.sixth.e3d.gui;
 
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate;
+import eu.svjatoslav.sixth.e3d.math.Vertex;
 import eu.svjatoslav.sixth.e3d.math.TransformsPipeline;
 
 public class UserRelativityTracker {
 
     private final static int minimalSliceFactor = 5;
-    public GeometryCoordinate center = new GeometryCoordinate();
-    public GeometryCoordinate right;
-    public GeometryCoordinate down;
+    public Vertex center = new Vertex();
+    public Vertex right;
+    public Vertex down;
 
     public UserRelativityTracker() {
 
@@ -31,8 +31,8 @@ public class UserRelativityTracker {
     }
 
     public void enableOrientationTracking() {
-        right = new GeometryCoordinate(new Point3D(10, 0, 0));
-        down = new GeometryCoordinate(new Point3D(0, 10, 0));
+        right = new Vertex(new Point3D(10, 0, 0));
+        down = new Vertex(new Point3D(0, 10, 0));
     }
 
     public double getAngleXY() {
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/math/GeometryCoordinate.java b/src/main/java/eu/svjatoslav/sixth/e3d/math/Vertex.java
similarity index 67%
rename from src/main/java/eu/svjatoslav/sixth/e3d/math/GeometryCoordinate.java
rename to src/main/java/eu/svjatoslav/sixth/e3d/math/Vertex.java
index af3d3d3..0c77868 100644
--- a/src/main/java/eu/svjatoslav/sixth/e3d/math/GeometryCoordinate.java
+++ b/src/main/java/eu/svjatoslav/sixth/e3d/math/Vertex.java
@@ -9,34 +9,35 @@ import eu.svjatoslav.sixth.e3d.geometry.Point3D;
 import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
 
 /**
- * A point in 3D space with a transformed and on-screen coordinates.
+ * It is used to store coordinates of vertices of 3D objects.
+ * It is also used to store coordinates of points in 3D space.
  */
-public class GeometryCoordinate {
+public class Vertex {
 
     /**
-     * The original coordinate.
+     * Vertex coordinate in 3D space.
      */
     public Point3D coordinate;
 
     /**
-     * The transformed coordinate.
+     * Vertex coordinate relative to the viewer after transformation.
      */
     public Point3D transformedCoordinate;
 
     /**
-     * The on-screen coordinate.
+     * Vertex coordinate on screen after transformation.
      */
     public Point2D onScreenCoordinate;
 
     private int lastTransformedFrame;
 
-    public GeometryCoordinate() {
+    public Vertex() {
         coordinate = new Point3D();
         transformedCoordinate = new Point3D();
         onScreenCoordinate = new Point2D();
     }
 
-    public GeometryCoordinate(final Point3D location) {
+    public Vertex(final Point3D location) {
         coordinate = location;
         transformedCoordinate = new Point3D();
         onScreenCoordinate = new Point2D();
@@ -45,10 +46,8 @@ public class GeometryCoordinate {
     /**
      * Transforms the coordinate.
      *
-     * @param transforms
-     *            The transform pipe.
-     * @param renderContext
-     *            The rendering context.
+     * @param transforms The transforms pipeline.
+     * @param renderContext The rendering context.
      */
     public void transform(final TransformsPipeline transforms,
                           final RenderingContext renderContext) {
@@ -60,9 +59,8 @@ public class GeometryCoordinate {
 
         transforms.transform(coordinate, transformedCoordinate);
 
-        onScreenCoordinate.x = ((transformedCoordinate.x / transformedCoordinate.z) * renderContext.zoom)
-                + renderContext.xCenter;
-        onScreenCoordinate.y = ((transformedCoordinate.y / transformedCoordinate.z) * renderContext.zoom)
-                + renderContext.yCenter;
+        onScreenCoordinate.x = ((transformedCoordinate.x / transformedCoordinate.z) * renderContext.zoom);
+        onScreenCoordinate.y = ((transformedCoordinate.y / transformedCoordinate.z) * renderContext.zoom);
+        onScreenCoordinate.add(renderContext.centerCoordinate);
     }
 }
diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractCoordinateShape.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractCoordinateShape.java
index 649e546..f2fdde0 100644
--- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractCoordinateShape.java
+++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/AbstractCoordinateShape.java
@@ -6,7 +6,7 @@ package eu.svjatoslav.sixth.e3d.renderer.raster.shapes;
 
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
 import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
-import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate;
+import eu.svjatoslav.sixth.e3d.math.Vertex;
 import eu.svjatoslav.sixth.e3d.math.TransformsPipeline;
 import eu.svjatoslav.sixth.e3d.renderer.raster.RenderAggregator;
 
@@ -16,22 +16,22 @@ public abstract class AbstractCoordinateShape extends AbstractShape {
 
     private static final AtomicInteger lastShapeId = new AtomicInteger();
     public final int shapeId;
-    public final GeometryCoordinate[] coordinates;
+    public final Vertex[] coordinates;
     public double onScreenZ;
 
     public AbstractCoordinateShape(final int pointsCount) {
-        coordinates = new GeometryCoordinate[pointsCount];
+        coordinates = new Vertex[pointsCount];
         for (int i = 0; i < pointsCount; i++)
-            coordinates[i] = new GeometryCoordinate();
+            coordinates[i] = new Vertex();
 
         shapeId = lastShapeId.getAndIncrement();
     }
 
     public AbstractCoordinateShape(final Point3D... vertexes) {
-        coordinates = new GeometryCoordinate[vertexes.length];
+        coordinates = new Vertex[vertexes.length];
 
         for (int i = 0; i < vertexes.length; i++)
-            coordinates[i] = new GeometryCoordinate(vertexes[i]);
+            coordinates[i] = new Vertex(vertexes[i]);
 
         shapeId = lastShapeId.getAndIncrement();
     }
@@ -50,7 +50,7 @@ public abstract class AbstractCoordinateShape extends AbstractShape {
         double accumulatedZ = 0;
         boolean paint = true;
 
-        for (final GeometryCoordinate geometryPoint : coordinates) {
+        for (final Vertex geometryPoint : coordinates) {
             geometryPoint.transform(transforms, renderingContext);
 
             accumulatedZ += geometryPoint.transformedCoordinate.z;
-- 
2.20.1