public DGRoomClass(int centerX, int centerY, int sizeH, int sizeV)
 {
     center         = new DGPointClass(centerX, centerY);
     horizontalSize = sizeH;
     verticalSize   = sizeV;
     RecalculateCorners();
 }
    public DGRoomClass()
    {
        center         = new DGPointClass();
        horizontalSize = 0;
        verticalSize   = 0;

        RecalculateCorners();
    }
예제 #3
0
    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);
    }
    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);
    }
    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();
    }
예제 #6
0
    public DGMap(int u, int v, DGPointClass min, DGPointClass max)
    {
        map      = new bool[u, v];
        minPoint = new DGPointClass(min);
        maxPoint = new DGPointClass(max);

        sizeU = u;
        sizeV = v;
    }
    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);
    }
예제 #8
0
    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 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();
 }