Click here to Skip to main content
11,796,394 members (70,736 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++
CRect rc;

M_DMBR is empty,and childNode->GetDMBR()has values;
I want to know why rc is empty?
and I make a little test like this:

CRect rt =CRect(35,35,112,112);
CRect rc,rc1;

rc1 is not empty.

I dont know the reason.somebody can help me?
Posted 25-Sep-12 3:25am
Edited 25-Sep-12 3:46am
Malli_S at 25-Sep-12 9:49am
There is a chance that the union is empty. What does the UnionRect() function call returns?
mengfei358 at 25-Sep-12 10:04am
CRect rt =CRect(35,35,112,112);
CRect rc,rc1;
In this code ,after using UnionRect,rc1 is not empty.
Richard MacCutchan at 25-Sep-12 12:40pm
What is the content of rc at this point? I suspect it has some garbage in it, which is why you get a union that is not zero. You can test this by initialising it to a null rectangle.
Sergey Alexandrovich Kryukov at 25-Sep-12 13:31pm
Maybe, still strange... union is not intersection...
Anyway, OP needs to make a sample where both operands are defined.
Richard MacCutchan at 25-Sep-12 13:39pm
Exactly so, I'm just guessing here as there is not enough information to be sure.
Sergey Alexandrovich Kryukov at 25-Sep-12 14:18pm
mengfei358 at 25-Sep-12 20:31pm
Rc is an object of CRect, It's empty,and after union Rc1 (35,35,112,112).this is not my question ,my question is why
CRect rc;
rc is empty after union .
Richard MacCutchan at 26-Sep-12 3:31am
As I said above, it may well be that rc contains garbage at this point, since you did not initialise it to anything. If you read the documentation you will see that the no argument constructor does not initialise it, so it may well contain values which mean it appears to be an unnormalized rectangle. This means that UnionRect() will return a zero rectangle, as again noted in the documentation.

It always pays to
i) read the documentation thoroughly, and
ii) use your debugger to check the actual values of your variables during execution.
Richard MacCutchan at 26-Sep-12 3:41am
What are the actual values of m_DMBR and childNode->GetDMBR() at this point?
mengfei358 at 26-Sep-12 4:24am
M_DMBR is an object of CRect .and initialise it is null. and childNode->GetDMBR() get the value of one node's MBR.
Richard MacCutchan at 26-Sep-12 4:38am
Why do you not answer the question I asked? I said What are the actual values, at this point in the program? The type of object or function call is totally irrelevant to your problem.
mengfei358 at 26-Sep-12 4:51am
sorry ,Maybe I dont understand whats your meaning ." the actual values of m_DMBR and childNode->GetDMBR() at this point?"?
Richard MacCutchan at 26-Sep-12 5:01am
I mean the l, t, r, and b values of each of the rectangles you are trying to get the union of? Have you learned how to use your debugger to check such things?
mengfei358 at 26-Sep-12 8:07am
the l, t, r, and b values of each of the rectangle is known.
Richard MacCutchan at 26-Sep-12 8:15am
Yes, but what are they? Unless you can answer this question with the actual values we cannot hope to guess why this is going wrong!
mengfei358 at 26-Sep-12 8:30am
CRect rc;
CString str;
using this to test.and get value as this:leaf:0,0 entry:53,550,m_DMBR:-858993460,-858993460,
Richard MacCutchan at 26-Sep-12 8:35am
At last you see that you are returning some incorrect values. Now you need to dig into your code to find out why.
mengfei358 at 26-Sep-12 8:52am
yes ,so thats what I want to know,after debug ,I cant find out the reason
Richard MacCutchan at 26-Sep-12 8:59am
Well how on earth do you expect us to guess what may be happening? We have no idea what your code is doing or where these values come from. It is up to you to get working with your debugger and step through the code to find out.
mengfei358 at 26-Sep-12 9:08am
ok ,if I can find out the reason.i wouldnt ask the question.anyway,thank you.
Richard MacCutchan at 26-Sep-12 11:06am
But how do you think we can find the reason? You have not given us any information about the values that are being passed in to the call to CRect::UnionRect(), in terms of where they come from, and even when I asked you to check them you did not provide all values. If you do not know how to use the debugger to trace through your code then I suggest you spend some time with the documentation and see how to stop the program at breakpoints and how to check the contents of variables.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Please check m_DMBR initializing proper?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 530
1 Abhinav S 392
2 OriginalGriff 340
3 CPallini 285
4 KrunalRohit 249
0 OriginalGriff 2,012
1 Maciej Los 1,725
2 KrunalRohit 1,310
3 CPallini 1,055
4 ppolymorphe 858

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100