Esempio n. 1
0
        internal virtual com.epl.geometry.Proximity2DResult[] PointGetNearestVertices(com.epl.geometry.Point geom, com.epl.geometry.Point2D inputPoint, double searchRadius, int maxVertexCountToReturn)
        {
            com.epl.geometry.Proximity2DResult[] resultArray;
            if (maxVertexCountToReturn == 0)
            {
                resultArray = new com.epl.geometry.Proximity2DResult[] {  };
                return(resultArray);
            }
            double searchRadiusSq = searchRadius * searchRadius;

            com.epl.geometry.Point2D pt = geom.GetXY();
            double distanceSq           = com.epl.geometry.Point2D.SqrDistance(pt, inputPoint);

            if (distanceSq <= searchRadiusSq)
            {
                resultArray = new com.epl.geometry.Proximity2DResult[1];
                com.epl.geometry.Proximity2DResult result = new com.epl.geometry.Proximity2DResult();
                result._setParams(pt.x, pt.y, 0, System.Math.Sqrt(distanceSq));
                resultArray[0] = result;
            }
            else
            {
                resultArray = new com.epl.geometry.Proximity2DResult[0];
            }
            return(resultArray);
        }
Esempio n. 2
0
        internal virtual com.epl.geometry.Proximity2DResult MultiVertexGetNearestVertex(com.epl.geometry.MultiVertexGeometry geom, com.epl.geometry.Point2D inputPoint)
        {
            com.epl.geometry.MultiVertexGeometryImpl mpImpl   = (com.epl.geometry.MultiVertexGeometryImpl)geom._getImpl();
            com.epl.geometry.AttributeStreamOfDbl    position = (com.epl.geometry.AttributeStreamOfDbl)mpImpl.GetAttributeStreamRef((com.epl.geometry.VertexDescription.Semantics.POSITION));
            int    pointCount        = geom.GetPointCount();
            int    closestIndex      = 0;
            double closestx          = 0.0;
            double closesty          = 0.0;
            double closestDistanceSq = com.epl.geometry.NumberUtils.DoubleMax();

            for (int i = 0; i < pointCount; i++)
            {
                com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D();
                position.Read(2 * i, pt);
                double distanceSq = com.epl.geometry.Point2D.SqrDistance(pt, inputPoint);
                if (distanceSq < closestDistanceSq)
                {
                    closestx          = pt.x;
                    closesty          = pt.y;
                    closestIndex      = i;
                    closestDistanceSq = distanceSq;
                }
            }
            com.epl.geometry.Proximity2DResult result = new com.epl.geometry.Proximity2DResult();
            result._setParams(closestx, closesty, closestIndex, System.Math.Sqrt(closestDistanceSq));
            return(result);
        }
 public static void TestCR254240()
 {
     com.epl.geometry.OperatorProximity2D proximityOp = com.epl.geometry.OperatorProximity2D.Local();
     com.epl.geometry.Point    inputPoint             = new com.epl.geometry.Point(-12, 12);
     com.epl.geometry.Polyline line = new com.epl.geometry.Polyline();
     line.StartPath(-10, 0);
     line.LineTo(0, 0);
     com.epl.geometry.Proximity2DResult result = proximityOp.GetNearestCoordinate(line, inputPoint, false, true);
     NUnit.Framework.Assert.IsTrue(result.IsRightSide() == false);
 }
 public static void TestProximity2D_3()
 {
     com.epl.geometry.OperatorFactoryLocal factory   = com.epl.geometry.OperatorFactoryLocal.GetInstance();
     com.epl.geometry.OperatorProximity2D  proximity = (com.epl.geometry.OperatorProximity2D)factory.GetOperator(com.epl.geometry.Operator.Type.Proximity2D);
     com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
     polygon.StartPath(new com.epl.geometry.Point(-120, 22));
     polygon.LineTo(new com.epl.geometry.Point(-120, 10));
     polygon.LineTo(new com.epl.geometry.Point(-110, 10));
     polygon.LineTo(new com.epl.geometry.Point(-110, 22));
     com.epl.geometry.Point point = new com.epl.geometry.Point();
     point.SetXY(-110, 20);
     com.epl.geometry.Proximity2DResult result = proximity.GetNearestCoordinate(polygon, point, false);
     com.epl.geometry.Point             point2 = new com.epl.geometry.Point();
     point2.SetXY(-120, 12);
     com.epl.geometry.Proximity2DResult[] results = proximity.GetNearestVertices(polygon, point2, 10, 12);
 }
 public virtual void TestProximity2D_2()
 {
     com.epl.geometry.Point    point1   = new com.epl.geometry.Point(3, 2);
     com.epl.geometry.Point    point2   = new com.epl.geometry.Point(2, 4);
     com.epl.geometry.Envelope envelope = new com.epl.geometry.Envelope();
     envelope.SetCoords(4, 3, 7, 6);
     com.epl.geometry.Polygon polygonToTest = new com.epl.geometry.Polygon();
     polygonToTest.AddEnvelope(envelope, false);
     com.epl.geometry.Proximity2DResult prxResult1 = com.epl.geometry.GeometryEngine.GetNearestVertex(envelope, point1);
     com.epl.geometry.Proximity2DResult prxResult2 = com.epl.geometry.GeometryEngine.GetNearestVertex(polygonToTest, point1);
     com.epl.geometry.Proximity2DResult prxResult3 = com.epl.geometry.GeometryEngine.GetNearestCoordinate(envelope, point2, false);
     com.epl.geometry.Proximity2DResult prxResult4 = com.epl.geometry.GeometryEngine.GetNearestCoordinate(polygonToTest, point2, false);
     com.epl.geometry.Point             result1    = prxResult1.GetCoordinate();
     com.epl.geometry.Point             result2    = prxResult2.GetCoordinate();
     NUnit.Framework.Assert.IsTrue(result1.GetX() == result2.GetX());
     com.epl.geometry.Point result3 = prxResult3.GetCoordinate();
     com.epl.geometry.Point result4 = prxResult4.GetCoordinate();
     NUnit.Framework.Assert.IsTrue(result3.GetX() == result4.GetX());
 }
Esempio n. 6
0
        internal virtual com.epl.geometry.Proximity2DResult[] MultiVertexGetNearestVertices(com.epl.geometry.MultiVertexGeometry geom, com.epl.geometry.Point2D inputPoint, double searchRadius, int maxVertexCountToReturn)
        {
            com.epl.geometry.Proximity2DResult[] resultArray;
            if (maxVertexCountToReturn == 0)
            {
                resultArray = new com.epl.geometry.Proximity2DResult[0];
                return(resultArray);
            }
            com.epl.geometry.MultiVertexGeometryImpl mpImpl   = (com.epl.geometry.MultiVertexGeometryImpl)geom._getImpl();
            com.epl.geometry.AttributeStreamOfDbl    position = (com.epl.geometry.AttributeStreamOfDbl)mpImpl.GetAttributeStreamRef((com.epl.geometry.VertexDescription.Semantics.POSITION));
            int pointCount = geom.GetPointCount();

            System.Collections.Generic.List <com.epl.geometry.Proximity2DResult> v = new System.Collections.Generic.List <com.epl.geometry.Proximity2DResult>(maxVertexCountToReturn);
            int    count          = 0;
            double searchRadiusSq = searchRadius * searchRadius;

            for (int i = 0; i < pointCount; i++)
            {
                double x          = position.Read(2 * i);
                double y          = position.Read(2 * i + 1);
                double xDiff      = inputPoint.x - x;
                double yDiff      = inputPoint.y - y;
                double distanceSq = xDiff * xDiff + yDiff * yDiff;
                if (distanceSq <= searchRadiusSq)
                {
                    com.epl.geometry.Proximity2DResult result = new com.epl.geometry.Proximity2DResult();
                    result._setParams(x, y, i, System.Math.Sqrt(distanceSq));
                    count++;
                    v.Add(result);
                }
            }
            int vsize = v.Count;

            v.Sort(new com.epl.geometry.Proximity2DResultComparator());
            if (maxVertexCountToReturn >= vsize)
            {
                return(v.ToArray());
            }
            return(v.GetRange(0, maxVertexCountToReturn - 0).ToArray());
        }
        public virtual void TestProximity_2D_1()
        {
            com.epl.geometry.OperatorFactoryLocal engine      = com.epl.geometry.OperatorFactoryLocal.GetInstance();
            com.epl.geometry.OperatorProximity2D  proximityOp = (com.epl.geometry.OperatorProximity2D)engine.GetOperator(com.epl.geometry.Operator.Type.Proximity2D);
            com.epl.geometry.Point inputPoint = new com.epl.geometry.Point(3, 2);
            com.epl.geometry.Point point0     = new com.epl.geometry.Point(2.75, 2);
            // Point point1 = new Point(3, 2.5);
            // Point point2 = new Point(3.75, 2);
            // Point point3 = new Point(2.25, 2.5);
            // Point point4 = new Point(4, 2.25);
            // GetNearestVertices for Polygon (Native and DotNet)
            com.epl.geometry.Polygon             polygon     = MakePolygon();
            com.epl.geometry.Proximity2DResult[] resultArray = com.epl.geometry.GeometryEngine.GetNearestVertices(polygon, inputPoint, 2.0, 8);
            NUnit.Framework.Assert.IsTrue(resultArray.Length == 8);
            double lastdistance;
            double distance;

            com.epl.geometry.Proximity2DResult result0 = resultArray[0];
            lastdistance = result0.GetDistance();
            NUnit.Framework.Assert.IsTrue(lastdistance <= 2.0);
            com.epl.geometry.Proximity2DResult result1 = resultArray[1];
            distance = result1.GetDistance();
            NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance);
            lastdistance = distance;
            com.epl.geometry.Proximity2DResult result2 = resultArray[2];
            distance = result2.GetDistance();
            NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance);
            lastdistance = distance;
            com.epl.geometry.Proximity2DResult result3 = resultArray[3];
            distance = result3.GetDistance();
            NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance);
            lastdistance = distance;
            com.epl.geometry.Proximity2DResult result4 = resultArray[4];
            distance = result4.GetDistance();
            NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance);
            lastdistance = distance;
            com.epl.geometry.Proximity2DResult result5 = resultArray[5];
            distance = result5.GetDistance();
            NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance);
            lastdistance = distance;
            com.epl.geometry.Proximity2DResult result6 = resultArray[6];
            distance = result6.GetDistance();
            NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance);
            lastdistance = distance;
            com.epl.geometry.Proximity2DResult result7 = resultArray[7];
            distance = result7.GetDistance();
            NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance);
            // lastdistance = distance;
            // Point[] coordinates = polygon.get.getCoordinates2D();
            // int pointCount = polygon.getPointCount();
            //
            // int hits = 0;
            // for (int i = 0; i < pointCount; i++)
            // {
            // Point ipoint = coordinates[i];
            // distance = Point::Distance(ipoint, inputPoint);
            //
            // if (distance < lastdistance)
            // hits++;
            // }
            // assertTrue(hits < 8);
            // GetNearestVertices for Point
            com.epl.geometry.Point point = MakePoint();
            resultArray = com.epl.geometry.GeometryEngine.GetNearestVertices(point, inputPoint, 1.0, 1);
            NUnit.Framework.Assert.IsTrue(resultArray.Length == 1);
            result0 = resultArray[0];
            com.epl.geometry.Point resultPoint0 = result0.GetCoordinate();
            NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == point.GetX() && resultPoint0.GetY() == point.GetY());
            // GetNearestVertex for Polygon
            result0      = com.epl.geometry.GeometryEngine.GetNearestVertex(polygon, inputPoint);
            resultPoint0 = result0.GetCoordinate();
            NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == point0.GetX() && resultPoint0.GetY() == point0.GetY());
            // GetNearestVertex for Point
            result0      = com.epl.geometry.GeometryEngine.GetNearestVertex(point, inputPoint);
            resultPoint0 = result0.GetCoordinate();
            NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == point.GetX() && resultPoint0.GetY() == point.GetY());
            // GetNearestCoordinate for Polygon
            com.epl.geometry.Polygon polygon2 = MakePolygon2();
            result0      = com.epl.geometry.GeometryEngine.GetNearestCoordinate(polygon2, inputPoint, true);
            resultPoint0 = result0.GetCoordinate();
            NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == inputPoint.GetX() && resultPoint0.GetY() == inputPoint.GetY());
            // GetNearestCoordinate for Polyline
            com.epl.geometry.Polyline polyline = MakePolyline();
            result0      = com.epl.geometry.GeometryEngine.GetNearestCoordinate(polyline, inputPoint, true);
            resultPoint0 = result0.GetCoordinate();
            NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == 0.0 && resultPoint0.GetY() == 2.0);
            com.epl.geometry.Polygon pp = new com.epl.geometry.Polygon();
            pp.StartPath(0, 0);
            pp.LineTo(0, 10);
            pp.LineTo(10, 10);
            pp.LineTo(10, 0);
            inputPoint.SetXY(15, -5);
            result0 = proximityOp.GetNearestCoordinate(pp, inputPoint, true, true);
            bool is_right = result0.IsRightSide();

            NUnit.Framework.Assert.IsTrue(!is_right);
        }
Esempio n. 8
0
        internal virtual com.epl.geometry.Proximity2DResult MultiPathGetNearestCoordinate(com.epl.geometry.MultiPath geom, com.epl.geometry.Point2D inputPoint, bool bTestPolygonInterior, bool bCalculateLeftRightSide)
        {
            if (geom.GetType() == com.epl.geometry.Geometry.Type.Polygon && bTestPolygonInterior)
            {
                com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D();
                geom.QueryEnvelope2D(env);
                double tolerance = com.epl.geometry.InternalUtils.CalculateToleranceFromGeometry(null, env, false);
                com.epl.geometry.PolygonUtils.PiPResult pipResult;
                if (bCalculateLeftRightSide)
                {
                    pipResult = com.epl.geometry.PolygonUtils.IsPointInPolygon2D((com.epl.geometry.Polygon)geom, inputPoint, 0.0);
                }
                else
                {
                    pipResult = com.epl.geometry.PolygonUtils.IsPointInPolygon2D((com.epl.geometry.Polygon)geom, inputPoint, tolerance);
                }
                if (pipResult != com.epl.geometry.PolygonUtils.PiPResult.PiPOutside)
                {
                    com.epl.geometry.Proximity2DResult result = new com.epl.geometry.Proximity2DResult(inputPoint, 0, 0.0);
                    if (bCalculateLeftRightSide)
                    {
                        result.SetRightSide(true);
                    }
                    return(result);
                }
            }
            com.epl.geometry.SegmentIterator segIter = geom.QuerySegmentIterator();
            com.epl.geometry.Point2D         closest = new com.epl.geometry.Point2D();
            int    closestVertexIndex = -1;
            int    closestPathIndex   = -1;
            double closestDistanceSq  = com.epl.geometry.NumberUtils.DoubleMax();
            bool   bRight             = false;
            int    num_candidates     = 0;

            while (segIter.NextPath())
            {
                while (segIter.HasNextSegment())
                {
                    com.epl.geometry.Segment segment = segIter.NextSegment();
                    double t = segment.GetClosestCoordinate(inputPoint, false);
                    com.epl.geometry.Point2D point = segment.GetCoord2D(t);
                    double distanceSq = com.epl.geometry.Point2D.SqrDistance(point, inputPoint);
                    if (distanceSq < closestDistanceSq)
                    {
                        num_candidates     = 1;
                        closest            = point;
                        closestVertexIndex = segIter.GetStartPointIndex();
                        closestPathIndex   = segIter.GetPathIndex();
                        closestDistanceSq  = distanceSq;
                    }
                    else
                    {
                        if (distanceSq == closestDistanceSq)
                        {
                            num_candidates++;
                        }
                    }
                }
            }
            com.epl.geometry.Proximity2DResult result_1 = new com.epl.geometry.Proximity2DResult(closest, closestVertexIndex, System.Math.Sqrt(closestDistanceSq));
            if (bCalculateLeftRightSide)
            {
                segIter.ResetToVertex(closestVertexIndex, closestPathIndex);
                com.epl.geometry.Segment segment = segIter.NextSegment();
                bRight = (com.epl.geometry.Point2D.OrientationRobust(inputPoint, segment.GetStartXY(), segment.GetEndXY()) < 0);
                if (num_candidates > 1)
                {
                    com.epl.geometry.OperatorProximity2DLocal.Side_helper sideHelper = new com.epl.geometry.OperatorProximity2DLocal.Side_helper(this);
                    sideHelper.Reset();
                    bRight = sideHelper.Calc_side(inputPoint, bRight, geom, closestVertexIndex, closestPathIndex);
                }
                result_1.SetRightSide(bRight);
            }
            return(result_1);
        }
Esempio n. 9
0
 /// <summary>
 /// Finds nearest vertex on the geometry which is closed to the specified
 /// point.
 /// </summary>
 /// <remarks>
 /// Finds nearest vertex on the geometry which is closed to the specified
 /// point.
 /// See OperatorProximity2D.
 /// </remarks>
 /// <param name="inputPoint">The point to find the nearest vertex of the geometry for.</param>
 /// <param name="geometry">The geometry to consider.</param>
 /// <returns>Proximity2DResult containing the nearest vertex.</returns>
 public static com.epl.geometry.Proximity2DResult GetNearestVertex(com.epl.geometry.Geometry geometry, com.epl.geometry.Point inputPoint)
 {
     com.epl.geometry.OperatorProximity2D proximity = (com.epl.geometry.OperatorProximity2D)factory.GetOperator(com.epl.geometry.Operator.Type.Proximity2D);
     com.epl.geometry.Proximity2DResult   result    = proximity.GetNearestVertex(geometry, inputPoint);
     return(result);
 }
Esempio n. 10
0
 /// <summary>
 /// Finds the coordinate of the geometry which is closest to the specified
 /// point.
 /// </summary>
 /// <remarks>
 /// Finds the coordinate of the geometry which is closest to the specified
 /// point.
 /// See OperatorProximity2D.
 /// </remarks>
 /// <param name="inputPoint">The point to find the nearest coordinate in the geometry for.</param>
 /// <param name="geometry">The geometry to consider.</param>
 /// <returns>Proximity2DResult containing the nearest coordinate.</returns>
 public static com.epl.geometry.Proximity2DResult GetNearestCoordinate(com.epl.geometry.Geometry geometry, com.epl.geometry.Point inputPoint, bool bTestPolygonInterior)
 {
     com.epl.geometry.OperatorProximity2D proximity = (com.epl.geometry.OperatorProximity2D)factory.GetOperator(com.epl.geometry.Operator.Type.Proximity2D);
     com.epl.geometry.Proximity2DResult   result    = proximity.GetNearestCoordinate(geometry, inputPoint, bTestPolygonInterior);
     return(result);
 }