public virtual void TestCreation1() { // Simple area and length calcul test com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); int number = poly.GetStateFlag(); com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(1000, 2000, 1010, 2010); env.ToString(); poly.AddEnvelope(env, false); poly.ToString(); number = poly.GetStateFlag(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(poly.CalculateArea2D() - 100) < 1e-12); NUnit.Framework.Assert.IsTrue(System.Math.Abs(poly.CalculateLength2D() - 40) < 1e-12); poly.SetEmpty(); number = poly.GetStateFlag(); poly.AddEnvelope(env, true); number = poly.GetStateFlag(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(poly.CalculateArea2D() + 100) < 1e-12); number = poly.GetStateFlag(); }
public static void TestPolygonAreaAndLength() { com.esri.core.geometry.Polygon poly; /* const */ double r = 1.0; /* const */ double epsilon = 1.0e-14; /* const */ int nMax = 40; // If r == 1.0 and nMax == 40 and epsilon == 1.0e-14, it will pass. // But if r == 1.0 and nMax == 40 and epsilon == 1.0e-15, it will fail. for (int n = 3; n < nMax; n++) { // regular polygon with n vertices and length from center to vertex // = r poly = new com.esri.core.geometry.Polygon(); double theta = 0.0; poly.StartPath(r, 0.0); for (int k = 1; k <= n; k++) { theta -= 2 * System.Math.PI / n; poly.LineTo(r * System.Math.Cos(theta), r * System.Math.Sin(theta)); } double sinPiOverN = System.Math.Sin(System.Math.PI / n); double sinTwoPiOverN = System.Math.Sin(2.0 * System.Math.PI / n); double analyticalLength = 2.0 * n * r * sinPiOverN; double analyticalArea = 0.5 * n * r * r * sinTwoPiOverN; double calculatedLength = poly.CalculateLength2D(); double calculatedArea = poly.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(analyticalLength - calculatedLength) < epsilon); NUnit.Framework.Assert.IsTrue(System.Math.Abs(analyticalArea - calculatedArea) < epsilon); } }