2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon;
7 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
9 public class PolygonBorderInterpolator implements
10 Comparable<PolygonBorderInterpolator> {
12 // on-screen coordinates
15 double distanceFromY1;
18 private int absoluteHeight;
19 private double twidth;
20 private double theight;
21 // texture coordinates
27 public boolean equals(final Object o) {
28 if (o == null) return false;
30 return o instanceof PolygonBorderInterpolator && compareTo((PolygonBorderInterpolator) o) == 0;
34 public int hashCode() {
36 result = 31 * result + absoluteHeight;
41 public int compareTo(final PolygonBorderInterpolator o) {
42 if (absoluteHeight < o.absoluteHeight)
44 if (absoluteHeight > o.absoluteHeight)
55 public boolean containsY(final int y) {
68 public double getTX() {
71 return (tp2.x + tp1.x) / 2d;
73 return tp1.x + ((twidth * distanceFromY1) / height);
76 public double getTY() {
79 return (tp2.y + tp1.y) / 2d;
81 return tp1.y + ((theight * distanceFromY1) / height);
87 return (int) ((p2.x + p1.x) / 2d);
89 return (int) (p1.x + ((width * distanceFromY1) / height));
92 public void setCurrentY(final int y) {
93 distanceFromY1 = y - p1.y;
96 public void setPoints(final Point2D p1, final Point2D p2,
97 final Point2D tp1, final Point2D tp2) {
104 height = (int) (p2.y - p1.y);
105 width = (int) (p2.x - p1.x);
106 absoluteHeight = Math.abs(height);
108 twidth = tp2.x - tp1.x;
109 theight = tp2.y - tp1.y;