public void Construct_Enumeration_Contructed()
 {
     var incrementalEnumerator = new IncrementalEnumerator(0, 10);
     var target = new PagedCollection<IntegerAdapter>(incrementalEnumerator);
     var expectedCount = 10;
     Assert.AreEqual(expectedCount, target.Count);
 }
        public void IncrementalOptimize()
        {
            //All this does is look for any bodies which are to the right of a given body. If it finds one, it pulls it to be adjacent.
            //This converges at the island level- that is, running this on a static topology of simulation islands will eventually result in
            //the islands being contiguous in memory, and at least some connected bodies being adjacent to each other.
            //However, within the islands, it may continue to unnecessarily swap objects around as bodies 'fight' for ownership.
            //One body doesn't know that another body has already claimed a body as a child, so this can't produce a coherent unique traversal order.
            //(In fact, it won't generally converge even with a single one dimensional chain of bodies.)

            //This optimization routine requires much less overhead than other options, like full island traversals. We only request the connections of a single body,
            //and the swap count is limited to the number of connected bodies.
            int optimizationCount = (int)Math.Max(1, Math.Round(bodies.ActiveSet.Count * optimizationFraction));

            for (int i = 0; i < optimizationCount; ++i)
            {
                //No point trying to optimize the last two bodies. No optimizations are possible.
                if (nextBodyIndex >= bodies.ActiveSet.Count - 2)
                {
                    nextBodyIndex = 0;
                }

                var enumerator = new IncrementalEnumerator();
                enumerator.bodies     = bodies;
                enumerator.broadPhase = broadPhase;
                enumerator.solver     = solver;
                enumerator.slotIndex  = nextBodyIndex + 1;
                bodies.EnumerateConnectedBodyIndices(nextBodyIndex, ref enumerator);

                ++nextBodyIndex;
            }
        }