Esempio n. 1
0
        public PathFinderFast(byte[,] grid)
        {
            if (grid == null)
            {
                throw new Exception("Grid cannot be null");
            }

            mGrid        = grid;
            mGridX       = (ushort)(mGrid.GetUpperBound(0) + 1);
            mGridY       = (ushort)(mGrid.GetUpperBound(1) + 1);
            mGridXMinus1 = (ushort)(mGridX - 1);
            mGridYLog2   = (ushort)Math.Log(mGridY, 2);

            // This should be done at the constructor, for now we leave it here.
            if (Math.Log(mGridX, 2) != (int)Math.Log(mGridX, 2) ||
                Math.Log(mGridY, 2) != (int)Math.Log(mGridY, 2))
            {
                throw new Exception("Invalid Grid, size in X and Y must be power of 2");
            }

            //if (mCalcGrid == null || mCalcGrid.Length != (mGridX * mGridY))
            if (mCalcGrid == null || mCalcGrid.Length < (mGridX * mGridY))
            {
                mCalcGrid = new PathFinderNodeFast[mGridX * mGridY];
            }

            mOpen = new PriorityQueueB <int>(new ComparePFNodeMatrix(mCalcGrid));
        }