예제 #1
0
        public void FindNearestEpsilonOverlap()
        {
            var points = new PointD[100];

            for (int i = 0; i < points.Length; i++)
            {
                points[i] = new PointD((i % 10) / 10.0, i / 10);
            }

            // unpredictable sorting since epsilon overlaps point distances
            var comparer = new PointDComparerY()
            {
                Epsilon = 0.2
            };

            Array.Sort <PointD>(points, comparer.Compare);

            for (int i = 0; i < points.Length; i++)
            {
                PointD q = points[i];
                Assert.AreEqual(i, comparer.FindNearest(points, q));

                /*
                 * Since epsilon overlaps adjacent points, sorting is unpredictable
                 * and we cannot know which index contains the point nearest to a
                 * non-collection point. So we use brute force to find that index.
                 */
                q = new PointD(q.X + 0.1, q.Y - 0.1);
                int index = GeoAlgorithms.NearestPoint(points, q);
                Assert.AreEqual(index, comparer.FindNearest(points, q));

                q     = new PointD(q.X - 0.4, q.Y + 0.4);
                index = GeoAlgorithms.NearestPoint(points, q);
                Assert.AreEqual(index, comparer.FindNearest(points, q));
            }
        }