2018-01-30 04:14:17 -05:00
|
|
|
/*
|
|
|
|
* Represents each mouse path as an ArrayList of points.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2018-02-19 16:25:11 -05:00
|
|
|
import java.util.Random;
|
2018-01-30 04:14:17 -05:00
|
|
|
|
|
|
|
public class CursorPath {
|
|
|
|
|
2018-02-04 15:34:27 -05:00
|
|
|
private ArrayList<CursorPoint> cursorPoints;
|
|
|
|
private double theta;
|
|
|
|
private int distance;
|
|
|
|
private int timespan;
|
2018-02-19 16:25:11 -05:00
|
|
|
Randomizer randomizer;
|
2018-01-30 04:14:17 -05:00
|
|
|
|
|
|
|
public CursorPath(ArrayList<CursorPoint> cursorPoints)
|
|
|
|
{
|
2018-02-04 15:34:27 -05:00
|
|
|
this.cursorPoints = initializePathOfCursorPoints(cursorPoints);
|
|
|
|
this.distance = calculateCursorPathDistance();
|
|
|
|
this.theta = calculateCursorPathTheta();
|
|
|
|
this.timespan = calculateCursorPathTimespan();
|
2018-02-19 16:25:11 -05:00
|
|
|
this.randomizer = new Randomizer();
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
|
|
|
|
2018-02-19 16:25:11 -05:00
|
|
|
// TODO: refactor
|
2018-02-15 06:27:12 -05:00
|
|
|
public CursorPath(ArrayList<CursorPoint> cursorPoints, boolean setInitializiationOff)
|
|
|
|
{
|
|
|
|
this.cursorPoints = cursorPoints;
|
|
|
|
this.distance = calculateCursorPathDistance();
|
|
|
|
this.theta = calculateCursorPathTheta();
|
|
|
|
this.timespan = calculateCursorPathTimespan();
|
|
|
|
}
|
|
|
|
|
2018-02-04 15:34:27 -05:00
|
|
|
private ArrayList<CursorPoint> initializePathOfCursorPoints(ArrayList<CursorPoint> cursorPoints) {
|
2018-01-30 08:15:20 -05:00
|
|
|
CursorPoint startingCursorPoint = cursorPoints.get(0);
|
2018-02-15 06:27:12 -05:00
|
|
|
ArrayList<CursorPoint> translatedCursorPoints = getTranslatedListOfCursorPoints(cursorPoints, startingCursorPoint);
|
|
|
|
ArrayList<CursorPoint> normalizedDelayCursorPoints = getNormalizedDelayListOfCursorPoints(translatedCursorPoints);
|
2018-02-04 15:34:27 -05:00
|
|
|
return normalizedDelayCursorPoints;
|
|
|
|
}
|
|
|
|
|
2018-02-15 06:27:12 -05:00
|
|
|
private ArrayList<CursorPoint> getTranslatedListOfCursorPoints(ArrayList<CursorPoint> cursorPoints, CursorPoint cursorPointToTranslateBy) {
|
|
|
|
ArrayList<CursorPoint> translatedCursorPath = new ArrayList<CursorPoint>();
|
2018-01-30 04:14:17 -05:00
|
|
|
for (CursorPoint cursorPoint : cursorPoints) {
|
2018-02-15 06:27:12 -05:00
|
|
|
translatedCursorPath.add(cursorPoint.getCursorPointTranslatedBy(cursorPointToTranslateBy));
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
2018-02-15 06:27:12 -05:00
|
|
|
return translatedCursorPath;
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
|
|
|
|
2018-02-15 06:27:12 -05:00
|
|
|
private ArrayList<CursorPoint> getNormalizedDelayListOfCursorPoints(ArrayList<CursorPoint> cursorPoints) {
|
2018-02-04 15:34:27 -05:00
|
|
|
ArrayList<CursorPoint> normalizedDelayCursorPoints = new ArrayList<CursorPoint>();
|
|
|
|
for (int i = 0; i < cursorPoints.size() - 1; i++) {
|
|
|
|
CursorPoint cursorPoint = cursorPoints.get(i);
|
|
|
|
CursorPoint nextCursorPoint = cursorPoints.get(i + 1);
|
|
|
|
normalizedDelayCursorPoints.add(cursorPoint.getCursorPointWithNewDelay(nextCursorPoint.delay - cursorPoint.delay));
|
|
|
|
}
|
|
|
|
normalizedDelayCursorPoints.add(cursorPoints.get(cursorPoints.size() - 1).getCursorPointWithNewDelay(0));
|
2018-02-15 06:27:12 -05:00
|
|
|
return normalizedDelayCursorPoints;
|
2018-02-04 15:34:27 -05:00
|
|
|
}
|
|
|
|
|
2018-02-15 06:27:12 -05:00
|
|
|
public CursorPath getScaledCopyOfCursorPath(double factorToScaleBy) {
|
2018-02-19 16:25:11 -05:00
|
|
|
ArrayList<CursorPoint> scaledCursorPoints= new ArrayList<CursorPoint>();
|
2018-02-15 06:27:12 -05:00
|
|
|
for (CursorPoint cursorPoint : this.cursorPoints) {
|
2018-02-19 16:25:11 -05:00
|
|
|
scaledCursorPoints.add(cursorPoint.getCursorPointScaledBy(factorToScaleBy));
|
2018-01-31 00:04:07 -05:00
|
|
|
}
|
2018-02-19 16:25:11 -05:00
|
|
|
return new CursorPath(scaledCursorPoints, true);
|
2018-01-31 00:04:07 -05:00
|
|
|
}
|
|
|
|
|
2018-02-15 06:27:12 -05:00
|
|
|
public CursorPath getRotatedCopyOfCursorPath(double angleToRotateTo) {
|
2018-02-19 16:25:11 -05:00
|
|
|
ArrayList<CursorPoint> rotatedCursorPoints = new ArrayList<CursorPoint>();
|
2018-02-15 06:27:12 -05:00
|
|
|
double angleToRotateBy = this.theta - angleToRotateTo;
|
|
|
|
for (CursorPoint cursorPoint : this.cursorPoints) {
|
2018-02-19 16:25:11 -05:00
|
|
|
rotatedCursorPoints.add(cursorPoint.getCursorPointRotatedBy(angleToRotateBy));
|
2018-02-04 15:34:27 -05:00
|
|
|
}
|
2018-02-19 16:25:11 -05:00
|
|
|
return new CursorPath(rotatedCursorPoints, true);
|
|
|
|
}
|
|
|
|
|
2018-02-19 20:55:50 -05:00
|
|
|
/*public CursorPath getCopyOfCursorPathTransformedByParabola() {
|
2018-02-19 16:25:11 -05:00
|
|
|
double[] parabolaEquation = randomizer.generateParabolaEquation(this.getCursorPathDistance());
|
|
|
|
ArrayList<CursorPoint> transformedCursorPoints = new ArrayList<CursorPoint>();
|
|
|
|
for (CursorPoint cursorPoint : this.cursorPoints) {
|
2018-02-19 20:55:50 -05:00
|
|
|
transformedCursorPoints.add(cursorPoint.getCursorPointTransformedBy(parabolaEquation));
|
2018-02-19 16:25:11 -05:00
|
|
|
}
|
|
|
|
return new CursorPath(transformedCursorPoints, true);
|
|
|
|
|
2018-02-19 20:55:50 -05:00
|
|
|
}*/
|
2018-01-30 10:19:12 -05:00
|
|
|
|
2018-01-30 04:14:17 -05:00
|
|
|
private int calculateCursorPathTimespan() {
|
2018-01-31 00:04:07 -05:00
|
|
|
int sumPathTimespanMilliseconds = 0;
|
2018-02-04 15:34:27 -05:00
|
|
|
for (CursorPoint cursorPoint : this.cursorPoints) {
|
|
|
|
sumPathTimespanMilliseconds += cursorPoint.delay;
|
2018-01-31 00:04:07 -05:00
|
|
|
}
|
|
|
|
return sumPathTimespanMilliseconds;
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private int calculateCursorPathDistance() {
|
2018-02-15 06:27:12 -05:00
|
|
|
return (int) (getEndingCursorPoint().getDistanceFromOrigin());
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
|
|
|
|
2018-01-30 10:04:20 -05:00
|
|
|
private double calculateCursorPathTheta() {
|
2018-02-15 06:27:12 -05:00
|
|
|
return getEndingCursorPoint().getThetaFromOrigin();
|
2018-01-30 10:04:20 -05:00
|
|
|
}
|
|
|
|
|
2018-02-04 15:34:27 -05:00
|
|
|
public CursorPoint getStartingCursorPoint() {
|
|
|
|
return this.cursorPoints.get(0);
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
|
|
|
|
2018-02-04 15:34:27 -05:00
|
|
|
public CursorPoint getEndingCursorPoint() {
|
|
|
|
return this.cursorPoints.get(this.cursorPoints.size() - 1);
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isCursorPathReasonable() {
|
|
|
|
return isCursorPathTimespanReasonable() && isCursorPathDistanceReasonable() &&
|
|
|
|
isCursorPathNumPointsReasonable();
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isCursorPathTimespanReasonable() {
|
2018-02-19 16:12:25 -05:00
|
|
|
return (this.timespan > 50 && this.timespan < 300);
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isCursorPathDistanceReasonable() {
|
2018-02-19 14:25:10 -05:00
|
|
|
return (this.distance > 0 && this.distance < 2200);
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isCursorPathNumPointsReasonable() {
|
2018-02-19 16:12:25 -05:00
|
|
|
return (this.cursorPoints.size() > 0 && this.cursorPoints.size() < 40);
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public ArrayList<CursorPoint> getCursorPathPoints() {
|
2018-02-04 15:34:27 -05:00
|
|
|
return cursorPoints;
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getCursorPathDistance() {
|
2018-02-04 15:34:27 -05:00
|
|
|
return distance;
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
|
|
|
|
2018-01-30 10:04:20 -05:00
|
|
|
public double getCursorPathTheta() {
|
2018-02-04 15:34:27 -05:00
|
|
|
return theta;
|
2018-02-04 12:18:34 -05:00
|
|
|
}
|
2018-02-04 15:34:27 -05:00
|
|
|
|
2018-02-04 12:18:34 -05:00
|
|
|
|
2018-01-30 04:14:17 -05:00
|
|
|
public void displayCursorPoints() {
|
2018-02-04 15:34:27 -05:00
|
|
|
for (CursorPoint p : this.cursorPoints) {
|
2018-01-31 00:04:07 -05:00
|
|
|
p.display();
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
2018-02-15 06:27:12 -05:00
|
|
|
System.out.println("Number of points:" + this.cursorPoints.size() + ", Timespan:" + this.timespan + ", Distance: " + this.distance + ", Theta: " + this.theta);
|
2018-01-31 00:04:07 -05:00
|
|
|
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~ End of Path ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
2018-01-30 04:14:17 -05:00
|
|
|
}
|
|
|
|
}
|