package clothSimulator;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import javax.vecmath.Point2d;
import javax.vecmath.Point3d;
import javax.vecmath.Vector2d;
import javax.vecmath.Vector3d;

/**
 * Particle class for 599 assignment 1
 * @author kry
 */
public class Particle {
    
	/** give every particle a normal for drawing */
	Vector3d n = new Vector3d();
	
    /** true means that the particle can not move */
    boolean pinned = false;
        
    /** The mass of the particle */
    double mass = 1;
    
    /** current position of the particle */
    public Point3d p = new Point3d();
    
    /** current velocity of the particle */
    Vector3d v = new Vector3d();
    
    /** initial position of the particle */
    Point3d p0 = new Point3d();
    
    /** initial velocity of the particle */
    Vector3d v0 = new Vector3d();
    
    /** force acting on this particle */
    Vector3d f = new Vector3d();
    
    /** the location in the particles List */
    private int index;
    
    /** the location in the Constraint Graph node list
     */
    public int CGraphIndex;
    /** the location in the spanning tree node list */
    public int CTreeIndex;
    /**
     * A list of springs to which this particle is attached
     * (currently unused, but perhaps of future use)
     */
    ArrayList<Spring> springs = new ArrayList<Spring>();
    
    
    /** despite my deep discomfort with this, I am adding a tag so that we can build a Kruskal tree using particles and constraints only (no abstraction to a graph or anything)
     */
//    public int theSet;   
    public Set<Particle> theSet;
    
    /** 
     * @return the tag identifying a set so that we can build a Kruskal tree using particles and constraints only 
     * (no abstraction to a graph or anything)
     */

    public Set<Particle> getSet(){
    	return theSet;
    }
    public void setSet(Set<Particle> aSet){
    	theSet=aSet;
    }
    /**the above code is just there to build the Kruskal tree
     */
    
    
    /** A list of constraints.  EAch particle knows what constraints act on it.
     * 
     */
    
    /**
     * Creates a particle with the given position and velocity
     * @param x
     * @param y
     * @param vx
     * @param vy
     */
    public Particle( double x, double y, double z, double vx, double vy, double vz ) {
        p0.set(x,y,z);
        v0.set(vx,vy,vz);
        reset();
    }
    
    /**
     * Resets the position of this particle
     */
    public void reset() {
        p.set(p0);
        v.set(v0);
        f.set(0,0,0);
    }
    
    /**
     * Adds the given force to this particle.
     * Note that you probably want to set the force to zero 
     * before accumulating forces. 
     * @param force
     */
    public void addForce( Vector3d force ) {
        f.add(force);
    }
    
    /**
     * Computes the distance of a point to this particle
     * @param x
     * @param y
     * @return the distance
     */
    public double distance( double x, double y, double z) {
        Point3d tmp = new Point3d( x, y, z);
        return tmp.distance(p);
    }

	public void setIndex(int index) {
		this.index = index;
	}

	public int getIndex() {
		return index;
	}
   
}
