KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > util > force > ForceItem


1 package prefuse.util.force;
2
3 /**
4  * Represents a point particle in a force simulation, maintaining values for
5  * mass, forces, velocity, and position.
6  *
7  * @author <a HREF="http://jheer.org">jeffrey heer</a>
8  */

9 public class ForceItem implements Cloneable JavaDoc {
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 JavaDoc 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
65           !( Float.isNaN(item.location[0]) || Float.isNaN(item.location[1]) ||
66              Float.isNaN(item.plocation[0]) || Float.isNaN(item.plocation[1]) ||
67              Float.isNaN(item.velocity[0]) || Float.isNaN(item.velocity[1]) ||
68              Float.isNaN(item.force[0]) || Float.isNaN(item.force[1]) );
69     }
70     
71 } // end of class ForceItem
72
Popular Tags