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) {
66 public double getTX() {
69 return (tp2.x + tp1.x) / 2d;
71 return tp1.x + ((twidth * distanceFromY1) / height);
74 public double getTY() {
77 return (tp2.y + tp1.y) / 2d;
79 return tp1.y + ((theight * distanceFromY1) / height);
85 return (int) ((p2.x + p1.x) / 2d);
87 return (int) (p1.x + ((width * distanceFromY1) / height));
90 public void setCurrentY(final int y) {
91 distanceFromY1 = y - p1.y;
94 public void setPoints(final Point2D p1, final Point2D p2,
95 final Point2D tp1, final Point2D tp2) {
102 height = (int) (p2.y - p1.y);
103 width = (int) (p2.x - p1.x);
104 absoluteHeight = Math.abs(height);
106 twidth = tp2.x - tp1.x;
107 theight = tp2.y - tp1.y;