From: Svjatoslav Agejenko Date: Tue, 20 Jun 2023 21:45:13 +0000 (+0300) Subject: Improved code readability X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=77e87370474822855924c2650fcccf61cb41a05f;p=sixth-3d.git Improved code readability --- diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/texturedpolygon/TexturedPolygon.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/texturedpolygon/TexturedPolygon.java index 972f6bb..0f40895 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/texturedpolygon/TexturedPolygon.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/texturedpolygon/TexturedPolygon.java @@ -51,8 +51,8 @@ public class TexturedPolygon extends AbstractCoordinateShape { final PolygonCoordinate pc2, final PolygonCoordinate pc3, final Texture texture) { - this(pc1.space, pc2.space, pc3.space, pc1.texture, pc2.texture, - pc3.texture, texture); + this(pc1.spaceCoordinate, pc2.spaceCoordinate, pc3.spaceCoordinate, pc1.textureCoordinate, pc2.textureCoordinate, + pc3.textureCoordinate, texture); } private void computeTotalTextureDistance() { diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/slicer/BorderLine.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/slicer/BorderLine.java index 6f28c36..aebf479 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/slicer/BorderLine.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/slicer/BorderLine.java @@ -28,12 +28,12 @@ public class BorderLine implements Comparator { } public double getLength() { - return c1.space.getDistanceTo(c2.space); + return c1.spaceCoordinate.getDistanceTo(c2.spaceCoordinate); } public PolygonCoordinate getMiddlePoint() { - return new PolygonCoordinate(new Point3D().computeMiddlePoint(c1.space, - c2.space), new Point2D().setToMiddle(c1.texture, - c2.texture)); + return new PolygonCoordinate(new Point3D().computeMiddlePoint(c1.spaceCoordinate, + c2.spaceCoordinate), new Point2D().setToMiddle(c1.textureCoordinate, + c2.textureCoordinate)); } } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/slicer/PolygonCoordinate.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/slicer/PolygonCoordinate.java index eca9afc..328896d 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/slicer/PolygonCoordinate.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/slicer/PolygonCoordinate.java @@ -7,14 +7,26 @@ package eu.svjatoslav.sixth.e3d.renderer.raster.slicer; import eu.svjatoslav.sixth.e3d.geometry.Point2D; import eu.svjatoslav.sixth.e3d.geometry.Point3D; +/** + * Polygon coordinate. + * This class is used to store coordinates of a point in 3D space and its + * texture coordinate. + */ public class PolygonCoordinate { - public Point3D space; - public Point2D texture; + /** + * Space coordinate of the point. + */ + public Point3D spaceCoordinate; + + /** + * Texture coordinate of the point. + */ + public Point2D textureCoordinate; - public PolygonCoordinate(final Point3D space, final Point2D texture) { - this.space = space; - this.texture = texture; + public PolygonCoordinate(final Point3D spaceCoordinate, final Point2D textureCoordinate) { + this.spaceCoordinate = spaceCoordinate; + this.textureCoordinate = textureCoordinate; } } diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/slicer/Slicer.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/slicer/Slicer.java index 73c9abf..183ea40 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/slicer/Slicer.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/slicer/Slicer.java @@ -7,12 +7,22 @@ package eu.svjatoslav.sixth.e3d.renderer.raster.slicer; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon.TexturedPolygon; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import static java.util.Arrays.sort; + public class Slicer { + /** + * Maximum distance between two points. + * If the distance is greater than this value, the polygon will be sliced. + * Otherwise, it will be added to the result. + */ private final double maxDistance; + + /** + * Result of slicing. + */ private final List result = new ArrayList<>(); public Slicer(final double maxDistance) { @@ -20,14 +30,15 @@ public class Slicer { } private void considerSlicing(final PolygonCoordinate c1, - final PolygonCoordinate c2, final PolygonCoordinate c3, + final PolygonCoordinate c2, + final PolygonCoordinate c3, final TexturedPolygon originalPolygon) { final BorderLine[] lines = new BorderLine[]{ new BorderLine(c1, c2, 1), new BorderLine(c2, c3, 2), new BorderLine(c3, c1, 3)}; - Arrays.sort(lines, lines[0]); + sort(lines, lines[0]); final BorderLine longestLine = lines[2];