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); } }
public virtual void TestReverseAllPaths() { com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 1); poly.LineTo(15, 20); poly.LineTo(30, 14); poly.LineTo(60, 144); poly.StartPath(10, 1); poly.LineTo(15, 20); poly.LineTo(300, 14); poly.LineTo(60, 144); poly.StartPath(10, 1); poly.LineTo(125, 20); poly.LineTo(30, 14); poly.LineTo(600, 144); // poly.setAttribute(enum_value2(VertexDescription, Semantics, Z), 0, 0, // 2); // poly.setAttribute(enum_value2(VertexDescription, Semantics, Z), 1, 0, // 3); // poly.setAttribute(enum_value2(VertexDescription, Semantics, Z), 2, 0, // 5); // poly.setAttribute(enum_value2(VertexDescription, Semantics, Z), 3, 0, // 7); // // poly.setAttribute(enum_value2(VertexDescription, Semantics, Z), 4, 0, // 11); // poly.setAttribute(enum_value2(VertexDescription, Semantics, Z), 5, 0, // 13); // poly.setAttribute(enum_value2(VertexDescription, Semantics, Z), 6, 0, // 17); // poly.setAttribute(enum_value2(VertexDescription, Semantics, Z), 7, 0, // 19); // // poly.setAttribute(enum_value2(VertexDescription, Semantics, Z), 8, 0, // 23); // poly.setAttribute(enum_value2(VertexDescription, Semantics, Z), 9, 0, // 29); // poly.setAttribute(enum_value2(VertexDescription, Semantics, Z), 10, // 0, 31); // poly.setAttribute(enum_value2(VertexDescription, Semantics, Z), 11, // 0, 37); double area = poly.CalculateArea2D(); poly.ReverseAllPaths(); double areaReversed = poly.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(area + areaReversed) <= 0.001); }
public virtual void TestRemovepath() { com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 1); poly.LineTo(15, 20); poly.LineTo(30, 14); poly.LineTo(60, 144); poly.StartPath(10, 1); poly.LineTo(15, 20); poly.LineTo(300, 14); poly.LineTo(60, 144); poly.StartPath(10, 1); poly.LineTo(125, 20); poly.LineTo(30, 14); poly.LineTo(600, 144); // poly->SetAttribute(enum_value2(VertexDescription, Semantics, Z), 0, // 0, 2); // poly->SetAttribute(enum_value2(VertexDescription, Semantics, Z), 1, // 0, 3); // poly->SetAttribute(enum_value2(VertexDescription, Semantics, Z), 2, // 0, 5); // poly->SetAttribute(enum_value2(VertexDescription, Semantics, Z), 3, // 0, 7); // poly->SetAttribute(enum_value2(VertexDescription, Semantics, Z), 4, // 0, 11); // poly->SetAttribute(enum_value2(VertexDescription, Semantics, Z), 5, // 0, 13); // poly->SetAttribute(enum_value2(VertexDescription, Semantics, Z), 6, // 0, 17); // poly->SetAttribute(enum_value2(VertexDescription, Semantics, Z), 7, // 0, 19); // poly->SetAttribute(enum_value2(VertexDescription, Semantics, Z), 8, // 0, 23); // poly->SetAttribute(enum_value2(VertexDescription, Semantics, Z), 9, // 0, 29); // poly->SetAttribute(enum_value2(VertexDescription, Semantics, Z), 10, // 0, 31); // poly->SetAttribute(enum_value2(VertexDescription, Semantics, Z), 11, // 0, 37); poly.RemovePath(1); NUnit.Framework.Assert.IsTrue(poly.GetPathCount() == 2); NUnit.Framework.Assert.IsTrue(poly.GetPathStart(1) == 4); NUnit.Framework.Assert.IsTrue(poly.IsClosedPath(0)); NUnit.Framework.Assert.IsTrue(poly.IsClosedPath(1)); com.esri.core.geometry.Point ptOut = poly.GetPoint(4); NUnit.Framework.Assert.IsTrue(ptOut.GetX() == 10 && ptOut.GetY() == 1); poly.RemovePath(0); poly.RemovePath(0); NUnit.Framework.Assert.IsTrue(poly.GetPathCount() == 0); com.esri.core.geometry.Polygon poly2 = new com.esri.core.geometry.Polygon(); poly2.StartPath(0, 0); poly2.LineTo(0, 10); poly2.LineTo(10, 10); poly2.StartPath(1, 1); poly2.LineTo(2, 2); poly2.RemovePath(0); // poly2->StartPath(0, 0); poly2.LineTo(0, 10); poly2.LineTo(10, 10); // Polygon polygon2 = new Polygon(); // polygon2.addPath(poly, -1, true); // polygon2.addPath(poly, -1, true); // polygon2.addPath(poly, -1, true); // assertTrue(polygon2.getPathCount() == 3); // polygon2.removePath(0); // polygon2.removePath(0); // polygon2.removePath(0); // assertTrue(polygon2.getPathCount() == 0); // polygon2.addPath(poly, -1, true); // Point point1 = new Point(); // Point point2 = new Point(); // point1.setX(0); // point1.setY(0); // point2.setX(0); // point2.setY(0); // polygon2.addPath(poly2, 0, true); // polygon2.removePath(0); // polygon2.insertPoint(0, 0, point1); // polygon2.insertPoint(0, 0, point2); // assertTrue(polygon2.getPathCount() == 1); // assertTrue(polygon2.getPointCount() == 2); com.esri.core.geometry.Polygon polygon3 = new com.esri.core.geometry.Polygon(); polygon3.StartPath(0, 0); polygon3.LineTo(0, 10); polygon3.LineTo(10, 10); double area = polygon3.CalculateArea2D(); polygon3.RemovePath(0); polygon3.StartPath(0, 0); polygon3.LineTo(0, 10); polygon3.LineTo(10, 10); area = polygon3.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(area > 0.0); }