Ejemplo n.º 1
0
        public void Test_Polygon_Centroid()
        {
            var arr = new IntPoint[4];

            arr[0] = new IntPoint(-100, -200);
            arr[1] = new IntPoint(100, -200);
            arr[2] = new IntPoint(100, 200);
            arr[3] = new IntPoint(-100, 200);

            var x = 77;
            var y = 44;

            for (var i = 0; i < arr.Length; ++i)
            {
                arr[i] = new IntPoint(x + arr[i].X, y + arr[i].Y);
            }

            var area = PolygonMath.GetClosedPolygonArea(arr);

            Assert.AreEqual(80000, area); // counterclockwise should give positive area
            var centroid = PolygonMath.GetClosedPolygonCentroid(arr);

            Assert.AreEqual(x, centroid.X);
            Assert.AreEqual(y, centroid.Y);
        }
Ejemplo n.º 2
0
        public void Test_Polygon_Area()
        {
            var arr = new IntPoint[4];

            arr[0] = new IntPoint(-200, -100);
            arr[1] = new IntPoint(100, -100);
            arr[2] = new IntPoint(100, 100);
            arr[3] = new IntPoint(-200, 100);

            var area = PolygonMath.GetClosedPolygonArea(arr);

            Assert.AreEqual(60000, area); // counterclockwise should give positive area
        }