Exemplo n.º 1
0
        public void TestDecode(int index, int x, int y)
        {
            var p = MortonCode.Decode(index);

            Assert.That(p.X, Is.EqualTo(x));
            Assert.That(p.Y, Is.EqualTo(y));
        }
Exemplo n.º 2
0
        public void TestDecodeEncode(int level)
        {
            int n = MortonCode.Size(level);

            for (int i = 0; i < n; i++)
            {
                var p      = MortonCode.Decode(i);
                int encode = MortonCode.Encode((int)p.X, (int)p.Y);
                Assert.That(encode, Is.EqualTo(i));
            }
        }
        public static Geometry SortByMortonCode(Geometry g)
        {
            var geoms = Components(g);
            var env   = g.EnvelopeInternal;
            // use level one less than max to avoid hitting negative integers
            int level  = 15;
            int maxOrd = MortonCode.MaxOrdinate(level);

            double strideX = env.Width / maxOrd;
            double strideY = env.Height / maxOrd;

            foreach (var geom in geoms)
            {
                var centre = geom.EnvelopeInternal.Centre;
                int x      = (int)((centre.X - env.MinX) / strideX);
                int y      = (int)((centre.Y - env.MinY) / strideY);
                int code   = MortonCode.Encode(x, y);
                geom.UserData = code;
            }

            geoms.Sort(UserDataIntComparator.Instance);

            return(g.Factory.BuildGeometry(geoms));
        }
Exemplo n.º 4
0
 public void TestLevel(int size, int expectedLevel)
 {
     Assert.That(MortonCode.Level(size), Is.EqualTo(expectedLevel));
 }
Exemplo n.º 5
0
 public void TestSize(int level, int expectedSize)
 {
     Assert.That(MortonCode.Size(level), Is.EqualTo(expectedSize));
 }