// This macro uses the formula
//
//    A = (x1y2-x2y1 + x2y3-x3y2 + ... + xny1-x1yn)/2
//
// to calculate the area of the current polygonal 
// selection and compares that value to the area 
// calculated by the Measure command.

     getSelectionCoordinates(x, y);
     n =x.length;
     area1 = 0;
     for (i=1; i<n; i++)
         area1 += x[i-1]*y[i] - x[i]*y[i-1];
     area1 += x[n-1]*y[0] - x[0]*y[n-1];
     area1 /= 2;
     if (area1<0) area1 = -area1;

     run("Measure");
     area2 = getResult("Area", nResults-1);

     print(area1 + "  " + area2 + "  " + ((area1-area2)*100/area1) + "%");


