Class Earcut

java.lang.Object
org.maplibre.earcut4j.Earcut

public final class Earcut extends Object
  • Method Details

    • earcut

      public static List<Integer> earcut(double[] data)
      Triangulates the given polygon
      Parameters:
      data - is a flat array of vertice coordinates like [x0,y0, x1,y1, x2,y2, ...].
      Returns:
      List containing groups of three vertice indices in the resulting array forms a triangle.
    • earcut

      public static List<Integer> earcut(double[] data, int[] holeIndices, int dim)
      Triangulates the given polygon
      Parameters:
      data - is a flat array of vertice coordinates like [x0,y0, x1,y1, x2,y2, ...].
      holeIndices - is an array of hole indices if any (e.g. [5, 8] for a 12-vertice input would mean one hole with vertices 5-7 and another with 8-11).
      dim - is the number of coordinates per vertice in the input array
      Returns:
      List containing groups of three vertice indices in the resulting array forms a triangle.
    • deviation

      public static double deviation(double[] data, int[] holeIndices, int dim, List<Integer> triangles)
      Calculates the relative difference between the total area of triangles and the area of the input polygon. 0 means the triangulation is fully correct.
      Parameters:
      data - is a flat array of vertex coordinates like [x0,y0, x1,y1, x2,y2, ...].
      holeIndices - is an array of hole indices if any.
      dim - is the number of coordinates per vertex in the input array.
      triangles - is the triangulation result from earcut.
      Returns:
      the relative difference between triangle area and polygon area.