using System; namespace Netron.Diagramming.Core.Layout.Force { /// /// Implements a viscosity/drag force to help stabilize items. /// public class DragForce : AbstractForce { #region Fields /// /// the parameter names /// private static String[] pnames = new String[] { "DragCoefficient" }; /// /// dragging coefficient /// public static float DefaultDragCoeff = 0.01f; /// /// minimum dragging coefficient /// public static float DefaultMinDragCoeff = 0.0f; /// /// maximum drag coefficient /// public static float DefaultMaxDragCoeff = 0.1f; /// /// current dragging coefficient /// public static int DragCoeff = 0; #endregion #region Properties /// /// Returns true. /// /// public override bool IsItemForce { get { return true; } } /// /// Gets the parameter names. /// /// /// protected override String[] ParameterNames { get { return pnames; } } #endregion #region Methods /// /// Create a new DragForce. /// /// The drag coefficient. public DragForce(float dragCoeff) { parms = new float[] { dragCoeff }; minValues = new float[] { DefaultMinDragCoeff }; maxValues = new float[] { DefaultMaxDragCoeff }; } /// /// Create a new DragForce with default drag co-efficient. /// public DragForce() : this(DefaultDragCoeff) { } /// /// Returns the force acting on the given item. /// /// public override void GetForce(ForceItem item) { item.Force[0] -= parms[DragCoeff] * item.Velocity[0]; item.Force[1] -= parms[DragCoeff] * item.Velocity[1]; } #endregion } }