{
int stepindex;
inT32 max_x, min_x, max_y, min_y;
inT32 initial_x, initial_y;
total = 0;
max_x = min_x = pos.
x ();
max_y = min_y = pos.
y ();
looking_for_max_x =
TRUE;
looking_for_min_x =
TRUE;
looking_for_max_y =
TRUE;
looking_for_min_y =
TRUE;
for (stepindex = 0; stepindex < total_steps; stepindex++) {
next_step =
step (stepindex);
pos += next_step;
if (next_step.
x () < 0) {
if (looking_for_max_x && pos.
x () < min_x)
if (looking_for_min_x && max_x - pos.
x () > threshold) {
if (looking_for_max_x) {
initial_x = max_x;
}
total++;
looking_for_max_x =
TRUE;
looking_for_min_x =
FALSE;
}
}
else if (next_step.
x () > 0) {
if (looking_for_min_x && pos.
x () > max_x)
if (looking_for_max_x && pos.
x () - min_x > threshold) {
if (looking_for_min_x) {
initial_x = min_x;
}
total++;
looking_for_max_x =
FALSE;
looking_for_min_x =
TRUE;
}
}
else if (next_step.
y () < 0) {
if (looking_for_max_y && pos.
y () < min_y)
if (looking_for_min_y && max_y - pos.
y () > threshold) {
if (looking_for_max_y) {
initial_y = max_y;
}
total++;
looking_for_max_y =
TRUE;
looking_for_min_y =
FALSE;
}
}
else {
if (looking_for_min_y && pos.
y () > max_y)
if (looking_for_max_y && pos.
y () - min_y > threshold) {
if (looking_for_min_y) {
initial_y = min_y;
}
total++;
looking_for_max_y =
FALSE;
looking_for_min_y =
TRUE;
}
}
}
if (first_was_max_x && looking_for_min_x) {
if (max_x - initial_x > threshold)
total++;
else
total--;
}
else if (!first_was_max_x && looking_for_max_x) {
if (initial_x - min_x > threshold)
total++;
else
total--;
}
if (first_was_max_y && looking_for_min_y) {
if (max_y - initial_y > threshold)
total++;
else
total--;
}
else if (!first_was_max_y && looking_for_max_y) {
if (initial_y - min_y > threshold)
total++;
else
total--;
}
return total;
}