/// <summary> /// Deep copy. /// </summary> /// <returns></returns> public OTree Copy() { OTree ot = new OTree(); ot._moduleSequence = new List<int>(_moduleSequence); ot._dfsSequence = new List<Bit>(_dfsSequence); return ot; }
/// <summary> /// Deep copy. /// </summary> /// <returns></returns> public OTree Copy() { OTree ot = new OTree(); ot._moduleSequence = new List <int>(_moduleSequence); ot._dfsSequence = new List <Bit>(_dfsSequence); return(ot); }
/// <summary> /// Greedy algorithm. /// </summary> /// <param name="modules">List of modules that represent the images that need to be inserted into the sprite.</param> /// <returns>Near optimal placement.</returns> public static Placement Greedy(IEnumerable<Module> modules) { var sortedByArea = from module in modules orderby module.Width * module.Height descending select module; //Empty O-Tree code. var oTree = new OTree(); OT finalOT = null; //Empty list of modules. var moduleList = new List<Module>(); //For each module which needs to be inserted. foreach (var module in sortedByArea) { OTree bestOTree = null; //Add module to the list of already packed modules. moduleList.Add(module); //Set the minimum perimeter of the placement to high. int minPerimeter = Int32.MaxValue; //Try all insertation point. foreach (int insertationPoint in oTree.InsertationPoints()) { var ot = oTree.Copy(); ot.Insert(module.Name, insertationPoint); var oT = new OT(ot, moduleList); var pm = oT.Placement; //Choose the one with the minimum perimeter. if (pm.Perimeter < minPerimeter) { finalOT = oT; bestOTree = ot; minPerimeter = pm.Perimeter; } } oTree = bestOTree; } return finalOT.Placement; }
/// <summary> /// Greedy algorithm. /// </summary> /// <param name="modules">List of modules that represent the images that need to be inserted into the sprite.</param> /// <returns>Near optimal placement.</returns> public static Placement Greedy(IEnumerable <Module> modules) { var sortedByArea = from module in modules orderby module.Width * module.Height descending select module; //Empty O-Tree code. var oTree = new OTree(); OT finalOT = null; //Empty list of modules. var moduleList = new List <Module>(); //For each module which needs to be inserted. foreach (var module in sortedByArea) { OTree bestOTree = null; //Add module to the list of already packed modules. moduleList.Add(module); //Set the minimum perimeter of the placement to high. int minPerimeter = Int32.MaxValue; //Try all insertation point. foreach (int insertationPoint in oTree.InsertationPoints()) { var ot = oTree.Copy(); ot.Insert(module.Name, insertationPoint); var oT = new OT(ot, moduleList); var pm = oT.Placement; //Choose the one with the minimum perimeter. if (pm.Perimeter < minPerimeter) { finalOT = oT; bestOTree = ot; minPerimeter = pm.Perimeter; } } oTree = bestOTree; } return(finalOT.Placement); }
/// <summary> /// Algoritms class for O-Tree representation. /// </summary> /// <param name="ot">The O-tree code which describes the placement.</param> /// <param name="_modules">Modules to be packed.</param> public OT(OTree ot, List <Module> modules) { _oTree = ot; _modules = modules.ToDictionary(item => item.Name, item => item); _placement = null; }
/// <summary> /// Algoritms class for O-Tree representation. /// </summary> /// <param name="ot">The O-tree code which describes the placement.</param> /// <param name="_modules">Modules to be packed.</param> public OT(OTree ot, List<Module> modules) { _oTree = ot; _modules = modules.ToDictionary(item => item.Name, item => item); _placement = null; }