Fixed git clone URL
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / slicer / Slicer.java
index 1d70a49..b79dc0d 100644 (file)
@@ -1,38 +1,45 @@
 /*
- * Sixth 3D engine. Copyright ©2012-2020, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- *
+ * Sixth 3D engine. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
  */
-
 package eu.svjatoslav.sixth.e3d.renderer.raster.slicer;
 
+import eu.svjatoslav.sixth.e3d.math.Vertex;
 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon.TexturedPolygon;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
+import static java.util.Arrays.sort;
+
 public class Slicer {
 
+    /**
+     * Maximum distance between two points.
+     * If the distance is greater than this value, the polygon will be sliced.
+     * Otherwise, it will be added to the result.
+     */
     private final double maxDistance;
+
+    /**
+     * Result of slicing.
+     */
     private final List<TexturedPolygon> result = new ArrayList<>();
 
     public Slicer(final double maxDistance) {
         this.maxDistance = maxDistance;
     }
 
-    private void considerSlicing(final PolygonCoordinate c1,
-                                 final PolygonCoordinate c2, final PolygonCoordinate c3,
+    private void considerSlicing(final Vertex c1,
+                                 final Vertex c2,
+                                 final Vertex c3,
                                  final TexturedPolygon originalPolygon) {
 
-        final BorderLine lines[] = new BorderLine[]{
+        final BorderLine[] lines = new BorderLine[]{
                 new BorderLine(c1, c2, 1), new BorderLine(c2, c3, 2),
                 new BorderLine(c3, c1, 3)};
 
-        Arrays.sort(lines, lines[0]);
+        sort(lines, lines[0]);
 
         final BorderLine longestLine = lines[2];
 
@@ -46,7 +53,7 @@ public class Slicer {
             return;
         }
 
-        final PolygonCoordinate middle = longestLine.getMiddlePoint();
+        final Vertex middle = longestLine.getMiddlePoint();
 
         switch (longestLine.count) {
             case 1:
@@ -70,19 +77,11 @@ public class Slicer {
 
     public void slice(final TexturedPolygon originalPolygon) {
 
-        final PolygonCoordinate pc1 = new PolygonCoordinate(
-                originalPolygon.coordinates[0].coordinate,
-                originalPolygon.texturePoint1);
-
-        final PolygonCoordinate pc2 = new PolygonCoordinate(
-                originalPolygon.coordinates[1].coordinate,
-                originalPolygon.texturePoint2);
-
-        final PolygonCoordinate pc3 = new PolygonCoordinate(
-                originalPolygon.coordinates[2].coordinate,
-                originalPolygon.texturePoint3);
-
-        considerSlicing(pc1, pc2, pc3, originalPolygon);
+        considerSlicing(
+                originalPolygon.coordinates[0],
+                originalPolygon.coordinates[1],
+                originalPolygon.coordinates[2],
+                originalPolygon);
     }
 
 }