コード例 #1
0
        /// <summary>
        /// This will get the neighbour cells on the same level of resolution
        /// </summary>
        /// <param name="direction">Direction where to look for the neighbour</param>
        /// <param name="onlySameResolution">If this is true and node of the same
        /// resolution doesn't exist as a neighbour NULL will be returned</param>
        /// <returns>neighbouring cell on the same or lower level of resolution or null.</returns>
        public XbimOctree <T> GetNeighbour(XbimDirectionEnum direction, bool onlySameResolution)
        {
            //if there is no parent there are no neighbours
            if (parent == null)
            {
                return(null);
            }
            int[] directionCode = new int[] { 0, 0, 0 };
            switch (direction)
            {
            case XbimDirectionEnum.WEST:
                directionCode = new int[] { -1, 0, 0 };
                break;

            case XbimDirectionEnum.EAST:
                directionCode = new int[] { 1, 0, 0 };
                break;

            case XbimDirectionEnum.NORTH:
                directionCode = new int[] { 0, 1, 0 };
                break;

            case XbimDirectionEnum.SOUTH:
                directionCode = new int[] { 0, -1, 0 };
                break;

            case XbimDirectionEnum.UP:
                directionCode = new int[] { 0, 0, 1 };
                break;

            case XbimDirectionEnum.DOWN:
                directionCode = new int[] { 0, 0, -1 };
                break;

            default:
                break;
            }

            if (localAddress.IsStillIn(directionCode))
            {
                //moved address is still within the same parent
                return(parent.GetChild(localAddress.Move(directionCode)));
            }
            else
            {
                //this is recursive call drilling up in the tree to get neighbour from the next branch
                var masterNeighbour = parent.GetNeighbour(direction, onlySameResolution);
                if (masterNeighbour != null)
                {
                    //if there is master neighbour but there is not a child it just means that there is
                    //nothing in the same level of resolution. But higher resolution shouldn't be ignored.
                    return
                        (masterNeighbour.GetChild(localAddress.Move(directionCode)) ??
                         masterNeighbour);
                }
            }

            return(null);
        }
コード例 #2
0
        public XbimOctree <T> GetCommonParentInDirection(XbimDirectionEnum direction, bool controlRange)
        {
            //if there is no parent there are no neighbours
            if (parent == null)
            {
                return(null);
            }
            int[] directionCode = new int[] { 0, 0, 0 };
            switch (direction)
            {
            case XbimDirectionEnum.WEST:
                directionCode = new int[] { -1, 0, 0 };
                break;

            case XbimDirectionEnum.EAST:
                directionCode = new int[] { 1, 0, 0 };
                break;

            case XbimDirectionEnum.NORTH:
                directionCode = new int[] { 0, 1, 0 };
                break;

            case XbimDirectionEnum.SOUTH:
                directionCode = new int[] { 0, -1, 0 };
                break;

            case XbimDirectionEnum.UP:
                directionCode = new int[] { 0, 0, 1 };
                break;

            case XbimDirectionEnum.DOWN:
                directionCode = new int[] { 0, 0, -1 };
                break;

            default:
                break;
            }

            if (localAddress.IsStillIn(directionCode))
            {
                //moved address is still within the same parent
                return(parent);
            }
            else if (parent != null)
            {
                //this is recursive call drilling up in the tree
                return(parent.GetCommonParentInDirection(direction, controlRange));
            }

            if (controlRange)
            {
                throw new IndexOutOfRangeException("Direction goes out of the tree world.");
            }
            else
            {
                return(null);
            }
        }