package yi.graph.polygon.gpc;

/**
 * GPC is a wrapper class for "c" language gpc library
 * http://www.cs.man.ac.uk/aig/staff/alan/software/
 */

public class GPC {

  public final static int GPC_DIFF = 0;   // Difference
  public final static int GPC_INT = 1;    // Intersection
  public final static int GPC_XOR = 2;    // Exclusive or
  public final static int GPC_UNION = 3;  // Union

  public static native GpcPolygon gpcPolygonClip(int set_operation,
                                                 GpcPolygon subject_polygon,
                                                 GpcPolygon clip_polygon);

  public static void main(String[] args) {

    // contour 1
    GpcContour contour1 = new GpcContour(
        new double[] {1, 4, 7, 4},
        new double[] {7, 3, 5, 9}
        );

    // contour 2
    GpcContour contour2 = new GpcContour(
        new double[] {5, 6, 9, 7},
        new double[] {6, 3, 5, 8}
        );

    // the polygon
    GpcPolygon polygon = new GpcPolygon();
    polygon.holes = new int[] {1, 0};
    polygon.contours = new GpcContour[] {contour1, contour2};
    //GpcPolygon result = GPC.gpcPolygonClip(1, polygon, null);

    GpcPolygon subject = new GpcPolygon(contour1);
    GpcPolygon clip = new GpcPolygon(contour2);
    GpcPolygon result = GPC.gpcPolygonClip(GPC.GPC_DIFF, subject, clip);
    System.out.println(result);

    result = GPC.gpcPolygonClip(GPC.GPC_INT, subject, clip);
    System.out.println(result);

    result = GPC.gpcPolygonClip(GPC.GPC_UNION, subject, clip);
    System.out.println(result);
  }

  static {
    System.loadLibrary("gpc");
  }

}