/*
* Copyright (c) 2013-2014. Confluenity
* This content is released under the Apache 2 license:
* http://www.apache.org/licenses/LICENSE-2.0
*/
package com.confluenity.jaylen.entity.phys;
import com.confluenity.jaylen.entity.math.Decimal;
import java.util.Vector;
public class Particle {
public static final Long VOID_SNAPSHOT_ID = -1L;
public static final Long VOID_TRACK_ID = -1L;
private static final int DIMENSIONS = 3;
private static final int X = 1;
private static final int Y = 2;
private static final int Z = 3;
private Vector<Decimal> r = new Vector<>(DIMENSIONS);
private Vector<Decimal> v = new Vector<>(DIMENSIONS);
private long snapshotId;
private long trackId;
private long id;
public Particle(int id, String x, String y, String z) {
this.id = id;
this.r.set(X, new Decimal(x));
this.r.set(Y, new Decimal(y));
this.r.set(Z, new Decimal(z));
this.v.set(X, new Decimal());
this.v.set(Y, new Decimal());
this.v.set(Z, new Decimal());
this.snapshotId = VOID_SNAPSHOT_ID;
this.trackId = VOID_TRACK_ID;
}
public boolean isAssignedToTrack() {
return trackId >= 0 && trackId != VOID_TRACK_ID;
}
public boolean isAssignedToSnapshot() {
return snapshotId >= 0 && snapshotId != VOID_SNAPSHOT_ID;
}
public Decimal getDistance(final Particle other) {
Decimal squareDistance = new Decimal();
for (int j = 0; j < DIMENSIONS; j++) {
squareDistance.add(getX().sub(other.getX()).sqr());
}
return squareDistance.sqrt();
}
public Decimal getVelocity() {
Decimal velocityModule = new Decimal();
for (int j = 0; j < DIMENSIONS; j++) {
velocityModule.add(getVx().sqr());
}
return velocityModule.sqrt();
}
public Decimal getX() {
return r.elementAt(X);
}
public void setX(Decimal x) {
this.r.set(X, x);
}
public Decimal getY() {
return r.elementAt(Y);
}
public void setY(Decimal y) {
this.r.set(Y, y);
}
public Decimal getZ() {
return r.elementAt(Z);
}
public void setZ(Decimal z) {
this.r.set(Z, z);
}
public Decimal getVx() {
return v.elementAt(Y);
}
public Particle setVx(Decimal vx) {
this.v.set(X, vx);
return this;
}
public Decimal getVy() {
return v.elementAt(Y);
}
public Particle setVy(Decimal vy) {
this.v.set(Y, vy);
return this;
}
public Decimal getVz() {
return v.elementAt(Y);
}
public Particle setVz(Decimal vz) {
this.v.set(Z, vz);
return this;
}
public long getSnapshotId() {
return snapshotId;
}
public Particle setSnapshotId(long snapshotId) {
this.snapshotId = snapshotId;
return this;
}
public long getTrackId() {
return trackId;
}
public Particle setTrackId(long trackId) {
this.trackId = trackId;
return this;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}