* @param conn
*/
@SuppressWarnings("unchecked")
static void recordFinalState(Connection conn) {
//$TODO
PointList points1 = (PointList) initialStates.get(conn);
PointList points2 = conn.getPoints().getCopy();
if (points1 != null && points1.size() != points2.size()) {
Point p = new Point(), q = new Point();
int size1 = points1.size() - 1;
int size2 = points2.size() - 1;
int i1 = size1;
int i2 = size2;
double current1 = 1.0;
double current2 = 1.0;
double prev1 = 1.0;
double prev2 = 1.0;
while (i1 > 0 || i2 > 0) {
if (Math.abs(current1 - current2) < 0.1 && i1 > 0 && i2 > 0) {
//Both points are the same, use them and go on;
prev1 = current1;
prev2 = current2;
i1--;
i2--;
current1 = (double) i1 / size1;
current2 = (double) i2 / size2;
}
else if (current1 < current2) {
//2 needs to catch up
// current1 < current2 < prev1
points1.getPoint(p, i1);
points1.getPoint(q, i1 + 1);
p.x = (int) (((q.x * (current2 - current1) + p.x
* (prev1 - current2)) / (prev1 - current1)));
p.y = (int) (((q.y * (current2 - current1) + p.y
* (prev1 - current2)) / (prev1 - current1)));
points1.insertPoint(p, i1 + 1);
prev1 = prev2 = current2;
i2--;
current2 = (double) i2 / size2;
}
else {
//1 needs to catch up
// current2< current1 < prev2
points2.getPoint(p, i2);
points2.getPoint(q, i2 + 1);
p.x = (int) (((q.x * (current1 - current2) + p.x
* (prev2 - current1)) / (prev2 - current2)));
p.y = (int) (((q.y * (current1 - current2) + p.y
* (prev2 - current1)) / (prev2 - current2)));
points2.insertPoint(p, i2 + 1);
prev2 = prev1 = current1;
i1--;
current1 = (double) i1 / size1;
}