private static int QuickTest2DEnvelopePoint(com.epl.geometry.Envelope2D geomAEnv, com.epl.geometry.Point2D ptB, double tolerance) { com.epl.geometry.Envelope2D envAMinus = geomAEnv; envAMinus.Inflate(-tolerance, -tolerance); if (envAMinus.Contains(ptB)) { return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains); } // clementini's contains com.epl.geometry.Envelope2D envAPlus = geomAEnv; envAPlus.Inflate(tolerance, tolerance); if (envAPlus.Contains(ptB)) { return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Touches); } // clementini's touches return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint); }
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())); }
internal static com.epl.geometry.Geometry MultiPointMinusPolygon_(com.epl.geometry.MultiPoint multi_point, com.epl.geometry.Polygon polygon, double tolerance, com.epl.geometry.ProgressTracker progress_tracker) { com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); polygon.QueryEnvelope2D(env); env.Inflate(tolerance, tolerance); int point_count = multi_point.GetPointCount(); bool b_found_covered = false; bool[] covered = new bool[point_count]; for (int i = 0; i < point_count; i++) { covered[i] = false; } com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D(); for (int i_1 = 0; i_1 < point_count; i_1++) { multi_point.GetXY(i_1, pt); if (!env.Contains(pt)) { continue; } com.epl.geometry.PolygonUtils.PiPResult result = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, pt, tolerance); if (result == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside) { continue; } b_found_covered = true; covered[i_1] = true; } if (!b_found_covered) { return(multi_point); } com.epl.geometry.MultiPoint new_multipoint = (com.epl.geometry.MultiPoint)multi_point.CreateInstance(); for (int i_2 = 0; i_2 < point_count; i_2++) { if (!covered[i_2]) { new_multipoint.Add(multi_point, i_2, i_2 + 1); } } return(new_multipoint); }
public static int IsPointInPolygon(com.epl.geometry.Polygon inputPolygon, com.epl.geometry.Point2D inputPoint, double tolerance) { if (inputPolygon.IsEmpty()) { return(0); } com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); inputPolygon.QueryLooseEnvelope(env); env.Inflate(tolerance, tolerance); if (!env.Contains(inputPoint)) { return(0); } com.epl.geometry.MultiPathImpl mpImpl = (com.epl.geometry.MultiPathImpl)inputPolygon._getImpl(); com.epl.geometry.GeometryAccelerators accel = mpImpl._getAccelerators(); if (accel != null) { // geometry has spatial indices built. Try using them. com.epl.geometry.RasterizedGeometry2D rgeom = accel.GetRasterizedGeometry(); if (rgeom != null) { com.epl.geometry.RasterizedGeometry2D.HitType hit = rgeom.QueryPointInGeometry(inputPoint.x, inputPoint.y); if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Inside) { return(1); } else { if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Outside) { return(0); } } } com.epl.geometry.QuadTreeImpl qtree = accel.GetQuadTree(); if (qtree != null) { return(_isPointInPolygonInternalWithQuadTree(inputPolygon, qtree, inputPoint, tolerance)); } } return(_isPointInPolygonInternal(inputPolygon, inputPoint, tolerance)); }
// GEOMTHROW(invalid_call); private static void _testPointsInEnvelope2D(com.epl.geometry.Envelope2D env2D, com.epl.geometry.Point2D[] inputPoints, int count, double tolerance, com.epl.geometry.PolygonUtils.PiPResult[] testResults) { if (inputPoints.Length < count || testResults.Length < count) { throw new System.ArgumentException(); } if (env2D.IsEmpty()) { for (int i = 0; i < count; i++) { testResults[i] = com.epl.geometry.PolygonUtils.PiPResult.PiPOutside; } return; } com.epl.geometry.Envelope2D envIn = env2D; // note for java port - assignement by value envIn.Inflate(-tolerance * 0.5, -tolerance * 0.5); com.epl.geometry.Envelope2D envOut = env2D; // note for java port - assignement by value envOut.Inflate(tolerance * 0.5, tolerance * 0.5); for (int i_1 = 0; i_1 < count; i_1++) { if (envIn.Contains(inputPoints[i_1])) { testResults[i_1] = com.epl.geometry.PolygonUtils.PiPResult.PiPInside; } else { if (!envOut.Contains(inputPoints[i_1])) { testResults[i_1] = com.epl.geometry.PolygonUtils.PiPResult.PiPOutside; } else { testResults[i_1] = com.epl.geometry.PolygonUtils.PiPResult.PiPBoundary; } } } }
internal static com.epl.geometry.Geometry PointMinusPolyline_(com.epl.geometry.Point point, com.epl.geometry.Polyline polyline, double tolerance, com.epl.geometry.ProgressTracker progress_tracker) { com.epl.geometry.Point2D pt = point.GetXY(); com.epl.geometry.SegmentIterator seg_iter = polyline.QuerySegmentIterator(); double tolerance_cluster = tolerance * System.Math.Sqrt(2.0) * 1.00001; double tolerance_cluster_sq = tolerance_cluster * tolerance_cluster; com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); while (seg_iter.NextPath()) { while (seg_iter.HasNextSegment()) { com.epl.geometry.Segment segment = seg_iter.NextSegment(); segment.QueryEnvelope2D(env); env.Inflate(tolerance_cluster, tolerance_cluster); if (!env.Contains(pt)) { continue; } if (segment.IsIntersecting(pt, tolerance)) { return(point.CreateInstance()); } // check segment end points to the cluster tolerance com.epl.geometry.Point2D end_point = segment.GetStartXY(); if (com.epl.geometry.Point2D.SqrDistance(pt, end_point) <= tolerance_cluster_sq) { return(point.CreateInstance()); } end_point = segment.GetEndXY(); if (com.epl.geometry.Point2D.SqrDistance(pt, end_point) <= tolerance_cluster_sq) { return(point.CreateInstance()); } } } return(point); }
internal static int IsPointInPolygon(com.epl.geometry.Polygon inputPolygon, double inputPointXVal, double inputPointYVal, double tolerance) { if (inputPolygon.IsEmpty()) { return(0); } com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); inputPolygon.QueryLooseEnvelope(env); env.Inflate(tolerance, tolerance); if (!env.Contains(inputPointXVal, inputPointYVal)) { return(0); } com.epl.geometry.MultiPathImpl mpImpl = (com.epl.geometry.MultiPathImpl)inputPolygon._getImpl(); com.epl.geometry.GeometryAccelerators accel = mpImpl._getAccelerators(); if (accel != null) { com.epl.geometry.RasterizedGeometry2D rgeom = accel.GetRasterizedGeometry(); if (rgeom != null) { com.epl.geometry.RasterizedGeometry2D.HitType hit = rgeom.QueryPointInGeometry(inputPointXVal, inputPointYVal); if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Inside) { return(1); } else { if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Outside) { return(0); } } } } return(_isPointInPolygonInternal(inputPolygon, new com.epl.geometry.Point2D(inputPointXVal, inputPointYVal), tolerance)); }
private static int QuickTest2DEnvelopeEnvelope(com.epl.geometry.Envelope2D geomAEnv, com.epl.geometry.Envelope2D geomBEnv, double tolerance) { // firstly check for contains and within to give a chance degenerate // envelopes to work. // otherwise, if there are two degenerate envelopes that are equal, // Touch relation may occur. int res = 0; if (geomAEnv.Contains(geomBEnv)) { res |= (int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains; } if (geomBEnv.Contains(geomAEnv)) { res |= (int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Within; } if (res != 0) { return(res); } com.epl.geometry.Envelope2D envAMinus = geomAEnv; envAMinus.Inflate(-tolerance, -tolerance); // Envelope A interior com.epl.geometry.Envelope2D envBMinus = geomBEnv; envBMinus.Inflate(-tolerance, -tolerance); // Envelope B interior if (envAMinus.IsIntersecting(envBMinus)) { com.epl.geometry.Envelope2D envAPlus = geomAEnv; envAPlus.Inflate(tolerance, tolerance); // Envelope A interior plus // boundary res = envAPlus.Contains(geomBEnv) ? (int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains : 0; com.epl.geometry.Envelope2D envBPlus = geomBEnv; envBPlus.Inflate(tolerance, tolerance); // Envelope A interior plus // boundary res |= envBPlus.Contains(geomAEnv) ? (int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Within : 0; if (res != 0) { return(res); } return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Overlaps); } else { // Clementini's Overlap com.epl.geometry.Envelope2D envAPlus = geomAEnv; envAPlus.Inflate(tolerance, tolerance); // Envelope A interior plus // boundary com.epl.geometry.Envelope2D envBPlus = geomBEnv; envBPlus.Inflate(tolerance, tolerance); // Envelope A interior plus // boundary if (envAPlus.IsIntersecting(envBPlus)) { return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Touches); } else { // Clementini Touch return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint); } } }
private bool CrackBruteForce_() { com.epl.geometry.EditShape.VertexIterator iter_1 = m_shape.QueryVertexIterator(false); bool b_cracked = false; com.epl.geometry.Line line_1 = new com.epl.geometry.Line(); com.epl.geometry.Line line_2 = new com.epl.geometry.Line(); com.epl.geometry.Envelope2D seg_1_env = new com.epl.geometry.Envelope2D(); seg_1_env.SetEmpty(); com.epl.geometry.Envelope2D seg_2_env = new com.epl.geometry.Envelope2D(); seg_2_env.SetEmpty(); bool assume_intersecting = false; com.epl.geometry.Point helper_point = new com.epl.geometry.Point(); com.epl.geometry.SegmentIntersector segment_intersector = new com.epl.geometry.SegmentIntersector(); for (int vertex_1 = iter_1.Next(); vertex_1 != -1; vertex_1 = iter_1.Next()) { com.epl.geometry.ProgressTracker.CheckAndThrow(m_progress_tracker); int GT_1 = m_shape.GetGeometryType(iter_1.CurrentGeometry()); com.epl.geometry.Segment seg_1 = null; bool seg_1_zero = false; if (!com.epl.geometry.Geometry.IsPoint(GT_1)) { seg_1 = GetSegment_(vertex_1, line_1); if (seg_1 == null) { continue; } seg_1.QueryEnvelope2D(seg_1_env); seg_1_env.Inflate(m_tolerance, m_tolerance); if (seg_1.IsDegenerate(m_tolerance)) { // do not crack with // degenerate segments if (seg_1.IsDegenerate(0)) { seg_1_zero = true; seg_1 = null; } else { continue; } } } com.epl.geometry.EditShape.VertexIterator iter_2 = m_shape.QueryVertexIterator(iter_1); int vertex_2 = iter_2.Next(); if (vertex_2 != -1) { vertex_2 = iter_2.Next(); } for (; vertex_2 != -1; vertex_2 = iter_2.Next()) { int GT_2 = m_shape.GetGeometryType(iter_2.CurrentGeometry()); com.epl.geometry.Segment seg_2 = null; bool seg_2_zero = false; if (!com.epl.geometry.Geometry.IsPoint(GT_2)) { seg_2 = GetSegment_(vertex_2, line_2); if (seg_2 == null) { continue; } seg_2.QueryEnvelope2D(seg_2_env); if (seg_2.IsDegenerate(m_tolerance)) { // do not crack with // degenerate segments if (seg_2.IsDegenerate(0)) { seg_2_zero = true; seg_2 = null; } else { continue; } } } int split_count_1 = 0; int split_count_2 = 0; if (seg_1 != null && seg_2 != null) { if (seg_1_env.IsIntersectingNE(seg_2_env)) { segment_intersector.PushSegment(seg_1); segment_intersector.PushSegment(seg_2); segment_intersector.Intersect(m_tolerance, assume_intersecting); split_count_1 = segment_intersector.GetResultSegmentCount(0); split_count_2 = segment_intersector.GetResultSegmentCount(1); if (split_count_1 + split_count_2 > 0) { m_shape.SplitSegment_(vertex_1, segment_intersector, 0, true); m_shape.SplitSegment_(vertex_2, segment_intersector, 1, true); } segment_intersector.Clear(); } } else { if (seg_1 != null) { com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D(); m_shape.GetXY(vertex_2, pt); if (seg_1_env.Contains(pt)) { segment_intersector.PushSegment(seg_1); m_shape.QueryPoint(vertex_2, helper_point); segment_intersector.Intersect(m_tolerance, helper_point, 0, 1.0, assume_intersecting); split_count_1 = segment_intersector.GetResultSegmentCount(0); if (split_count_1 > 0) { m_shape.SplitSegment_(vertex_1, segment_intersector, 0, true); if (seg_2_zero) { //seg_2 was zero length. Need to change all coincident points //segment at vertex_2 is dzero length, change all attached zero length segments int v_to = -1; for (int v = m_shape.GetNextVertex(vertex_2); v != -1 && v != vertex_2; v = m_shape.GetNextVertex(v)) { seg_2 = GetSegment_(v, line_2); v_to = v; if (seg_2 == null || !seg_2.IsDegenerate(0)) { break; } } //change from vertex_2 to v_to (inclusive). for (int v_1 = vertex_2; v_1 != -1; v_1 = m_shape.GetNextVertex(v_1)) { m_shape.SetPoint(v_1, segment_intersector.GetResultPoint()); if (v_1 == v_to) { break; } } } else { m_shape.SetPoint(vertex_2, segment_intersector.GetResultPoint()); } } segment_intersector.Clear(); } } else { if (seg_2 != null) { com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D(); m_shape.GetXY(vertex_1, pt); seg_2_env.Inflate(m_tolerance, m_tolerance); if (seg_2_env.Contains(pt)) { segment_intersector.PushSegment(seg_2); m_shape.QueryPoint(vertex_1, helper_point); segment_intersector.Intersect(m_tolerance, helper_point, 0, 1.0, assume_intersecting); split_count_2 = segment_intersector.GetResultSegmentCount(0); if (split_count_2 > 0) { m_shape.SplitSegment_(vertex_2, segment_intersector, 0, true); if (seg_1_zero) { //seg_1 was zero length. Need to change all coincident points //segment at vertex_2 is dzero length, change all attached zero length segments int v_to = -1; for (int v = m_shape.GetNextVertex(vertex_1); v != -1 && v != vertex_1; v = m_shape.GetNextVertex(v)) { seg_2 = GetSegment_(v, line_2); //using here seg_2 for seg_1 v_to = v; if (seg_2 == null || !seg_2.IsDegenerate(0)) { break; } } //change from vertex_2 to v_to (inclusive). for (int v_1 = vertex_1; v_1 != -1; v_1 = m_shape.GetNextVertex(v_1)) { m_shape.SetPoint(v_1, segment_intersector.GetResultPoint()); if (v_1 == v_to) { break; } } } else { m_shape.SetPoint(vertex_1, segment_intersector.GetResultPoint()); } } segment_intersector.Clear(); } } else { continue; } } } // points on points if (split_count_1 + split_count_2 != 0) { if (split_count_1 != 0) { seg_1 = m_shape.GetSegment(vertex_1); // reload segment // after split if (seg_1 == null) { if (!m_shape.QueryLineConnector(vertex_1, line_1)) { continue; } seg_1 = line_1; line_1.QueryEnvelope2D(seg_1_env); } else { seg_1.QueryEnvelope2D(seg_1_env); } if (seg_1.IsDegenerate(m_tolerance)) { // do not crack with // degenerate // segments break; } } b_cracked = true; } } } return(b_cracked); }
public static int IsPointInRing(com.epl.geometry.MultiPathImpl inputPolygonImpl, int iRing, com.epl.geometry.Point2D inputPoint, double tolerance, com.epl.geometry.QuadTree quadTree) { com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); inputPolygonImpl.QueryLooseEnvelope2D(env); env.Inflate(tolerance, tolerance); if (!env.Contains(inputPoint)) { return(0); } bool bAltenate = true; com.epl.geometry.PointInPolygonHelper helper = new com.epl.geometry.PointInPolygonHelper(bAltenate, inputPoint, tolerance); if (quadTree != null) { com.epl.geometry.Envelope2D queryEnv = new com.epl.geometry.Envelope2D(); queryEnv.SetCoords(env); queryEnv.xmax = inputPoint.x + tolerance; // no need to query // segments to // the right of the // point. // Only segments to the // left // matter. queryEnv.ymin = inputPoint.y - tolerance; queryEnv.ymax = inputPoint.y + tolerance; com.epl.geometry.SegmentIteratorImpl iter = inputPolygonImpl.QuerySegmentIterator(); com.epl.geometry.QuadTree.QuadTreeIterator qiter = quadTree.GetIterator(queryEnv, tolerance); for (int qhandle = qiter.Next(); qhandle != -1; qhandle = qiter.Next()) { iter.ResetToVertex(quadTree.GetElement(qhandle), iRing); if (iter.HasNextSegment()) { if (iter.GetPathIndex() != iRing) { continue; } com.epl.geometry.Segment segment = iter.NextSegment(); if (helper.ProcessSegment(segment)) { return(-1); } } } // point on boundary return(helper.Result()); } else { com.epl.geometry.SegmentIteratorImpl iter = inputPolygonImpl.QuerySegmentIterator(); iter.ResetToPath(iRing); if (iter.NextPath()) { while (iter.HasNextSegment()) { com.epl.geometry.Segment segment = iter.NextSegment(); if (helper.ProcessSegment(segment)) { return(-1); } } } // point on boundary return(helper.Result()); } }