2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
8 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon;
10 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
12 public class PolygonBorderInterpolator implements
13 Comparable<PolygonBorderInterpolator> {
15 // on-screen coordinates
18 double distanceFromY1;
21 private int absoluteHeight;
22 private double twidth;
23 private double theight;
24 // texture coordinates
30 public boolean equals(final Object o) {
31 if (o == null) return false;
33 return o instanceof PolygonBorderInterpolator && compareTo((PolygonBorderInterpolator) o) == 0;
37 public int hashCode() {
39 result = 31 * result + absoluteHeight;
44 public int compareTo(final PolygonBorderInterpolator o) {
45 if (absoluteHeight < o.absoluteHeight)
47 if (absoluteHeight > o.absoluteHeight)
58 public boolean containsY(final int y) {
71 public double getTX() {
74 return (tp2.x + tp1.x) / 2d;
76 return tp1.x + ((twidth * distanceFromY1) / height);
79 public double getTY() {
82 return (tp2.y + tp1.y) / 2d;
84 return tp1.y + ((theight * distanceFromY1) / height);
90 return (int) ((p2.x + p1.x) / 2d);
92 return (int) (p1.x + ((width * distanceFromY1) / height));
95 public void setCurrentY(final int y) {
96 distanceFromY1 = y - p1.y;
99 public void setPoints(final Point2D p1, final Point2D p2,
100 final Point2D tp1, final Point2D tp2) {
107 height = (int) (p2.y - p1.y);
108 width = (int) (p2.x - p1.x);
109 absoluteHeight = Math.abs(height);
111 twidth = tp2.x - tp1.x;
112 theight = tp2.y - tp1.y;