From: Svjatoslav Agejenko Date: Thu, 23 Mar 2023 18:15:19 +0000 (+0200) Subject: Updated readability of the code. X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=d493b94b0d7840799692bbaa16754d342363e9df;p=sixth-3d.git Updated readability of the code. --- diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/texturedpolygon/PolygonBorderInterpolator.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/texturedpolygon/PolygonBorderInterpolator.java index c0ae36f..f35448d 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/texturedpolygon/PolygonBorderInterpolator.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/texturedpolygon/PolygonBorderInterpolator.java @@ -6,21 +6,24 @@ package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon; import eu.svjatoslav.sixth.e3d.geometry.Point2D; +import static java.lang.Math.abs; + public class PolygonBorderInterpolator implements Comparable { // on-screen coordinates - Point2D p1; - Point2D p2; + Point2D onScreenPoint1; + Point2D onScreenPoint2; + double distanceFromY1; - private int height; - private int width; - private int absoluteHeight; - private double twidth; - private double theight; + private int onScreenHeight; + private int onScreenWidth; + private int onscreenAbsoluteHeight; + private double textureWidth; + private double textureHeight; // texture coordinates - private Point2D tp1; - private Point2D tp2; + private Point2D texturePoint1; + private Point2D texturePoint2; @Override @@ -32,21 +35,21 @@ public class PolygonBorderInterpolator implements @Override public int hashCode() { - int result = width; - result = 31 * result + absoluteHeight; + int result = onScreenWidth; + result = 31 * result + onscreenAbsoluteHeight; return result; } @Override - public int compareTo(final PolygonBorderInterpolator o) { - if (absoluteHeight < o.absoluteHeight) + public int compareTo(final PolygonBorderInterpolator otherInterpolator) { + if (onscreenAbsoluteHeight < otherInterpolator.onscreenAbsoluteHeight) return 1; - if (absoluteHeight > o.absoluteHeight) + if (onscreenAbsoluteHeight > otherInterpolator.onscreenAbsoluteHeight) return -1; - if (width < o.width) + if (onScreenWidth < otherInterpolator.onScreenWidth) return 1; - if (width > o.width) + if (onScreenWidth > otherInterpolator.onScreenWidth) return -1; return 0; @@ -54,57 +57,57 @@ public class PolygonBorderInterpolator implements public boolean containsY(final int y) { - if (p1.y < p2.y) { - if (y >= p1.y) - return y <= p2.y; - } else if (y >= p2.y) - return y <= p1.y; + if (onScreenPoint1.y < onScreenPoint2.y) { + if (y >= onScreenPoint1.y) + return y <= onScreenPoint2.y; + } else if (y >= onScreenPoint2.y) + return y <= onScreenPoint1.y; return false; } public double getTX() { - if (height == 0) - return (tp2.x + tp1.x) / 2d; + if (onScreenHeight == 0) + return (texturePoint2.x + texturePoint1.x) / 2d; - return tp1.x + ((twidth * distanceFromY1) / height); + return texturePoint1.x + ((textureWidth * distanceFromY1) / onScreenHeight); } public double getTY() { - if (height == 0) - return (tp2.y + tp1.y) / 2d; + if (onScreenHeight == 0) + return (texturePoint2.y + texturePoint1.y) / 2d; - return tp1.y + ((theight * distanceFromY1) / height); + return texturePoint1.y + ((textureHeight * distanceFromY1) / onScreenHeight); } public int getX() { - if (height == 0) - return (int) ((p2.x + p1.x) / 2d); + if (onScreenHeight == 0) + return (int) ((onScreenPoint2.x + onScreenPoint1.x) / 2d); - return (int) (p1.x + ((width * distanceFromY1) / height)); + return (int) (onScreenPoint1.x + ((onScreenWidth * distanceFromY1) / onScreenHeight)); } public void setCurrentY(final int y) { - distanceFromY1 = y - p1.y; + distanceFromY1 = y - onScreenPoint1.y; } - public void setPoints(final Point2D p1, final Point2D p2, - final Point2D tp1, final Point2D tp2) { + public void setPoints(final Point2D onScreenPoint1, final Point2D onScreenPoint2, + final Point2D texturePoint1, final Point2D texturePoint2) { - this.p1 = p1; - this.p2 = p2; - this.tp1 = tp1; - this.tp2 = tp2; + this.onScreenPoint1 = onScreenPoint1; + this.onScreenPoint2 = onScreenPoint2; + this.texturePoint1 = texturePoint1; + this.texturePoint2 = texturePoint2; - height = (int) (p2.y - p1.y); - width = (int) (p2.x - p1.x); - absoluteHeight = Math.abs(height); + onScreenHeight = (int) (onScreenPoint2.y - onScreenPoint1.y); + onScreenWidth = (int) (onScreenPoint2.x - onScreenPoint1.x); + onscreenAbsoluteHeight = abs(onScreenHeight); - twidth = tp2.x - tp1.x; - theight = tp2.y - tp1.y; + textureWidth = texturePoint2.x - texturePoint1.x; + textureHeight = texturePoint2.y - texturePoint1.y; } }