public void RTreeMemoryIndexSmall1Tests()
        {
            var rect1 = new BoxF2D(0, 0, 2, 2);
            var rect2 = new BoxF2D(4, 0, 6, 2);
            var rect3 = new BoxF2D(0, 4, 2, 6);
            var rect4 = new BoxF2D(4, 4, 6, 6);

            var rect5 = new BoxF2D(1, 1, 3, 3);

            // create the index and reference index.
            var index = new RTreeMemoryIndex<string>(4, 1);

            // add data.
            index.Add(rect1, rect1.ToString() + "1");
            index.Add(rect1, rect1.ToString() + "2");
            index.Add(rect1, rect1.ToString() + "3");
            index.Add(rect1, rect1.ToString() + "4");

            index.Add(rect2, rect2.ToString() + "1");
            index.Add(rect2, rect2.ToString() + "2");
            index.Add(rect2, rect2.ToString() + "3");
            index.Add(rect2, rect2.ToString() + "4");

            index.Add(rect3, rect3.ToString() + "1");
            index.Add(rect3, rect3.ToString() + "2");
            index.Add(rect3, rect3.ToString() + "3");
            index.Add(rect3, rect3.ToString() + "4");

            index.Add(rect4, rect4.ToString() + "1");
            index.Add(rect4, rect4.ToString() + "2");
            index.Add(rect4, rect4.ToString() + "3");
            index.Add(rect4, rect4.ToString() + "4");

            index.Add(rect5, rect5.ToString());

            // some simple queries.
            var result = new HashSet<string>(
                index.Get(rect4));
            Assert.AreEqual(4, result.Count);
            Assert.IsTrue(result.Contains(rect4.ToString() + "1"));
            Assert.IsTrue(result.Contains(rect4.ToString() + "2"));
            Assert.IsTrue(result.Contains(rect4.ToString() + "3"));
            Assert.IsTrue(result.Contains(rect4.ToString() + "4"));

            result = new HashSet<string>(
                index.Get(rect3));
            Assert.AreEqual(4, result.Count);
            Assert.IsTrue(result.Contains(rect3.ToString() + "1"));
            Assert.IsTrue(result.Contains(rect3.ToString() + "2"));
            Assert.IsTrue(result.Contains(rect3.ToString() + "3"));
            Assert.IsTrue(result.Contains(rect3.ToString() + "4"));

            result = new HashSet<string>(
                index.Get(rect2));
            Assert.AreEqual(4, result.Count);
            Assert.IsTrue(result.Contains(rect2.ToString() + "1"));
            Assert.IsTrue(result.Contains(rect2.ToString() + "2"));
            Assert.IsTrue(result.Contains(rect2.ToString() + "3"));
            Assert.IsTrue(result.Contains(rect2.ToString() + "4"));

            result = new HashSet<string>(
                index.Get(rect1));
            Assert.AreEqual(5, result.Count);
            Assert.IsTrue(result.Contains(rect1.ToString() + "1"));
            Assert.IsTrue(result.Contains(rect1.ToString() + "2"));
            Assert.IsTrue(result.Contains(rect1.ToString() + "3"));
            Assert.IsTrue(result.Contains(rect1.ToString() + "4"));
            Assert.IsTrue(result.Contains(rect5.ToString()));
        }
Exemplo n.º 2
0
        public void RTreeMemoryIndexSmall1Tests()
        {
            var rect1 = new BoxF2D(0, 0, 2, 2);
            var rect2 = new BoxF2D(4, 0, 6, 2);
            var rect3 = new BoxF2D(0, 4, 2, 6);
            var rect4 = new BoxF2D(4, 4, 6, 6);

            var rect5 = new BoxF2D(1, 1, 3, 3);

            // create the index and reference index.
            var index = new RTreeMemoryIndex <string>(4, 1);

            // add data.
            index.Add(rect1, rect1.ToString() + "1");
            index.Add(rect1, rect1.ToString() + "2");
            index.Add(rect1, rect1.ToString() + "3");
            index.Add(rect1, rect1.ToString() + "4");

            index.Add(rect2, rect2.ToString() + "1");
            index.Add(rect2, rect2.ToString() + "2");
            index.Add(rect2, rect2.ToString() + "3");
            index.Add(rect2, rect2.ToString() + "4");

            index.Add(rect3, rect3.ToString() + "1");
            index.Add(rect3, rect3.ToString() + "2");
            index.Add(rect3, rect3.ToString() + "3");
            index.Add(rect3, rect3.ToString() + "4");

            index.Add(rect4, rect4.ToString() + "1");
            index.Add(rect4, rect4.ToString() + "2");
            index.Add(rect4, rect4.ToString() + "3");
            index.Add(rect4, rect4.ToString() + "4");

            index.Add(rect5, rect5.ToString());

            // some simple queries.
            var result = new HashSet <string>(
                index.Get(rect4));

            Assert.AreEqual(4, result.Count);
            Assert.IsTrue(result.Contains(rect4.ToString() + "1"));
            Assert.IsTrue(result.Contains(rect4.ToString() + "2"));
            Assert.IsTrue(result.Contains(rect4.ToString() + "3"));
            Assert.IsTrue(result.Contains(rect4.ToString() + "4"));

            result = new HashSet <string>(
                index.Get(rect3));
            Assert.AreEqual(4, result.Count);
            Assert.IsTrue(result.Contains(rect3.ToString() + "1"));
            Assert.IsTrue(result.Contains(rect3.ToString() + "2"));
            Assert.IsTrue(result.Contains(rect3.ToString() + "3"));
            Assert.IsTrue(result.Contains(rect3.ToString() + "4"));

            result = new HashSet <string>(
                index.Get(rect2));
            Assert.AreEqual(4, result.Count);
            Assert.IsTrue(result.Contains(rect2.ToString() + "1"));
            Assert.IsTrue(result.Contains(rect2.ToString() + "2"));
            Assert.IsTrue(result.Contains(rect2.ToString() + "3"));
            Assert.IsTrue(result.Contains(rect2.ToString() + "4"));

            result = new HashSet <string>(
                index.Get(rect1));
            Assert.AreEqual(5, result.Count);
            Assert.IsTrue(result.Contains(rect1.ToString() + "1"));
            Assert.IsTrue(result.Contains(rect1.ToString() + "2"));
            Assert.IsTrue(result.Contains(rect1.ToString() + "3"));
            Assert.IsTrue(result.Contains(rect1.ToString() + "4"));
            Assert.IsTrue(result.Contains(rect5.ToString()));
        }
Exemplo n.º 3
0
        public void RTreeStreamSerializeSmallTest()
        {
            var rect1 = new BoxF2D(0, 0, 2, 2);
            var rect2 = new BoxF2D(4, 0, 6, 2);
            var rect3 = new BoxF2D(0, 4, 2, 6);
            var rect4 = new BoxF2D(4, 4, 6, 6);

            // create the index and reference index.
            var index = new RTreeMemoryIndex <string>();

            // add data.
            index.Add(rect1, rect1.ToString() + "1");
            index.Add(rect1, rect1.ToString() + "2");
            index.Add(rect1, rect1.ToString() + "3");
            index.Add(rect1, rect1.ToString() + "4");

            index.Add(rect2, rect2.ToString() + "1");
            index.Add(rect2, rect2.ToString() + "2");
            index.Add(rect2, rect2.ToString() + "3");
            index.Add(rect2, rect2.ToString() + "4");

            index.Add(rect3, rect3.ToString() + "1");
            index.Add(rect3, rect3.ToString() + "2");
            index.Add(rect3, rect3.ToString() + "3");
            index.Add(rect3, rect3.ToString() + "4");

            index.Add(rect4, rect4.ToString() + "1");
            index.Add(rect4, rect4.ToString() + "2");
            index.Add(rect4, rect4.ToString() + "3");
            index.Add(rect4, rect4.ToString() + "4");

            var stream     = new MemoryStream();
            var serializer = new DataTestClassSerializer();

            serializer.Serialize(stream, index);

            ISpatialIndexReadonly <string> deserialized =
                serializer.Deserialize(stream, true);

            // some simple queries.
            var result = new HashSet <string>(
                deserialized.Get(rect4));

            Assert.AreEqual(4, result.Count);
            Assert.IsTrue(result.Contains(rect4.ToString() + "1"));
            Assert.IsTrue(result.Contains(rect4.ToString() + "2"));
            Assert.IsTrue(result.Contains(rect4.ToString() + "3"));
            Assert.IsTrue(result.Contains(rect4.ToString() + "4"));

            result = new HashSet <string>(
                deserialized.Get(rect3));
            Assert.AreEqual(4, result.Count);
            Assert.IsTrue(result.Contains(rect3.ToString() + "1"));
            Assert.IsTrue(result.Contains(rect3.ToString() + "2"));
            Assert.IsTrue(result.Contains(rect3.ToString() + "3"));
            Assert.IsTrue(result.Contains(rect3.ToString() + "4"));

            result = new HashSet <string>(
                deserialized.Get(rect2));
            Assert.AreEqual(4, result.Count);
            Assert.IsTrue(result.Contains(rect2.ToString() + "1"));
            Assert.IsTrue(result.Contains(rect2.ToString() + "2"));
            Assert.IsTrue(result.Contains(rect2.ToString() + "3"));
            Assert.IsTrue(result.Contains(rect2.ToString() + "4"));

            result = new HashSet <string>(
                deserialized.Get(rect1));
            Assert.AreEqual(4, result.Count);
            Assert.IsTrue(result.Contains(rect1.ToString() + "1"));
            Assert.IsTrue(result.Contains(rect1.ToString() + "2"));
            Assert.IsTrue(result.Contains(rect1.ToString() + "3"));
            Assert.IsTrue(result.Contains(rect1.ToString() + "4"));
        }