Ballz.GameSession.World.Terrain.DecimateOutline C# (CSharp) Method

DecimateOutline() private method

private DecimateOutline ( List outline ) : void
outline List
return void
        private void DecimateOutline(List<Vector2> outline)
        {
            // Simple version
            /*
            const int rem = 10;
            for (int i = outline.Count - 2; i > 0; --i)
            {
                if(i % rem > 0)
                    outline.RemoveAt(i);
            }
            */

            // At around 0.1 and lower, the physics outline cannot be distinguished from the rendering
            // At around 0.7 and larger, the decimation has quite a visible effect
            const float thresh = 0.5f;
            const int maxiters = 3; // Will not take more than 3 runs anyway  
            bool changed;
            for(int k = 0; k < maxiters; ++k)
            {
                changed = false;
                for (int i = outline.Count - 1; i > 2; --i)
                {
                    Vector2 a = outline[i-0];
                    Vector2 b = outline[i-1];
                    Vector2 c = outline[i-2];

                    float A = area(a, b, c);
                    if (A < thresh)
                    {
                        outline.RemoveAt(i-1);
                        changed = true;
                    }
                }

                // Early out
                if (!changed)
                {
                    //Console.WriteLine("Early out after " + k + " iters.");
                    break;
                }
            }
        }