import java.util.*; public class Borders { public static final int MAXEDGES = 200; public static final int MAXBORDERS = 20; public static final long[] perims = new long[MAXBORDERS+1]; public static final long[] areas = new long[MAXBORDERS+1]; public static boolean between(int a, int b, int c) { if (a>=b && a <=c) return true; else return (a<=b && a>=c); } public static long calcPerim(Border border) { long perim=0; for(int i=0; i cy1 && e.y1 < cy2); boolean y2in = (e.y2 > cy1 && e.y2 < cy2); if (x1in==0 && x2in==0 && y1in && y2in) { // inside prev border e.clipped = true; return true; } else if (!y1in || !y2in) { // no need to clip return false; } else if (x1in*x2in < 0) { // break into two pieces if (e.x1 < e.x2) { elist.e[elist.numE++].set(cx2, e.x2, e.y1, e.y2, d); e.x2 = cx1; } else { elist.e[elist.numE++].set(cx1, e.x2, e.y1, e.y2, d); e.x2 = cx2; } return false; } else if (x1in == 0) { if (e.x1 < e.x2) e.x1 = cx2; else e.x1 = cx1; } else if (x2in == 0) { if (e.x2 < e.x1) e.x2 = cx2; else e.x2 = cx1; } return false; } public static boolean clipVert(Edge e, BPiece elist, int d, int cx1, int cy1, int cx2, int cy2) { boolean x1in = (e.x1 > cx1 && e.x1 < cx2); boolean x2in = (e.x2 > cx1 && e.x2 < cx2); int y1in = (e.y1 < cy1 ? -1 : e.y1 <= cy2 ? 0 : 1); int y2in = (e.y2 < cy1 ? -1 : e.y2 <= cy2 ? 0 : 1); if (x1in && x2in && y1in==0 && y2in==0) { // inside prev border e.clipped = true; return true; } else if (!x1in || !x2in) { // no need to clip return false; } else if (y1in*y2in<0) { // break into two pieces if (e.y1 < e.y2) { elist.e[elist.numE++].set(e.x1, e.x2, cy2, e.y2, d); e.y2 = cy1; } else { elist.e[elist.numE++].set(e.x1, e.x2, cy1, e.y2, d); e.y2 = cy2; } return false; } else if (y1in==0) { if (e.y1 < e.y2) e.y1 = cy2; else e.y1 = cy1; } else if (y2in==0) { if (e.y2 < e.y1) e.y2 = cy2; else e.y2 = cy1; } return false; } public static BPiece clip(Edge e, int genPiece, int genEdge, Border bdr, int d) { BPiece ans = new BPiece(); boolean clipped = false; ans.e[0] = e; ans.numE = 1; for(int i=0; i