1 | using System;
|
---|
2 |
|
---|
3 | namespace Netron.Diagramming.Core.Layout.Force {
|
---|
4 | /// <summary>
|
---|
5 | /// Represents a point particle in a force simulation, maintaining values for
|
---|
6 | /// mass, forces, velocity, and position.
|
---|
7 | /// </summary>
|
---|
8 | public class ForceItem : ICloneable {
|
---|
9 | #region Fields
|
---|
10 | /// <summary>
|
---|
11 | /// Temporary variables for Runge-Kutta integration
|
---|
12 | /// </summary>
|
---|
13 | private float[,] l;
|
---|
14 | /// <summary>
|
---|
15 | /// The mass value of this ForceItem.
|
---|
16 | /// </summary>
|
---|
17 | private float mass;
|
---|
18 | /// <summary> The values of the forces acting on this ForceItem.
|
---|
19 | /// </summary>
|
---|
20 | private float[] force;
|
---|
21 | /// <summary>
|
---|
22 | /// The velocity values of this ForceItem.
|
---|
23 | /// </summary>
|
---|
24 | private float[] velocity;
|
---|
25 | /// <summary>
|
---|
26 | /// The location values of this ForceItem.
|
---|
27 | /// </summary>
|
---|
28 | private float[] location;
|
---|
29 | /// <summary>
|
---|
30 | /// The previous location values of this ForceItem.
|
---|
31 | /// /// </summary>
|
---|
32 | private float[] plocation;
|
---|
33 | /// <summary>
|
---|
34 | /// Temporary variables for Runge-Kutta integration
|
---|
35 | /// /// </summary>
|
---|
36 | private float[,] k;
|
---|
37 | #endregion
|
---|
38 |
|
---|
39 | #region Properties
|
---|
40 | /// <summary>
|
---|
41 | /// Gets or sets the temporary Runge-Kutta integration value.
|
---|
42 | /// </summary>
|
---|
43 | /// <value>The runge kutta temp1.</value>
|
---|
44 | public float[,] RungeKuttaTemp1 {
|
---|
45 | get { return k; }
|
---|
46 | set { k = value; }
|
---|
47 | }
|
---|
48 |
|
---|
49 |
|
---|
50 | /// <summary>
|
---|
51 | /// Gets or sets the temporary Runge-Kutta integration value.
|
---|
52 | /// </summary>
|
---|
53 | /// <value>The runge kutta temp2.</value>
|
---|
54 | public float[,] RungeKuttaTemp2 {
|
---|
55 | get { return l; }
|
---|
56 | set { l = value; }
|
---|
57 | }
|
---|
58 | /// <summary>
|
---|
59 | /// Gets or sets the mass.
|
---|
60 | /// </summary>
|
---|
61 | /// <value>The mass.</value>
|
---|
62 | public float Mass {
|
---|
63 | get { return mass; }
|
---|
64 | set { mass = value; }
|
---|
65 | }
|
---|
66 | /// <summary>
|
---|
67 | /// Gets or sets the force.
|
---|
68 | /// </summary>
|
---|
69 | /// <value>The force.</value>
|
---|
70 | public float[] Force {
|
---|
71 | get { return force; }
|
---|
72 | set { force = value; }
|
---|
73 | }
|
---|
74 | /// <summary>
|
---|
75 | /// Gets or sets the velocity.
|
---|
76 | /// </summary>
|
---|
77 | /// <value>The velocity.</value>
|
---|
78 | public float[] Velocity {
|
---|
79 | get { return velocity; }
|
---|
80 | set { velocity = value; }
|
---|
81 | }
|
---|
82 | /// <summary>
|
---|
83 | /// Gets or sets the location.
|
---|
84 | /// </summary>
|
---|
85 | /// <value>The location.</value>
|
---|
86 | public float[] Location {
|
---|
87 | get { return location; }
|
---|
88 | set { location = value; }
|
---|
89 | }
|
---|
90 | /// <summary>
|
---|
91 | /// Gets or sets the previous location.
|
---|
92 | /// </summary>
|
---|
93 | /// <value>The previous location.</value>
|
---|
94 | public float[] PreviousLocation {
|
---|
95 | get { return plocation; }
|
---|
96 | set { plocation = value; }
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | #endregion
|
---|
101 |
|
---|
102 | #region Constructor
|
---|
103 | /// <summary>
|
---|
104 | /// Create a new ForceItem.
|
---|
105 | /// </summary>
|
---|
106 | public ForceItem() {
|
---|
107 | mass = 1.0f;
|
---|
108 | force = new float[] { 0.0F, 0.0F };
|
---|
109 | velocity = new float[] { 0.0F, 0.0F };
|
---|
110 | location = new float[] { 0.0F, 0.0F };
|
---|
111 | plocation = new float[] { 0.0F, 0.0F };
|
---|
112 | k = new float[4, 2];
|
---|
113 | l = new float[4, 2];
|
---|
114 | }
|
---|
115 |
|
---|
116 | #endregion
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 | #region Methods
|
---|
121 | /// <summary>
|
---|
122 | /// Checks a ForceItem to make sure its values are all valid numbers(i.e., not NaNs).
|
---|
123 | /// </summary>
|
---|
124 | /// <param name="item">The item to check.</param>
|
---|
125 | /// <returns>
|
---|
126 | /// <c>true</c> if the specified item is valid; otherwise, <c>false</c>.
|
---|
127 | /// </returns>
|
---|
128 | public static bool isValid(ForceItem item) {
|
---|
129 | return
|
---|
130 | !(float.IsNaN(item.location[0]) || float.IsNaN(item.location[1]) ||
|
---|
131 | float.IsNaN(item.plocation[0]) || float.IsNaN(item.plocation[1]) ||
|
---|
132 | float.IsNaN(item.velocity[0]) || float.IsNaN(item.velocity[1]) ||
|
---|
133 | float.IsNaN(item.force[0]) || float.IsNaN(item.force[1]));
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 | /// <summary>
|
---|
138 | /// Creates a new object that is a copy of the current instance.
|
---|
139 | /// </summary>
|
---|
140 | /// <returns>
|
---|
141 | /// A new object that is a copy of this instance.
|
---|
142 | /// </returns>
|
---|
143 | public object Clone() {
|
---|
144 | //ForceItem item = new ForceItem();
|
---|
145 | //item.mass = this.mass;
|
---|
146 | //Array.Copy(force, 0, item.force, 0, 2);
|
---|
147 | //Array.Copy(velocity, 0, item.velocity, 0, 2);
|
---|
148 | //Array.Copy(location, 0, item.location, 0, 2);
|
---|
149 | //Array.Copy(plocation, 0, item.plocation, 0, 2);
|
---|
150 | //for (int i = 0; i < k.Length; ++i)
|
---|
151 | //{
|
---|
152 | // Array.Copy(k[i,], 0, item.k[i,], 0, 2);
|
---|
153 | // Array.Copy(l[i], 0, item.l[i], 0, 2);
|
---|
154 | // Array
|
---|
155 | //}
|
---|
156 | //return item;
|
---|
157 | throw new NotImplementedException("Do you really need this feature?");
|
---|
158 | }
|
---|
159 | #endregion
|
---|
160 | }
|
---|
161 | }
|
---|