Click here to Skip to main content
15,886,919 members
Articles / Programming Languages / C#

Triangulation of Arbitrary Polygons

Rate me:
Please Sign up or sign in to vote.
4.54/5 (7 votes)
22 Nov 2009CPOL4 min read 58K   5K   31  
This article describes a way of triangulating polygons that is intuitively easy to understand and explain diagrammatically
using System.Collections.Generic;

namespace FarseerGames.FarseerPhysics.Controllers
{
    /// <summary>
    /// Provides an implementation of a strongly typed List with Controller
    /// </summary>
    public class ControllerList : List<Controller>
    {
        #region Delegates

        public delegate void ContentsChangedEventHandler(Controller controller);

        #endregion

        private List<Controller> _markedForRemovalList = new List<Controller>();

        public ContentsChangedEventHandler Added;
        public ContentsChangedEventHandler Removed;

        /// <summary>
        /// Adds the specified controller.
        /// </summary>
        /// <param name="controller">The controller.</param>
        public new void Add(Controller controller)
        {
            base.Add(controller);
            if (Added != null)
            {
                Added(controller);
            }
        }

        /// <summary>
        /// Removes the specified controller.
        /// </summary>
        /// <param name="controller">The controller.</param>
        public new void Remove(Controller controller)
        {
            base.Remove(controller);
            if (Removed != null)
            {
                Removed(controller);
            }
        }

        /// <summary>
        /// Removes the disposed controllers.
        /// </summary>
        public void RemoveDisposed()
        {
            for (int i = 0; i < Count; i++)
            {
                if (IsDisposed(this[i]))
                {
                    _markedForRemovalList.Add(this[i]);
                }
            }
            for (int j = 0; j < _markedForRemovalList.Count; j++)
            {
                Remove(_markedForRemovalList[j]);
            }
            _markedForRemovalList.Clear();
        }

        internal static bool IsDisposed(Controller controller)
        {
            return controller.IsDisposed;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Singapore Singapore
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions