public Vector3 GetPosition(int u, int v)
    {
        float xLength = ((float)(maxPoint.GetX() - minPoint.GetX())) / (float)(sizeV);
        float yLength = ((float)(maxPoint.GetY() - minPoint.GetY())) / (float)(sizeU);

        return(new Vector3(v * xLength + (float)minPoint.GetX(), 0f, (float)maxPoint.GetY() - u * yLength));
    }
    DGPointPairClass GetMinMax()
    {
        DGPointPairClass toReturn = new DGPointPairClass();
        DGPointClass     rMin     = rooms[0].GetCorner(0);
        DGPointClass     rMax     = rooms[0].GetCorner(2);

        toReturn.point01 = new DGPointClass(rMin);
        toReturn.point02 = new DGPointClass(rMax);
        foreach (DGRoomClass room in rooms)
        {
            rMin = room.GetCorner(0);
            rMax = room.GetCorner(2);
            if (rMin.GetX() < toReturn.point01.GetX())
            {
                toReturn.point01.SetX(rMin.GetX());
            }
            if (rMin.GetY() < toReturn.point01.GetY())
            {
                toReturn.point01.SetY(rMin.GetY());
            }

            if (rMax.GetX() > toReturn.point02.GetX())
            {
                toReturn.point02.SetX(rMax.GetX());
            }
            if (rMax.GetY() > toReturn.point02.GetY())
            {
                toReturn.point02.SetY(rMax.GetY());
            }
        }

        foreach (DGRoomClass coridor in coridors)
        {
            rMin = coridor.GetCorner(0);
            rMax = coridor.GetCorner(2);
            if (rMin.GetX() < toReturn.point01.GetX())
            {
                toReturn.point01.SetX(rMin.GetX());
            }
            if (rMin.GetY() < toReturn.point01.GetY())
            {
                toReturn.point01.SetY(rMin.GetY());
            }

            if (rMax.GetX() > toReturn.point02.GetX())
            {
                toReturn.point02.SetX(rMax.GetX());
            }
            if (rMax.GetY() > toReturn.point02.GetY())
            {
                toReturn.point02.SetY(rMax.GetY());
            }
        }

        //Debug.Log("Minimum: " + toReturn.point01.ToString() + " Maximum: " + toReturn.point02.ToString());

        return(toReturn);
    }
 void BuildCornersArray()
 {
     cornersArray    = new Vector3[5];
     cornersArray[0] = new Vector3(cornerBL.GetX(), 0, cornerBL.GetY());
     cornersArray[1] = new Vector3(cornerTL.GetX(), 0, cornerTL.GetY());
     cornersArray[2] = new Vector3(cornerTR.GetX(), 0, cornerTR.GetY());
     cornersArray[3] = new Vector3(cornerBR.GetX(), 0, cornerBR.GetY());
     cornersArray[4] = new Vector3(cornerBL.GetX(), 0, cornerBL.GetY());
 }
    void RecalculateCorners()
    {
        cornerBL = new DGPointClass(center.GetX() - horizontalSize / 2, center.GetY() - verticalSize / 2);
        cornerBR = new DGPointClass(cornerBL.GetX() + horizontalSize, cornerBL.GetY());
        cornerTL = new DGPointClass(cornerBL.GetX(), cornerBL.GetY() + verticalSize);
        cornerTR = new DGPointClass(cornerBL.GetX() + horizontalSize, cornerBL.GetY() + verticalSize);

        BuildCornersArray();
    }
    public DGRoomClass(DGPointClass blCorner, DGPointClass trCorner)
    {
        cornerBL = new DGPointClass(Mathf.Min(blCorner.GetX(), trCorner.GetX()), Mathf.Min(blCorner.GetY(), trCorner.GetY()));
        cornerTR = new DGPointClass(Mathf.Max(blCorner.GetX(), trCorner.GetX()), Mathf.Max(blCorner.GetY(), trCorner.GetY()));


        cornerTL = new DGPointClass(cornerBL.GetX(), cornerTR.GetY());
        cornerBR = new DGPointClass(cornerTR.GetX(), cornerBL.GetY());

        BuildCornersArray();

        verticalSize   = cornerTL.GetY() - cornerBL.GetY();
        horizontalSize = cornerBR.GetX() - cornerBL.GetX();
        center         = new DGPointClass(cornerBL.GetX() + horizontalSize / 2, cornerBL.GetY() + verticalSize / 2);
    }
    public void FillByRoom(DGRoomClass room, bool isCoridor)
    {
        DGPointClass min = room.GetCorner(0);
        DGPointClass max = room.GetCorner(2);

        for (int i = maxPoint.GetY() - max.GetY(); i < maxPoint.GetY() - min.GetY(); i++)
        {
            for (int j = min.GetX() - minPoint.GetX(); j < max.GetX() - minPoint.GetX(); j++)
            {
                /*if(isCoridor)
                 * {
                 *  Debug.Log("Add to " + i.ToString() + " " + j.ToString());
                 * }*/
                map[i, j] = true;
            }
        }
    }
    public bool IsPointInside(DGPointClass point)
    {
        if (point.GetX() >= cornerBL.GetX() && point.GetX() <= cornerBR.GetX() && point.GetY() >= cornerBL.GetY() && point.GetY() <= cornerTL.GetY())
        {
            return(true);
        }

        return(false);
    }
    public bool IsIntersect(DGRoomClass room)
    {
        //проверяем, лежат ли углы первой комнаты во второй, а потом углы вторй в первой. Если хотя бы один раз да - то есть пересечение
        if (IsPointInside(room.GetCorner(0)) || IsPointInside(room.GetCorner(1)) || IsPointInside(room.GetCorner(2)) || IsPointInside(room.GetCorner(3)) ||
            room.IsPointInside(cornerBL) || room.IsPointInside(cornerTL) || room.IsPointInside(cornerTR) || room.IsPointInside(cornerBR))
        {
            return(true);
        }
        //дальше проверяем, не накладываются ли они друг на друга. Для этого смотрим, центр второй комнаты должен лежать либо на горизоантали, либо на вертикали первой комнаты
        DGPointClass c = room.GetCenter();

        if ((c.GetX() >= cornerBL.GetX() && c.GetX() <= cornerBR.GetX() && center.GetY() >= room.GetCorner(0).GetY() && center.GetY() <= room.GetCorner(1).GetY()) ||
            (c.GetY() >= cornerBL.GetY() && c.GetY() <= cornerTL.GetY() && center.GetX() >= room.GetCorner(0).GetX() && center.GetX() <= room.GetCorner(3).GetX()))
        {
            return(true);
        }

        return(false);
    }
 public float GetDistance(DGPointClass point)
 {
     return(Mathf.Sqrt((point.GetX() - x) * (point.GetX() - x) + (point.GetY() - y) * (point.GetY() - y)));
 }
 public DGPointClass(DGPointClass point)
 {
     x = point.GetX();
     y = point.GetY();
 }