开发者

intersect function

i am checking intersection of two objects.. and i have a class MBR with data meembers low[2] and high[2].. but i am not getiing intersect..c an you explain this function..

intersects(const MBR* h) const
{
 for (int i = 0; i < 2;开发者_运维问答 i++) 
 {
  if (low_[i] > h->high_[i] || high_[i] < h->low_[i]) 
   return FALSE;
 }
 return TRUE;


intersects compares a MBR to another MBR and returns FALSE if any of the values in the first MBR's low[] are greater than the values (in the respective indices) in the second MBR's high[] or if any of the values in the first MBR's high[] are less than the values (in the respective indices) in the second MBR's low[]. Otherwise it returns TRUE.


Not quite sure what you mean by intersect. If you're talking about intersection of sets, you should probably use std::set_intersection rather than trying to implement this kind of thing yourself. Remember that std::set_intersection requires that the input is already sorted.


If the upper border of one box is smaller than the lower border of another box, than the two boxes don't intersect. Equally, if the lower border of one box is larger than the upper border of the other box. Otherwise the two boxes intersect.

This check is done for both X- and Y-coordinates.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜