public Sky(Box bin, int spreadFactor, Box[] input)
            {
                this.skylines   = new LStack <Skyline>();
                this.backBuffer = new LStack <Skyline>();
                this.skylines.Add(new Skyline {
                    x    = 0,
                    h    = 0,
                    w    = bin.w,
                    rFit = bin.w,
                    lFit = bin.w,
                });
                this.binIndex = 0;
                this.bin      = bin;
                this.input    = input;
                this._toPack  = new LStack <int>(this.input.Length);
                for (int i = 0; i < this.input.Length; ++i)
                {
                    _toPack.Add(i);
                }

                this.packCandidates = new LStack <PackCandidate>();
                this.candComp       = new CandidateComparer(this);
                this.spreadFactor   = spreadFactor;
                this.lowestSky      = this.highestSky = 0;
            }
Esempio n. 2
0
        /// <summary>
        /// インスタンスを生成します。
        /// </summary>
        /// <param name="manager">パーティション マネージャ。</param>
        /// <param name="volume">アクティブ領域。</param>
        /// <param name="priorDistance">アクティブ化優先距離。</param>
        public ActivationCandidateFinder(PartitionManager manager, IActiveVolume volume, float priorDistance)
        {
            this.manager = manager;
            this.volume  = volume;

            collectAction = new Action <IntVector3>(Collect);
            comparer      = new CandidateComparer(priorDistance);
            candidates    = new PriorityQueue <Candidate>(candidateQueueCapacity, comparer);

            thread = new Thread(Run);
            thread.IsBackground = true;
        }
        public void Should_handle_nulls()
        {
            var comparer = new CandidateComparer("address");

            var x = new Candidate {
                Address = "address",
                Score   = 100,
                Weight  = 1
            };

            comparer.Compare(x, null).ShouldBe(1);
            comparer.Compare(null, x).ShouldBe(-1);
            comparer.Compare(null, null).ShouldBe(0);
        }
Esempio n. 4
0
        private void RemoveSortedCandidate(GraphEntry candidateEntry)
        {
            Assert.IsTrue(candidateEntry != null);
            CandidateComparer comparer = new CandidateComparer();
            int findIndex = _sortedCandidateGraphEntries.BinarySearch(candidateEntry, comparer);

            if (findIndex >= 0)
            {
                // Find the lower bound...
                int lowerBound = findIndex;
                while (lowerBound > 0)
                {
                    if (comparer.Compare(_sortedCandidateGraphEntries[lowerBound - 1], _sortedCandidateGraphEntries[findIndex]) == 0)
                    {
                        --lowerBound;
                    }
                    else
                    {
                        break;
                    }
                }

                // Find the upper bound...
                int upperBound = findIndex;
                while (upperBound < (_sortedCandidateGraphEntries.Count - 1))
                {
                    if (comparer.Compare(_sortedCandidateGraphEntries[upperBound + 1], _sortedCandidateGraphEntries[findIndex]) == 0)
                    {
                        ++upperBound;
                    }
                    else
                    {
                        break;
                    }
                }

                // Loop over all possible candidates until we find the one we're looking for.
                for (int currTestIndex = lowerBound; currTestIndex <= upperBound; ++currTestIndex)
                {
                    Assert.IsTrue(comparer.Compare(_sortedCandidateGraphEntries[currTestIndex], _sortedCandidateGraphEntries[findIndex]) == 0);
                    if (_sortedCandidateGraphEntries[findIndex] == candidateEntry)
                    {
                        _sortedCandidateGraphEntries.RemoveAt(findIndex);
                        break;
                    }
                }
            }
        }
        public void Should_return_highest_score(int result, string address, string addressA, int scoreA, int weightA,
                                                string addressB, int scoreB, int weightB)
        {
            var comparer = new CandidateComparer(address);

            var a = new Candidate {
                Address = addressA,
                Score   = scoreA,
                Weight  = weightA
            };

            var b = new Candidate {
                Address = addressB,
                Score   = scoreB,
                Weight  = weightB
            };

            comparer.Compare(a, b).ShouldBe(result);
        }