Exemplo n.º 1
0
        private void AddSkylineLevel(int skylineNodeIndex, ref Rect rect)
        {
            // First track all wasted areas and mark them into the waste map if we're using one.
            if (UseWasteMap)
            {
                AddWasteMapArea(skylineNodeIndex, rect.Width, rect.Height, rect.Y);
            }

            SkylineNode newNode;

            newNode.x     = rect.X;
            newNode.y     = rect.Y + rect.Height;
            newNode.width = rect.Width;
            skyLine.Insert(skylineNodeIndex, newNode);

            Debug.Assert(newNode.x + newNode.width <= BinWidth);
            Debug.Assert(newNode.y <= BinHeight);

            for (int i = skylineNodeIndex + 1; i < skyLine.Count; ++i)
            {
                Debug.Assert(skyLine[i - 1].x <= skyLine[i].x);

                if (skyLine[i].x < skyLine[i - 1].x + skyLine[i - 1].width)
                {
                    int shrink = skyLine[i - 1].x + skyLine[i - 1].width - skyLine[i].x;

                    var skylineNodeNew = new SkylineNode()
                    {
                        x     = skyLine[i].x + shrink,
                        y     = skyLine[i].y,
                        width = skyLine[i].width - shrink
                    };

                    skyLine[i] = skylineNodeNew;

                    if (skyLine[i].width <= 0)
                    {
                        skyLine.RemoveAt(i);
                        --i;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            MergeSkylines();
        }
Exemplo n.º 2
0
        public SkyLineBinPack(int binWidth, bool useWasteMap_)
        {
            BinWidth    = binWidth;
            UseWasteMap = useWasteMap_;
            skyLine.Clear();
            SkylineNode first = new SkylineNode();

            first.x     = 0;
            first.y     = 0;
            first.width = binWidth;
            skyLine.Add(first);

            if (UseWasteMap)
            {
                wasteMap.Clear();
            }
        }
Exemplo n.º 3
0
 /// Merges all skyline nodes that are at the same level.
 private void MergeSkylines()
 {
     for (int i = 0; i < skyLine.Count - 1; ++i)
     {
         if (skyLine[i].y == skyLine[i + 1].y)
         {
             var skylineNewNode = new SkylineNode()
             {
                 x     = skyLine[i].x,
                 y     = skyLine[i].y,
                 width = skyLine[i].width + skyLine[i + 1].width
             };
             skyLine[i] = skylineNewNode;
             skyLine.RemoveAt(i + 1);
             --i;
         }
     }
 }
Exemplo n.º 4
0
        public void AddSkylineLevel(int skylineNodeIndex, ref Module rect)
        {
            if (UseWasteMap)
            {
                AddWasteMapArea(skylineNodeIndex, rect.Width, rect.Height, rect.Y);
            }

            SkylineNode newNode = new SkylineNode();

            newNode.x     = rect.X;
            newNode.y     = rect.Y + rect.Height;
            newNode.width = rect.Width;
            skyLine.Insert(skylineNodeIndex, newNode);

            for (int i = skylineNodeIndex + 1; i < skyLine.Count; ++i)
            {
                if (skyLine[i].x < skyLine[i - 1].x + skyLine[i - 1].width)
                {
                    int shrink = skyLine[i - 1].x + skyLine[i - 1].width - skyLine[i].x;

                    skyLine[i].x     += shrink;
                    skyLine[i].width -= shrink;

                    if (skyLine[i].width <= 0)
                    {
                        skyLine.RemoveAt(i);
                        --i;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            MergeSkylines();
        }