/// <summary>
 /// enlarge the size of quadrant
 /// copies original values
 /// </summary>
 /// <param name="quadrant"></param>
 public void DoubleSizeOf(ref MountainPeaks[,] quadrant, int quadrantNumber)
 {
     int newQuadrantSize = (int)Math.Sqrt(quadrant.Length) * 2;
     MountainPeaks[,] newQuadrant = new MountainPeaks[newQuadrantSize, newQuadrantSize];
     for (int x = 0; x < newQuadrantSize; x++)
     {
         for (int z = 0; z < newQuadrantSize; z++)
         {
             if (x < newQuadrantSize / 2 && z < newQuadrantSize / 2)
             {
                 newQuadrant[x, z] = quadrant[x, z];
             }
             else
             {
                 if (quadrantNumber == 1)
                     newQuadrant[x, z] = new MountainPeaks(x, z, gm.GetPointArea(x, z), mpm);
                 else if (quadrantNumber == 2)
                     newQuadrant[x, z] = new MountainPeaks(-x, z, gm.GetPointArea(-x, z), mpm);
                 else if (quadrantNumber == 3)
                     newQuadrant[x, z] = new MountainPeaks(-x, -z, gm.GetPointArea(-x, -z), mpm);
                 else if (quadrantNumber == 4)
                     newQuadrant[x, z] = new MountainPeaks(x, -z, gm.GetPointArea(x, -z), mpm);
             }
         }
     }
     quadrant = newQuadrant;
 }
    public MountainPeaksCoordinates(int quadrantSize, GridManager gridManager, MountainPeaksManager mountainPeaksManager)
    {
        gm = gridManager;
        mpm = mountainPeaksManager;

        globalCenter = new MountainPeaks(0,0, gm.GetPointArea(0,0), mpm);

        quadrant1 = new MountainPeaks[quadrantSize, quadrantSize];
        quadrant2 = new MountainPeaks[quadrantSize, quadrantSize];
        quadrant3 = new MountainPeaks[quadrantSize, quadrantSize];
        quadrant4 = new MountainPeaks[quadrantSize, quadrantSize];

        InitialiseQuadrant(quadrant1, 1);
        InitialiseQuadrant(quadrant2, 2);
        InitialiseQuadrant(quadrant3, 3);
        InitialiseQuadrant(quadrant4, 4);
    }
    public void SetValue(int x, int z, MountainPeaks mountainPeaks, bool overwrite)
    {
        while (!CheckIfQuadrantDefined(x, z))
        {
            //Debug.Log(x + "," + z + ": SMALL");
            DoubleSizeOfQuadrant(GetQuandrantNumber(x, z));
        }

        //do not overwite if it is already set
        if (!overwrite && IsDefined(x, z))
            return;

        if (x == 0 && z == 0)
        {
            globalCenter = mountainPeaks;
        }
        else
        {
            GetQuandrant(x, z)[Math.Abs(x), Math.Abs(z)] = mountainPeaks;
        }
    }
 public void InitialiseQuadrant(MountainPeaks[,] quadrant, int quadrantNumber)
 {
     //can't acces array size with quadrant[0].Length
     for (int x = 0; x < Math.Sqrt(quadrant.Length); x++)
     {
         for (int z = 0; z < Math.Sqrt(quadrant.Length); z++)
         {
             if(quadrantNumber == 1)
                 quadrant[x, z] = new MountainPeaks(x,z, gm.GetPointArea(x,z),mpm);
             else if (quadrantNumber == 2)
                 quadrant[x, z] = new MountainPeaks(-x, z, gm.GetPointArea(-x, z), mpm);
             else if (quadrantNumber == 3)
                 quadrant[x, z] = new MountainPeaks(-x, -z, gm.GetPointArea(-x, -z), mpm);
             else if (quadrantNumber == 4)
                 quadrant[x, z] = new MountainPeaks(x, -z, gm.GetPointArea(x, -z), mpm);
         }
     }
 }