Changed license to Creative Commons Zero (CC0).
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / slicer / BorderLine.java
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko. 
3  * This project is released under Creative Commons Zero (CC0) license.
4  *
5 *
6  */
7
8 package eu.svjatoslav.sixth.e3d.renderer.raster.slicer;
9
10 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
11 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
12
13 import java.util.Comparator;
14
15 public class BorderLine implements Comparator<BorderLine> {
16
17     public final int count;
18     final PolygonCoordinate c1;
19     final PolygonCoordinate c2;
20
21     public BorderLine(final PolygonCoordinate c1, final PolygonCoordinate c2,
22                       final int count) {
23         this.c1 = c1;
24         this.c2 = c2;
25         this.count = count;
26     }
27
28     @Override
29     public int compare(final BorderLine o1, final BorderLine o2) {
30         return Double.compare(o1.getLength(), o2.getLength());
31     }
32
33     public double getLength() {
34         return c1.space.getDistanceTo(c2.space);
35     }
36
37     public PolygonCoordinate getMiddlePoint() {
38         return new PolygonCoordinate(new Point3D().computeMiddlePoint(c1.space,
39                 c2.space), new Point2D().getMiddle(c1.texture,
40                 c2.texture));
41     }
42 }