//------------------------------------------------------------------------------ double Area(OutRec outRec, bool UseFull64BitRange) { OutPt op = outRec.pts; if (op == null) return 0; if (UseFull64BitRange) { Int128 a = new Int128(0); do { a += Int128.Int128Mul(op.pt.X + op.prev.pt.X, op.prev.pt.Y - op.pt.Y); op = op.next; } while (op != outRec.pts); return a.ToDouble() / 2; } else { double a = 0; do { a = a + (op.pt.X + op.prev.pt.X) * (op.prev.pt.Y - op.pt.Y); op = op.next; } while (op != outRec.pts); return a/2; } }
//------------------------------------------------------------------------------ public static double Area(Polygon poly) { int highI = poly.Count - 1; if (highI < 2) return 0; bool UseFullInt64Range = false; RangeTest rt = TestRange(poly); switch (rt) { case RangeTest.rtHi: UseFullInt64Range = true; break; case RangeTest.rtError: throw new ClipperException("Coordinate exceeds range bounds."); } if (UseFullInt64Range) { Int128 a = new Int128(0); a = Int128.Int128Mul(poly[highI].X, poly[0].Y) - Int128.Int128Mul(poly[0].X, poly[highI].Y); for (int i = 0; i < highI; ++i) a += Int128.Int128Mul(poly[i].X, poly[i + 1].Y) - Int128.Int128Mul(poly[i + 1].X, poly[i].Y); return a.ToDouble() / 2; } else { double area = (double)poly[highI].X * (double)poly[0].Y - (double)poly[0].X * (double)poly[highI].Y; for (int i = 0; i < highI; ++i) area += (double)poly[i].X * (double)poly[i + 1].Y - (double)poly[i + 1].X * (double)poly[i].Y; return area / 2; } }
//------------------------------------------------------------------------------ public static double Area(Polygon poly) { int highI = poly.Count - 1; if (highI < 2) return 0; if (FullRangeNeeded(poly)) { Int128 a = new Int128(0); a = Int128.Int128Mul(poly[highI].X + poly[0].X, poly[0].Y - poly[highI].Y); for (int i = 1; i <= highI; ++i) a += Int128.Int128Mul(poly[i - 1].X + poly[i].X, poly[i].Y - poly[i - 1].Y); return a.ToDouble() / 2; } else { double area = ((double)poly[highI].X + poly[0].X) * ((double)poly[0].Y - poly[highI].Y); for (int i = 1; i <= highI; ++i) area += ((double)poly[i - 1].X + poly[i].X) * ((double)poly[i].Y - poly[i -1].Y); return area / 2; } }