Jitter.Collision.CollisionSystemPersistentSAP.SortAxis C# (CSharp) Method

SortAxis() private method

private SortAxis ( List axis ) : void
axis List
return void
        private void SortAxis(List<SweepPoint> axis)
        {
            for (int j = 1; j < axis.Count; j++)
            {
                SweepPoint keyelement = axis[j];
                float key = keyelement.GetValue();

                int i = j - 1;

                while (i >= 0 && axis[i].GetValue() > key)
                {
                    SweepPoint swapper = axis[i];

                    if (keyelement.Begin && !swapper.Begin)
                    {
                        lock (t2bM)
                        {
                            int count = t2bM.IncrementCounter(keyelement.Body.BroadphaseTag,
                                swapper.Body.BroadphaseTag);

                            if (count == 3)
                            {
                                BodyPair pair = new BodyPair(keyelement.Body, swapper.Body);
                                fullOverlaps.Add(pair);
                            }
                        }
                    }

                    if (!keyelement.Begin && swapper.Begin)
                    {
                        lock (t2bM)
                        {
                            int count = t2bM.DecrementCounter(keyelement.Body.BroadphaseTag,
                                swapper.Body.BroadphaseTag);

                            if (count == 2)
                            {
                                BodyPair pair = new BodyPair(keyelement.Body, swapper.Body);
                                fullOverlaps.Remove(pair);
                            }
                        }
                    }

                    axis[i + 1] = swapper;
                    i = i - 1;
                }
                axis[i + 1] = keyelement;
            }
        }
        #endregion