using System; namespace Netron.Diagramming.Core.Layout.Force { /// /// Represents a point particle in a force simulation, maintaining values for /// mass, forces, velocity, and position. /// public class ForceItem : ICloneable { #region Fields /// /// Temporary variables for Runge-Kutta integration /// private float[,] l; /// /// The mass value of this ForceItem. /// private float mass; /// The values of the forces acting on this ForceItem. /// private float[] force; /// /// The velocity values of this ForceItem. /// private float[] velocity; /// /// The location values of this ForceItem. /// private float[] location; /// /// The previous location values of this ForceItem. /// /// private float[] plocation; /// /// Temporary variables for Runge-Kutta integration /// /// private float[,] k; #endregion #region Properties /// /// Gets or sets the temporary Runge-Kutta integration value. /// /// The runge kutta temp1. public float[,] RungeKuttaTemp1 { get { return k; } set { k = value; } } /// /// Gets or sets the temporary Runge-Kutta integration value. /// /// The runge kutta temp2. public float[,] RungeKuttaTemp2 { get { return l; } set { l = value; } } /// /// Gets or sets the mass. /// /// The mass. public float Mass { get { return mass; } set { mass = value; } } /// /// Gets or sets the force. /// /// The force. public float[] Force { get { return force; } set { force = value; } } /// /// Gets or sets the velocity. /// /// The velocity. public float[] Velocity { get { return velocity; } set { velocity = value; } } /// /// Gets or sets the location. /// /// The location. public float[] Location { get { return location; } set { location = value; } } /// /// Gets or sets the previous location. /// /// The previous location. public float[] PreviousLocation { get { return plocation; } set { plocation = value; } } #endregion #region Constructor /// /// Create a new ForceItem. /// public ForceItem() { mass = 1.0f; force = new float[] { 0.0F, 0.0F }; velocity = new float[] { 0.0F, 0.0F }; location = new float[] { 0.0F, 0.0F }; plocation = new float[] { 0.0F, 0.0F }; k = new float[4, 2]; l = new float[4, 2]; } #endregion #region Methods /// /// Checks a ForceItem to make sure its values are all valid numbers(i.e., not NaNs). /// /// The item to check. /// /// true if the specified item is valid; otherwise, false. /// public static bool isValid(ForceItem item) { return !(float.IsNaN(item.location[0]) || float.IsNaN(item.location[1]) || float.IsNaN(item.plocation[0]) || float.IsNaN(item.plocation[1]) || float.IsNaN(item.velocity[0]) || float.IsNaN(item.velocity[1]) || float.IsNaN(item.force[0]) || float.IsNaN(item.force[1])); } /// /// Creates a new object that is a copy of the current instance. /// /// /// A new object that is a copy of this instance. /// public object Clone() { //ForceItem item = new ForceItem(); //item.mass = this.mass; //Array.Copy(force, 0, item.force, 0, 2); //Array.Copy(velocity, 0, item.velocity, 0, 2); //Array.Copy(location, 0, item.location, 0, 2); //Array.Copy(plocation, 0, item.plocation, 0, 2); //for (int i = 0; i < k.Length; ++i) //{ // Array.Copy(k[i,], 0, item.k[i,], 0, 2); // Array.Copy(l[i], 0, item.l[i], 0, 2); // Array //} //return item; throw new NotImplementedException("Do you really need this feature?"); } #endregion } }