2 * Sixth 3D engine. Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public License
6 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon;
12 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
14 public class PolygonBorderInterpolator implements
15 Comparable<PolygonBorderInterpolator> {
17 // on-screen coordinates
20 double distanceFromY1;
23 private int absoluteHeight;
24 private double twidth;
25 private double theight;
26 // texture coordinates
32 public boolean equals(final Object o) {
33 if (o == null) return false;
35 return o instanceof PolygonBorderInterpolator && compareTo((PolygonBorderInterpolator) o) == 0;
39 public int hashCode() {
41 result = 31 * result + absoluteHeight;
46 public int compareTo(final PolygonBorderInterpolator o) {
47 if (absoluteHeight < o.absoluteHeight)
49 if (absoluteHeight > o.absoluteHeight)
60 public boolean containsY(final int y) {
73 public double getTX() {
76 return (tp2.x + tp1.x) / 2d;
78 return tp1.x + ((twidth * distanceFromY1) / height);
81 public double getTY() {
84 return (tp2.y + tp1.y) / 2d;
86 return tp1.y + ((theight * distanceFromY1) / height);
92 return (int) ((p2.x + p1.x) / 2d);
94 return (int) (p1.x + ((width * distanceFromY1) / height));
97 public void setCurrentY(final int y) {
98 distanceFromY1 = y - p1.y;
101 public void setPoints(final Point2D p1, final Point2D p2,
102 final Point2D tp1, final Point2D tp2) {
109 height = (int) (p2.y - p1.y);
110 width = (int) (p2.x - p1.x);
111 absoluteHeight = Math.abs(height);
113 twidth = tp2.x - tp1.x;
114 theight = tp2.y - tp1.y;