private void PutOnShelf(Shelf shelf, Cuboid cuboid) { var width = cuboid.Width; var height = cuboid.Height; var depth = cuboid.Depth; // Sort edges in decreasing order var edges = new List <decimal>() { width, height, depth }; edges.Sort(); var max = edges[2]; var middle = edges[1]; var min = edges[0]; // Set cuboid's longest egde vertically if (max <= shelf.Height && (_parameter.AllowRotateVertically || max == cuboid.Height)) { var maxVerticalRect = new Rectangle(middle, min, 0, 0); shelf.Guillotine.Insert(maxVerticalRect, _rectChoice, out int freeRectIndex); if (maxVerticalRect.IsPlaced && cuboid.AllowPlacing(maxVerticalRect.Width, max, maxVerticalRect.Height)) { shelf.Guillotine.InsertOnPosition(maxVerticalRect, _splitMethod, freeRectIndex); cuboid.IsPlaced = true; cuboid.Width = maxVerticalRect.Width; cuboid.Height = max; cuboid.Depth = maxVerticalRect.Height; cuboid.X = maxVerticalRect.X; cuboid.Z = maxVerticalRect.Y; return; } } // Set cuboid's second longest egde vertically if (middle <= shelf.Height && (_parameter.AllowRotateVertically || middle == cuboid.Height)) { var middleVerticalRect = new Rectangle(min, max, 0, 0); shelf.Guillotine.Insert(middleVerticalRect, _rectChoice, out int freeRectIndex); if (middleVerticalRect.IsPlaced && cuboid.AllowPlacing(middleVerticalRect.Width, middle, middleVerticalRect.Height)) { shelf.Guillotine.InsertOnPosition(middleVerticalRect, _splitMethod, freeRectIndex); cuboid.IsPlaced = true; cuboid.Width = middleVerticalRect.Width; cuboid.Height = middle; cuboid.Depth = middleVerticalRect.Height; cuboid.X = middleVerticalRect.X; cuboid.Z = middleVerticalRect.Y; return; } } // Set cuboid's smallest egde vertically if (min <= shelf.Height && (_parameter.AllowRotateVertically || min == cuboid.Height)) { var minVerticalRect = new Rectangle(middle, max, 0, 0); shelf.Guillotine.Insert(minVerticalRect, _rectChoice, out int freeRectIndex); if (minVerticalRect.IsPlaced && cuboid.AllowPlacing(minVerticalRect.Width, min, minVerticalRect.Height)) { shelf.Guillotine.InsertOnPosition(minVerticalRect, _splitMethod, freeRectIndex); cuboid.IsPlaced = true; cuboid.Width = minVerticalRect.Width; cuboid.Height = min; cuboid.Depth = minVerticalRect.Height; cuboid.X = minVerticalRect.X; cuboid.Z = minVerticalRect.Y; return; } } // Place failed }