do{}while stopping condition
Hi,
I am having trouble with my stopping statement! I want all the items to evaluate to true before it stops:
do{...}while(px!=x && py!=y && entryDir!=S)
I am tracing around the outline of a character, the trouble is as soon as it get to the top of the letter and the entryDir changes it stops...
So it should stop when px = x, py = y and the entry direction into the starting pixel (x,y) was S (south).
Thanks, Ron
Message was edited by:
cake
[509 byte] By [
cakea] at [2007-11-27 3:22:06]

Here is the rest of the code, just to make sure...
public void getMooreBlob(int x, int y){
char N='N', E='E', S='S', W='W';
int px=x, py=y, nextMove=1;
downSampleLeft = downSampleRight = x;
downSampleTop = downSampleBottom = y;
System.out.println("left="+x+"right="+x+"top="+y+"bottom="+y);
//I am always going to be entering from the south to start, scanning down
char entryDir = S;
do{
//pixel positions relative to p
switch (nextMove)
{
//move1
case 1:
if(loadImg.getRGB((px+1),(py-1))!=-1){
entryDir='E';
px=px+1; py=py-1;
setP(px, py);
nextMove=7;
break;
}
//move2
case 2:
if(loadImg.getRGB((px+1),py)!=-1){
entryDir='S';
px=px+1; py=py;
setP(px, py);
nextMove=1;
break;
}
//move3
case 3:
if(loadImg.getRGB((px+1),(py+1))!=-1){
entryDir='S';
px=px+1;py=py+1;
setP(px, py);
nextMove=1;
break;
}
//move4
case 4:
if(loadImg.getRGB(px,(py+1))!=-1){
entryDir='W';
px=px;py=py+1;
setP(px, py);
nextMove=3;
break;
}
//move5
case 5:
if(loadImg.getRGB((px-1),(py+1))!=-1){
entryDir='W';
px=px-1;py=py+1;
setP(px, py);
nextMove=3;
break;
}
//move6
case 6:
if(loadImg.getRGB((px-1),py)!=-1){
entryDir='N';
px=px-1;py=py;
setP(px, py);
nextMove=5;
break;
}
//move7
case 7:
if(loadImg.getRGB((px-1),(py-1))!=-1){
entryDir='N';
px=px-1;py=py-1;
setP(px, py);
nextMove=5;
break;
}
//move8
case 8:
if(loadImg.getRGB(px,(py-1))!=-1){
entryDir='E';
px=px;py=py-1;
setP(px, py);
nextMove=7;
break;
}
default:
nextMove++;
if(nextMove==9)nextMove=1;
break;
}
}while(px!=x && py!=y && entryDir!=S);
}
cakea at 2007-7-12 8:24:52 >
