public void Compare()
        {
            double sumCn = 0;
            double sumWn = 0;

            for (int i = 0; i < tryCount; i++)
            {
                point   = RandomV2();
                polygon = new Vector2[10000];
                for (var j = 0; j < polygon.Length; j++)
                {
                    polygon[j] = RandomV2();
                }

                stopwatch.Restart();
                PointInPolygon.CrossingNumber(point, polygon);
                stopwatch.Stop();

                sumCn += stopwatch.Elapsed.TotalMilliseconds;

                stopwatch.Restart();
                PointInPolygon.WindingNumber(point, polygon);
                stopwatch.Stop();

                sumWn += stopwatch.Elapsed.TotalMilliseconds;
            }

            Console.WriteLine($"Crossing Number:    {sumCn / tryCount}ms");
            Console.WriteLine($"Winding Number:    {sumWn / tryCount}ms");
        }
Пример #2
0
    static public void Main(string[] args)
    {
        PointInPolygon PP = new PointInPolygon();
        string         userInput;


        WriteLine("Enter the values of [N x 2] array consisting the coordinates of N vertices of a polygon in 2D space");
        userInput = ReadLine();
        userInput = userInput.Replace("], [", " ").Replace("],", " ").Replace("[", "").Replace("]", "").Trim();
        userInput = Regex.Replace(userInput, @"\s+", " ");
        string[] polygonDataRaw = userInput.Split(' ');

        while (polygonDataRaw.Length < 3)
        {
            PP.numOfVertices = 0;
            WriteLine("Wrong number of coordinates ( Enter atleast 3 coordinates for the polygon ) or wrong format, please try again. ( FORMAT: [[1,0], [8,3], [8,8], [1,5]] )");
            WriteLine("Enter the values of [N x 2] array consisting the coordinates of N vertices of a polygon in 2D space");
            userInput      = ReadLine();
            userInput      = userInput.Replace("], [", " ").Replace("],", " ").Replace("[", "").Replace("]", "").Trim();
            userInput      = Regex.Replace(userInput, @"\s+", " ");
            polygonDataRaw = userInput.Split(' ');
        }
        PP.ProcessRawCoordinates(polygonDataRaw, 0);
        WriteLine("Enter the coordinates of point in 2D space");
        userInput = ReadLine();
        userInput = userInput.Replace("[", "").Replace("]", "");
        string[] pointCoordinatesRaw = userInput.Split(',');
        while (!(pointCoordinatesRaw.Length == 2))
        {
            WriteLine("Wrong number of coordinates or wrong format, please try again. ( FORMAT: [1,1] )");
            WriteLine("Enter the coordinates of point in 2D space");
            userInput           = ReadLine();
            pointCoordinatesRaw = userInput.Split(',');
        }
        PP.ProcessRawCoordinates(pointCoordinatesRaw, 1);
        bool result = PP.IsPointInPolygon();

        WriteLine("Output (Is point inside the polygon?): " + result);
    }
Пример #3
0
 /// <summary>
 /// Returns true if the given point lies within the ring.
 /// </summary>
 public static bool PointIn(List <Coordinate> ring, Coordinate point)
 {
     return(PointInPolygon.PointIn(ring, point));
 }
Пример #4
0
 /// <summary>
 /// Returns true if the given point lies within the polygon.
 ///
 /// Note that polygons spanning a pole, without a point at the pole itself, will fail to detect points within the polygon;
 /// (e.g. Polygon=[(lat=80°, 0), (80, 90), (80, 180)] will *not* detect the point (85, 90))
 /// </summary>
 public static bool PointIn(this Polygon poly, Coordinate point)
 {
     return(PointInPolygon.PointIn(poly, point));
 }
Пример #5
0
 /// <summary>
 /// Calculates a bounding box for the ring.
 /// </summary>
 public static void BoundingBox(this List <Coordinate> exteriorRing, out float north, out float east, out float south, out float west)
 {
     PointInPolygon.BoundingBox(exteriorRing, out north, out east, out south, out west);
 }