Exemplo n.º 1
0
        private QuadTreeNode CreateAndSetNode(SubNodeIndex subNodeIndex)
        {
            var x = this.Position.X;
            var y = this.Position.Y;

            var subSize           = (ushort)(this.Size / 2);
            var subSizePowerOfTwo = (byte)(this.sizePowerOfTwo - 1);

            switch (subNodeIndex)
            {
            case SubNodeIndex.BottomLeft:
                return(this.subNodeBottomLeft = new QuadTreeNode(new Vector2Int(x, y), subSizePowerOfTwo));

            case SubNodeIndex.BottomRight:
                return(this.subNodeBottomRight = new QuadTreeNode(new Vector2Int(x + subSize, y), subSizePowerOfTwo));

            case SubNodeIndex.TopLeft:
                return(this.subNodeTopLeft = new QuadTreeNode(new Vector2Int(x, y + subSize), subSizePowerOfTwo));

            case SubNodeIndex.TopRight:
                return(this.subNodeTopRight = new QuadTreeNode(new Vector2Int(x + subSize, y + subSize), subSizePowerOfTwo));

            default:
                throw new ArgumentOutOfRangeException(nameof(subNodeIndex), subNodeIndex, null);
            }
        }
Exemplo n.º 2
0
        public QuadTreeNode GetSubNode(SubNodeIndex subNodeIndex)
        {
            switch (subNodeIndex)
            {
            case SubNodeIndex.BottomLeft:
                return(this.subNodeBottomLeft);

            case SubNodeIndex.BottomRight:
                return(this.subNodeBottomRight);

            case SubNodeIndex.TopLeft:
                return(this.subNodeTopLeft);

            case SubNodeIndex.TopRight:
                return(this.subNodeTopRight);

            default:
                throw new ArgumentOutOfRangeException(nameof(subNodeIndex), subNodeIndex, null);
            }
        }
Exemplo n.º 3
0
        private void DestroySubNode(SubNodeIndex subNodeIndex)
        {
            switch (subNodeIndex)
            {
            case SubNodeIndex.BottomLeft:
                this.subNodeBottomLeft = null;
                break;

            case SubNodeIndex.BottomRight:
                this.subNodeBottomRight = null;
                break;

            case SubNodeIndex.TopLeft:
                this.subNodeTopLeft = null;
                break;

            case SubNodeIndex.TopRight:
                this.subNodeTopRight = null;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(subNodeIndex), subNodeIndex, null);
            }
        }