public void TestLimitDistance()
        {
            IncrementalDistanceSearch <Vector> ids = new IncrementalDistanceSearch <Vector>(_tree.Root);

            ids.DistanceLimit = 0.1;
            ids.CountLimit    = 2;
            List <Vector> ordered = new List <Vector>(ids.Find(Vector.Create(-1.0, -1.0)));

            Assert.AreEqual(1, ordered.Count);
            Assert.IsTrue(VectorComparison.Equal(ordered[0], _vecs[0]));


            ordered = new List <Vector>(ids.Find(Vector.Create(5.0, 5.0)));
            Assert.AreEqual(0, ordered.Count);
        }
        public void TestNoLimits()
        {
            IncrementalDistanceSearch <Vector> ids = new IncrementalDistanceSearch <Vector>(_tree.Root);
            List <Vector> ordered = new List <Vector>(ids.Find(Vector.Create(-1.0, -1.0)));

            Assert.AreEqual(ordered.Count, 4);
            Assert.IsTrue(VectorComparison.Equal(ordered[0], _vecs[0]));
            Assert.IsTrue(VectorComparison.Equal(ordered[1], _vecs[1]));
            Assert.IsTrue(VectorComparison.Equal(ordered[2], _vecs[2]));
            Assert.IsTrue(VectorComparison.Equal(ordered[3], _vecs[3]));

            ordered = new List <Vector>(ids.Find(Vector.Create(5.0, 5.0)));
            Assert.IsTrue(VectorComparison.Equal(ordered[0], _vecs[3]));
            Assert.IsTrue(VectorComparison.Equal(ordered[1], _vecs[2]));
            Assert.IsTrue(VectorComparison.Equal(ordered[2], _vecs[1]));
            Assert.IsTrue(VectorComparison.Equal(ordered[3], _vecs[0]));
        }
Пример #3
0
        public void TestConversionInSearch()
        {
            KdMap <Vector, string> map = new KdMap <Vector, string>(1);

            map[Vector.Create(0.0)] = "a";
            map[Vector.Create(1.0)] = "b";
            map[Vector.Create(2.0)] = "c";

            IncrementalDistanceSearch <LocatablePair <Vector, string> > s =
                new IncrementalDistanceSearch <LocatablePair <Vector, string> >(map.KdTree.Root);

            IEnumerable <LocatablePair <Vector, string> > e = (IEnumerable <LocatablePair <Vector, string> >)s.Find(Vector.Create(3.0));

            List <KeyValuePair <Vector, string> > l = new List <KeyValuePair <Vector, string> >((IEnumerable <KeyValuePair <Vector, string> >)e);

            Assert.AreEqual("c", l[0].Value);
            Assert.AreEqual("b", l[0].Value);
            Assert.AreEqual("a", l[0].Value);
        }