예제 #1
0
        public void PolygonArea()
        {
            PointD p0 = new PointD(0, 0), p1 = new PointD(1, 1), p2 = new PointD(2, 0);
            PointD p3 = new PointD(0, 2), p4 = new PointD(2, 2);

            // triangles in both orientations
            Assert.AreEqual(-1, GeoAlgorithms.PolygonArea(p0, p1, p2));
            Assert.AreEqual(+1, GeoAlgorithms.PolygonArea(p2, p1, p0));

            // squares in both orientations
            Assert.AreEqual(-4, GeoAlgorithms.PolygonArea(p0, p3, p4, p2));
            Assert.AreEqual(+4, GeoAlgorithms.PolygonArea(p2, p4, p3, p0));

            // collinear points and star shape
            Assert.AreEqual(0, GeoAlgorithms.PolygonArea(p0, p1, p4));
            Assert.AreEqual(0, GeoAlgorithms.PolygonArea(p0, p1, p3, p1, p2, p1, p4, p1));
        }