Пример #1
0
        public void TestComplexAreaAlgorithmWithComplexPolygonNoBufferOverrun()
        {
            // the complex area algorithm is very low resolution compared to simple area, so the error magnitude is higher
            const int side     = 1000;
            const int expected = side * side / 2;

            PointF[] data = new PointF[5];
            data[0] = new PointF(0, 0);
            data[1] = new PointF(side, 0);
            data[2] = new PointF(0, side);
            data[3] = new PointF(side, side);
            data[4] = new PointF(side / 2f, side / 2f);

            PolygonF.TestVertexNormalization(data);

            RectangleF bounding = RectangleUtilities.ComputeBoundingRectangle(data);

            // test for a possible buffer overrun in the computation
            foreach (PointF garbagePoint in SimulatedBufferOverrunPoints)
            {
                data[data.Length - 1] = garbagePoint;
                unsafe
                {
                    fixed(PointF *points = data)
                    {
                        // inside PolygonF, the vertexCount is always exactly the expected array length
                        // which is 4 (the 5th point simulates garbage data beyond the array)
                        double result = PolygonF.TestComplexAreaComputation(bounding, points, data.Length - 1);

                        Trace.WriteLine(string.Format("Complex Area: Expected {0:f5} Got {1:f5}", expected, result), "UNIT_TESTS");
                        Assert.IsTrue(Math.Abs(expected - result) < expected / 100f);
                    }
                }
            }
        }
Пример #2
0
        public void TestComplexAreaAlgorithmWithComplexPolygon()
        {
            // the complex area algorithm is very low resolution compared to simple area, so the error magnitude is higher
            const int side     = 1000;
            const int expected = side * side / 2;

            PointF[] data = new PointF[4];
            data[0] = new PointF(0, 0);
            data[1] = new PointF(side, 0);
            data[2] = new PointF(0, side);
            data[3] = new PointF(side, side);

            PolygonF.TestVertexNormalization(data);

            RectangleF bounding = RectangleUtilities.ComputeBoundingRectangle(data);

            unsafe
            {
                fixed(PointF *points = data)
                {
                    // inside PolygonF, the vertexCount is always exactly the expected array length
                    double result = PolygonF.TestComplexAreaComputation(bounding, points, data.Length);

                    Trace.WriteLine(string.Format("Complex Area: Expected {0:f5} Got {1:f5}", expected, result), "UNIT_TESTS");
                    Assert.IsTrue(Math.Abs(expected - result) < expected / 100f);
                }
            }
        }