public virtual void TestEnvelope2D_corners() { com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(0, 1, 2, 3); NUnit.Framework.Assert.IsFalse(env.Equals(null)); NUnit.Framework.Assert.IsTrue(env.Equals((object)new com.epl.geometry.Envelope2D(0, 1, 2, 3))); com.epl.geometry.Point2D pt2D = env.GetLowerLeft(); NUnit.Framework.Assert.IsTrue(pt2D.Equals(com.epl.geometry.Point2D.Construct(0, 1))); pt2D = env.GetUpperLeft(); NUnit.Framework.Assert.IsTrue(pt2D.Equals(com.epl.geometry.Point2D.Construct(0, 3))); pt2D = env.GetUpperRight(); NUnit.Framework.Assert.IsTrue(pt2D.Equals(com.epl.geometry.Point2D.Construct(2, 3))); pt2D = env.GetLowerRight(); NUnit.Framework.Assert.IsTrue(pt2D.Equals(com.epl.geometry.Point2D.Construct(2, 1))); { com.epl.geometry.Point2D[] corners = new com.epl.geometry.Point2D[4]; env.QueryCorners(corners); NUnit.Framework.Assert.IsTrue(corners[0].Equals(com.epl.geometry.Point2D.Construct(0, 1))); NUnit.Framework.Assert.IsTrue(corners[1].Equals(com.epl.geometry.Point2D.Construct(0, 3))); NUnit.Framework.Assert.IsTrue(corners[2].Equals(com.epl.geometry.Point2D.Construct(2, 3))); NUnit.Framework.Assert.IsTrue(corners[3].Equals(com.epl.geometry.Point2D.Construct(2, 1))); env.QueryCorners(corners); NUnit.Framework.Assert.IsTrue(corners[0].Equals(env.QueryCorner(0))); NUnit.Framework.Assert.IsTrue(corners[1].Equals(env.QueryCorner(1))); NUnit.Framework.Assert.IsTrue(corners[2].Equals(env.QueryCorner(2))); NUnit.Framework.Assert.IsTrue(corners[3].Equals(env.QueryCorner(3))); } { com.epl.geometry.Point2D[] corners = new com.epl.geometry.Point2D[4]; env.QueryCornersReversed(corners); NUnit.Framework.Assert.IsTrue(corners[0].Equals(com.epl.geometry.Point2D.Construct(0, 1))); NUnit.Framework.Assert.IsTrue(corners[1].Equals(com.epl.geometry.Point2D.Construct(2, 1))); NUnit.Framework.Assert.IsTrue(corners[2].Equals(com.epl.geometry.Point2D.Construct(2, 3))); NUnit.Framework.Assert.IsTrue(corners[3].Equals(com.epl.geometry.Point2D.Construct(0, 3))); env.QueryCornersReversed(corners); NUnit.Framework.Assert.IsTrue(corners[0].Equals(env.QueryCorner(0))); NUnit.Framework.Assert.IsTrue(corners[1].Equals(env.QueryCorner(3))); NUnit.Framework.Assert.IsTrue(corners[2].Equals(env.QueryCorner(2))); NUnit.Framework.Assert.IsTrue(corners[3].Equals(env.QueryCorner(1))); } NUnit.Framework.Assert.IsTrue(env.GetCenter().Equals(com.epl.geometry.Point2D.Construct(1, 2))); NUnit.Framework.Assert.IsFalse(env.ContainsExclusive(env.GetUpperLeft())); NUnit.Framework.Assert.IsTrue(env.Contains(env.GetUpperLeft())); NUnit.Framework.Assert.IsTrue(env.ContainsExclusive(env.GetCenter())); }
// p0 and p1 have to be on left/right boundary of fullRange2D (since this // fuction can be called recursively, p0 or p1 can also be fullRange2D // corners) internal static int AddPointsToArray(com.epl.geometry.Point2D p0In, com.epl.geometry.Point2D p1In, com.epl.geometry.Point2D[] pointsArray, int idx, com.epl.geometry.Envelope2D fullRange2D, bool clockwise, double densifyDist) { // PointerOfArrayOf(Point2D) // pointsArray, int idx, // Envelope2D fullRange2D, // boolean clockwise, double // densifyDist) com.epl.geometry.Point2D p0 = new com.epl.geometry.Point2D(); p0.SetCoords(p0In); com.epl.geometry.Point2D p1 = new com.epl.geometry.Point2D(); p1.SetCoords(p1In); fullRange2D._snapToBoundary(p0); fullRange2D._snapToBoundary(p1); // //_ASSERT((p0.x == fullRange2D.xmin || p0.x == fullRange2D.xmax) && // (p1.x == fullRange2D.xmin || p1.x == fullRange2D.xmax)); double boundDist0 = fullRange2D._boundaryDistance(p0); double boundDist1 = fullRange2D._boundaryDistance(p1); if (boundDist1 == 0.0) { boundDist1 = fullRange2D.GetLength(); } if ((p0.x == p1.x || p0.y == p1.y && (p0.y == fullRange2D.ymin || p0.y == fullRange2D.ymax)) && (boundDist1 > boundDist0) == clockwise) { com.epl.geometry.Point2D delta = new com.epl.geometry.Point2D(); delta.SetCoords(p1.x - p0.x, p1.y - p0.y); if (densifyDist != 0) { // if (densifyDist) long cPoints = (long)(delta._norm(0) / densifyDist); if (cPoints > 0) { // if (cPoints) delta.Scale(1.0 / (cPoints + 1)); for (long i = 0; i < cPoints; i++) { p0.Add(delta); pointsArray[idx++].SetCoords(p0.x, p0.y); } } } } else { // ARRAYELEMENT(pointsArray, // idx++).setCoords(p0.x, // p0.y); int side0 = fullRange2D._envelopeSide(p0); int side1 = fullRange2D._envelopeSide(p1); // create up to four corner points; the order depends on boolean // clockwise com.epl.geometry.Point2D corner; int deltaSide = clockwise ? 1 : 3; do { // 3 is equivalent to -1 side0 = (side0 + deltaSide) & 3; corner = fullRange2D.QueryCorner(side0); if (densifyDist != 0) { // if (densifyDist) idx = AddPointsToArray(p0, corner, pointsArray, idx, fullRange2D, clockwise, densifyDist); } pointsArray[idx++].SetCoords(corner.x, corner.y); // ARRAYELEMENT(pointsArray, // idx++).setCoords(corner.x, // corner.y); p0 = corner; }while ((side0 & 3) != side1); if (densifyDist != 0) { // if (densifyDist) idx = AddPointsToArray(p0, p1, pointsArray, idx, fullRange2D, clockwise, densifyDist); } } return(idx); }
public virtual void QueryCorner(int index, com.epl.geometry.Point2D ptDst) { com.epl.geometry.Point2D p = m_envelope.QueryCorner(index); ptDst.SetCoords(p.x, p.y); }