コード例 #1
0
        /// <summary>
        /// Packs the supplied items across the supplied containers and returns packing results and expanded statistics about packing performance.
        /// </summary>
        /// <param name="items">The items to pack.</param>
        /// <param name="containers">The containers to pack into.</param>
        /// <returns>Packing results and expanded statistics about packing performance.</returns>
        public List <CuboidPacker> PackMultipleContainersWithStats(
            List <Cuboid> items,
            List <Cuboid> containers)
        {
            if (containers == null || containers.Count == 0)
            {
                throw new ArgumentNullException(nameof(containers));
            }

            if (items == null || items.Count == 0)
            {
                throw new ArgumentNullException(nameof(items));
            }

            // we need to keep track of packed items across bins
            // and then aggregate results, hence the lists external to BinPacker object
            var remainingItems = new List <Item>(ItemsFromCuboids(items));
            var packers        = new List <CuboidPacker>();

            for (var i = 0; i < containers.Count; i++)
            {
                // pack items
                var currentBin = containers[i];
                var packer     = new CuboidPacker(currentBin, i);
                packer.PackItems(remainingItems);

                // update list of remaining items to pack
                RemovePackedItemsById(remainingItems, packer);

                // record results
                packers.Add(packer);
            }

            return(packers);
        }
コード例 #2
0
 private static void RemovePackedItemsById(List <Item> items, CuboidPacker packer)
 {
     items.RemoveAll(x => packer.PackedIndices.Contains(x.ID));
 }