01: package prefuse.util.force;
02:
03: /**
04: * Represents a point particle in a force simulation, maintaining values for
05: * mass, forces, velocity, and position.
06: *
07: * @author <a href="http://jheer.org">jeffrey heer</a>
08: */
09: public class ForceItem implements Cloneable {
10:
11: /**
12: * Create a new ForceItem.
13: */
14: public ForceItem() {
15: mass = 1.0f;
16: force = new float[] { 0.f, 0.f };
17: velocity = new float[] { 0.f, 0.f };
18: location = new float[] { 0.f, 0.f };
19: plocation = new float[] { 0.f, 0.f };
20: k = new float[4][2];
21: l = new float[4][2];
22: }
23:
24: /**
25: * Clone a ForceItem.
26: * @see java.lang.Object#clone()
27: */
28: public Object clone() {
29: ForceItem item = new ForceItem();
30: item.mass = this .mass;
31: System.arraycopy(force, 0, item.force, 0, 2);
32: System.arraycopy(velocity, 0, item.velocity, 0, 2);
33: System.arraycopy(location, 0, item.location, 0, 2);
34: System.arraycopy(plocation, 0, item.plocation, 0, 2);
35: for (int i = 0; i < k.length; ++i) {
36: System.arraycopy(k[i], 0, item.k[i], 0, 2);
37: System.arraycopy(l[i], 0, item.l[i], 0, 2);
38: }
39: return item;
40: }
41:
42: /** The mass value of this ForceItem. */
43: public float mass;
44: /** The values of the forces acting on this ForceItem. */
45: public float[] force;
46: /** The velocity values of this ForceItem. */
47: public float[] velocity;
48: /** The location values of this ForceItem. */
49: public float[] location;
50: /** The previous location values of this ForceItem. */
51: public float[] plocation;
52: /** Temporary variables for Runge-Kutta integration */
53: public float[][] k;
54: /** Temporary variables for Runge-Kutta integration */
55: public float[][] l;
56:
57: /**
58: * Checks a ForceItem to make sure its values are all valid numbers
59: * (i.e., not NaNs).
60: * @param item the item to check
61: * @return true if all the values are valid, false otherwise
62: */
63: public static final boolean isValid(ForceItem item) {
64: return !(Float.isNaN(item.location[0])
65: || Float.isNaN(item.location[1])
66: || Float.isNaN(item.plocation[0])
67: || Float.isNaN(item.plocation[1])
68: || Float.isNaN(item.velocity[0])
69: || Float.isNaN(item.velocity[1])
70: || Float.isNaN(item.force[0]) || Float
71: .isNaN(item.force[1]));
72: }
73:
74: } // end of class ForceItem
|