예제 #1
0
        //------------------------------------------------------------------------------

        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;
            }
        }
예제 #2
0
        //------------------------------------------------------------------------------

        public static double Area(PolygonClp 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;
            }
        }