• Post Reply Bookmark Topic Watch Topic
  • New Topic

Rectangle outcode() not working quite right

 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote the following to try to capture if the rect is top bottom right left, however it doesnt work right. If I replace the statements eg lets say for top to code==2 || code ==6 || code ==3 it works fine. Any idea what im doing wrong

code = nodeRect.outcode(currentRect.getX(), currentRect.getY());

if(code & Rectangle.OUT_TOP) != 0 ||
(code & (Rectangle.OUT_RIGHT | Rectangle.OUT_TOP)) != 0 ||
(code & (Rectangle.OUT_LEFT | Rectangle.OUT_TOP) ) != 0)
{
//This means the point is above the rectangle
}
else if(code & Rectangle.OUT_BOTTOM) != 0 ||
(code & (Rectangle.OUT_RIGHT | Rectangle.OUT_BOTTOM) ) != 0 ||
(code & (Rectangle.OUT_LEFT | Rectangle.OUT_BOTTOM) ) != 0 )
{
//This means the point is below the rectangle
}
else if(code & Rectangle.OUT_RIGHT) != 0 )
{
//This means the point is to the right of the rectangle
}
else if(code & Rectangle.OUT_LEFT) != 0 )
{
//This means the point is to the left of the rectangle
}
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try something like this

Here's a page in the tutorial that may be helpful
Shift and Logical Operators
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!