Esempio n. 1
0
 private static bool checkForTwoAreasIntersection(Area i, Area j)
 {
     int iw = i.get_width() + i.get_area_x(), ih = i.get_length() + i.get_area_y();
         int jw = j.get_width() + j.get_area_x(), jh = j.get_length() + j.get_area_y();
         if ((!((iw <= j.get_area_x()) || (jw <= i.get_area_x()))) && (!((ih <= j.get_area_y()) || (jh <= i.get_area_y()))))
         {
             return true;
         }
         else
         {
             return false;
         }
 }
Esempio n. 2
0
        private static List<Area> findAreas(int H, int W, List<Item> placed, List<Item> items)
        {
            List<Area> FreeAreas = new List<Area>();
                if (placed.Count == 0)
                {
                    FreeAreas.Add(new Area(H, W, 0, 0));
                }
                else
                {
                    for (int p = 0; p < placed.Count; p++)
                    {
                        int minX = W + 1;
                        int ptrt = -1;
                        int width = 0; //free space width
                        int pw = placed[p].get_width() + placed[p].get_item_x();
                        if (W - pw == 0)
                        {
                            continue;
                        }
                        int ph = placed[p].get_length() + placed[p].get_item_y();

                        for (int t = 0; t < placed.Count; t++)
                        {
                            if (p == t)
                            {
                                continue;
                            }
                            int th = placed[t].get_length() + placed[t].get_item_y();
                            if ((placed[t].get_item_x() >= pw) && (placed[t].get_item_x() - pw < minX) && !((placed[t].get_item_y() >= ph) || (th <= placed[p].get_item_y())))
                            {
                                ptrt = t;
                                minX = placed[t].get_item_x() - pw;
                            }
                        }
                        if (minX == 0)
                        {
                            continue;
                        }
                        if (minX > W)
                        {
                            width = W - pw;
                        }
                        if (minX < W)
                        {
                            width = minX;
                        }

                        int minY = H + 1;
                        int ptrs = -1;
                        int height = 0; //free space height

                        for (int s = 0; s < placed.Count; s++)
                        {
                            if (p == s)
                            {
                                continue;
                            }
                            int sw = placed[s].get_width() + placed[s].get_item_x();
                            if ((placed[s].get_item_y() >= placed[p].get_item_y()) && (placed[s].get_item_y() - placed[p].get_item_y() < minY) && !((sw <= pw) || (pw + width <= placed[s].get_item_x())))
                            {
                                ptrs = s;
                                minY = placed[s].get_item_y() - placed[p].get_item_y();
                            }
                        }

                        if (minY != 0)
                        {
                            if (minY > H)
                            {
                                height = H - placed[p].get_item_y();
                            }
                            if (minY < H)
                            {
                                height = minY;
                            }
                            Area newAreaa = new Area(height, width, placed[p].get_item_y(), pw);
                            if (checkForAreaUseless(height, width, items) && checkCheckForAreaExistence(newAreaa, FreeAreas))
                            {
                                FreeAreas.Add(newAreaa);
                            }
                        }

                        if (placed[p].get_item_y() == 0)
                        {
                            continue;
                        }

                        int minZ = H + 1;
                        int ptrd = -1;
                        int depth = 0; //free space height

                        for (int d = 0; d < placed.Count; d++)
                        {
                            if (p == d)
                            {
                                continue;
                            }
                            int dw = placed[d].get_width() + placed[d].get_item_x();
                            int dh = placed[d].get_length() + placed[d].get_item_y();
                            if ((dh <= placed[p].get_item_y()) && (placed[p].get_item_y() - dh < minZ) && !((dw <= pw) || (pw + width <= placed[d].get_item_x())))
                            {
                                ptrs = d;
                                minZ = placed[p].get_item_y() - dh;
                            }
                        }

                        if (minZ == 0)
                        {
                            continue;
                        }
                        if (minZ > H)
                        {
                            depth = height + placed[p].get_item_y();
                        }
                        if (minZ < H)
                        {
                            depth = height + minZ;
                        }
                        Area newArea = new Area(depth, width, placed[p].get_item_y() + height - depth, pw);
                        if (checkForAreaUseless(depth, width, items) && checkCheckForAreaExistence(newArea, FreeAreas))
                        {
                            FreeAreas.Add(newArea);
                        }
                    }

                    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

                    //镳钼屦赅 î‘"å±�å±™è�¾ï¿½ 疋屦躞 é"— ç–£ç�ˆå¦�å±™çœ�æ³�
                    for (int p = 0; p < placed.Count; p++)
                    {
                        int minY = H + 1;
                        int ptrt = -1;
                        int height = 0; //free space width
                        int ph = placed[p].get_length() + placed[p].get_item_y();
                        if (H - ph == 0)
                        {
                            continue;
                        }
                        int pw = placed[p].get_width() + placed[p].get_item_x();

                        for (int t = 0; t < placed.Count; t++)
                        {
                            if (p == t)
                            {
                                continue;
                            }
                            int tw = placed[t].get_width() + placed[t].get_item_x();
                            if ((placed[t].get_item_y() >= ph) && (placed[t].get_item_y() - ph < minY) && !((placed[t].get_item_x() >= pw) || (tw <= placed[p].get_item_x())))
                            {
                                ptrt = t;
                                minY = placed[t].get_item_y() - ph;
                            }
                        }
                        if (minY == 0)
                        {
                            continue;
                        }
                        if (minY > H)
                        {
                            height = H - ph;
                        }
                        if (minY < H)
                        {
                            height = minY;
                        }

                        int minX = W + 1;
                        int ptrs = -1;
                        int width = 0; //free space height

                        for (int s = 0; s < placed.Count; s++)
                        {
                            if (p == s)
                            {
                                continue;
                            }
                            int sh = placed[s].get_length() + placed[s].get_item_y();
                            if ((placed[s].get_item_x() >= placed[p].get_item_x()) && (placed[s].get_item_x() - placed[p].get_item_x() < minX) && !((sh <= ph) || (ph + height <= placed[s].get_item_y())))
                            {
                                ptrs = s;
                                minX = placed[s].get_item_x() - placed[p].get_item_x();
                            }
                        }

                        if (minX != 0)
                        {
                            if (minX > W)
                            {
                                width = W - placed[p].get_item_x();
                            }
                            if (minX < W)
                            {
                                width = minX;
                            }
                            Area newArea1 = new Area(height, width, ph, placed[p].get_item_x());
                            if (checkForAreaUseless(height, width, items) && checkCheckForAreaExistence(newArea1, FreeAreas))
                            {
                                FreeAreas.Add(newArea1);
                            }
                        }

                        if (placed[p].get_item_x() == 0)
                        {
                            continue;
                        }

                        int minZ = W + 1;
                        int ptrd = -1;
                        int depth = 0; //free space height

                        for (int d = 0; d < placed.Count; d++)
                        {
                            if (p == d)
                            {
                                continue;
                            }
                            int dw = placed[d].get_width() + placed[d].get_item_x();
                            int dh = placed[d].get_length() + placed[d].get_item_y();
                            if ((dw <= placed[p].get_item_x()) && (placed[p].get_item_x() - dw < minZ) && !((dh <= ph) || (ph + height <= placed[d].get_item_y())))
                            {
                                ptrs = d;
                                minZ = placed[p].get_item_x() - dw;
                            }
                        }

                        if (minZ == 0)
                        {
                            continue;
                        }
                        if (minZ > W)
                        {
                            depth = width + placed[p].get_item_x();
                        }
                        if (minZ < W)
                        {
                            depth = width + minZ;
                        }
                        Area newArea = new Area(height, depth, ph, placed[p].get_item_x() + width - depth);
                        if (checkForAreaUseless(height, depth, items) && checkCheckForAreaExistence(newArea, FreeAreas))
                        {
                            FreeAreas.Add(newArea);
                        }
                    }
                }
                return FreeAreas;
        }
Esempio n. 3
0
 private static bool checkCheckForAreaExistence(Area i, List<Area> areas)
 {
     foreach (Area area in areas)
         {
             if ((i.get_width() == area.get_width()) && (i.get_length() == area.get_length()) && (i.get_area_x() == area.get_area_x()) && (i.get_area_y() == area.get_area_y()))
             {
                 return false;
             }
         }
         return true;
 }