Fixed git clone URL
[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 package eu.svjatoslav.sixth.e3d.renderer.raster.slicer;
6
7 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
8 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
9 import eu.svjatoslav.sixth.e3d.math.Vertex;
10
11 import java.util.Comparator;
12
13 public class BorderLine implements Comparator<BorderLine> {
14
15     public final int count;
16     final Vertex c1;
17     final Vertex c2;
18
19     public BorderLine(final Vertex c1, final Vertex c2,
20                       final int count) {
21         this.c1 = c1;
22         this.c2 = c2;
23         this.count = count;
24     }
25
26     @Override
27     public int compare(final BorderLine o1, final BorderLine o2) {
28         return Double.compare(o1.getLength(), o2.getLength());
29     }
30
31     public double getLength() {
32         return c1.coordinate.getDistanceTo(c2.coordinate);
33     }
34
35     public Vertex getMiddlePoint() {
36         return new Vertex(
37                 new Point3D().computeMiddlePoint(c1.coordinate, c2.coordinate),
38                 new Point2D().setToMiddle(c1.textureCoordinate, c2.textureCoordinate));
39     }
40 }