Updated copyright info
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / slicer / BorderLine.java
1 /*
2  * Sixth 3D engine. Copyright ©2012-2020, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
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.
7  *
8  */
9
10 package eu.svjatoslav.sixth.e3d.renderer.raster.slicer;
11
12 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
13 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
14
15 import java.util.Comparator;
16
17 public class BorderLine implements Comparator<BorderLine> {
18
19     public final int count;
20     final PolygonCoordinate c1;
21     final PolygonCoordinate c2;
22
23     public BorderLine(final PolygonCoordinate c1, final PolygonCoordinate c2,
24                       final int count) {
25         this.c1 = c1;
26         this.c2 = c2;
27         this.count = count;
28     }
29
30     @Override
31     public int compare(final BorderLine o1, final BorderLine o2) {
32         return Double.compare(o1.getLength(), o2.getLength());
33     }
34
35     public double getLength() {
36         return c1.space.getDistanceTo(c2.space);
37     }
38
39     public PolygonCoordinate getMiddlePoint() {
40         return new PolygonCoordinate(new Point3D().computeMiddlePoint(c1.space,
41                 c2.space), new Point2D().getMiddle(c1.texture,
42                 c2.texture));
43     }
44 }