예제 #1
0
        /// <summary>
        /// Creates the covering rectangle of the node that encloses
        /// a point at a given depth in the index tree.
        /// </summary>
        /// <param name="p">The point of interest</param>
        /// <param name="depth">The 0-based tree depth (specify 0 when dealing
        /// with the root node)</param>
        /// <returns>The covering rectangle enclosing the point at the requested depth</returns>
        Extent CreateWindow(IPoint p, int depth)
        {
            if (depth == 0)
            {
                return(new Extent());
            }

            ulong x = SpatialIndex.ToUnsigned(p.Geometry.Easting.Microns);
            ulong y = SpatialIndex.ToUnsigned(p.Geometry.Northing.Microns);

            // The lower-left corner is given by masking out the low-order bits (neat)
            ulong size = Node.SIZES[depth];
            ulong mask = size ^ 0xFFFFFFFFFFFFFFFF;

            ulong minx = (x & mask);
            ulong miny = (y & mask);
            ulong maxx = minx + size;
            ulong maxy = miny + size;

            Debug.Assert(maxx > minx);
            Debug.Assert(maxy > miny);

            return(new Extent(minx, miny, maxx, maxy));
        }