コード例 #1
0
        public int GetIndexFromPoint(Point position)
        {
            if (Children == null || Children.Count == 0)
            {
                return(0);
            }
            int idx = cardLocations.OrderBy(y => Math.Abs(y.Value - position.X)).First().Key;

            //if (idx > Children.Count) idx = Children.Count;
            return(idx);
        }
コード例 #2
0
        SortDependencies()
        {
            Log.Detail("Analysing module dependencies...");
            var moduleRanks      = new System.Collections.Generic.Dictionary <Module, int>();
            var modulesToProcess = new System.Collections.Generic.Queue <Module>();
            var scale            = 100.0f / (3 * Module.Count);

            // initialize the map with top-level modules
            // and populate the to-process list
            foreach (var module in this.TopLevelModules)
            {
                SetModuleRank(moduleRanks, module, 0);
                ProcessModule(moduleRanks, modulesToProcess, module, 0);
                Log.DetailProgress("{0,3}%", (int)((Module.Count - modulesToProcess.Count) * scale));
            }
            // process all modules by initializing them to a best-guess rank
            // but then potentially moving them to a higher rank if they re-appear as dependencies
            while (modulesToProcess.Count > 0)
            {
                var module = modulesToProcess.Dequeue();
                ProcessModule(moduleRanks, modulesToProcess, module, moduleRanks[module]);
                Log.DetailProgress("{0,3}%", (int)((Module.Count - modulesToProcess.Count) * scale));
            }
            // moduleRanks[*].Value is now sparse - there may be gaps between successive ranks with modules
            // this needs to be collapsed so that the rank indices are contiguous (the order is correct, the indices are just wrong)

            // assign modules, for each rank index, into collections
            var count = Module.Count;
            var contiguousRankIndex = 0;
            var lastRankIndex       = 0;

            foreach (var nextModule in moduleRanks.OrderBy(item => item.Value))
            {
                if (lastRankIndex != nextModule.Value)
                {
                    lastRankIndex = nextModule.Value;
                    contiguousRankIndex++;
                }
                var rank = this.DependencyGraph[contiguousRankIndex];
                rank.Add(nextModule.Key);
                Log.DetailProgress("{0,3}%", (int)(count++ *scale));
            }
            Module.CompleteModules();
        }