Project/02 - Engine/LittleBigEngine/Utils/DouglasPeucker.cs
/// <summary>
/// Uses the Douglas Peucker algorithm to reduce the number of Vector2s.
/// </summary>
/// <param name="points">The Vector2s.</param>
/// <param name="Tolerance">The tolerance.</param>
/// <returns></returns>
Uses the Douglas Peucker algorithm to reduce the number of Vector2s.
Uses the Douglas Peucker algorithm to reduce the number of Vector2s .
public static List<Vector2> DouglasPeuckerReduction
            (List<Vector2> points, Double Tolerance)
        {
            if (points == null || points.Count < 3)
                return points;
            Int32 firstVector2 = 0;
            Int32 lastVector2 = points.Count - 1;
            List<Int32> Vector2IndexsToKeep = new List<Int32>();
            Vector2IndexsToKeep.Add(firstVector2);
            Vector2IndexsToKeep.Add(lastVector2);
            while (points[firstVector2].Equals(points[lastVector2]))
            {
                lastVector2--;
            }
            DouglasPeuckerReduction(points, firstVector2, lastVector2,
            Tolerance, ref Vector2IndexsToKeep);
            List<Vector2> returnVector2s = new List<Vector2>();
            Vector2IndexsToKeep.Sort();
            foreach (Int32 index in Vector2IndexsToKeep)
            {
                returnVector2s.Add(points[index]);
            }
            return returnVector2s;
        }
public static List < Vector2 > DouglasPeuckerReduction ( List < Vector2 > points , Double Tolerance ) { if ( points == null || points . Count < 3 ) return points ; Int32 firstVector2 = 0 ; Int32 lastVector2 = points . Count - 1 ; List < Int32 > Vector2IndexsToKeep = new List < Int32 > ( ) ; Vector2IndexsToKeep . Add ( firstVector2 ) ; Vector2IndexsToKeep . Add ( lastVector2 ) ; while ( points [ firstVector2 ] . Equals ( points [ lastVector2 ] ) ) { lastVector2 -- ; } DouglasPeuckerReduction ( points , firstVector2 , lastVector2 , Tolerance , ref Vector2IndexsToKeep ) ; List < Vector2 > returnVector2s = new List < Vector2 > ( ) ; Vector2IndexsToKeep . Sort ( ) ; foreach ( Int32 index in Vector2IndexsToKeep ) { returnVector2s . Add ( points [ index ] ) ; } return returnVector2s ; }
Uses the Douglas Peucker algorithm to reduce the number of Vector2s.
Uses the Douglas Peucker algorithm to reduce the number of Vector2s .
//Add the first and last index to the keepers //The first and the last Vector2 cannot be the same
None
points
List<Vector2>
None
Tolerance
Double
None