Click here to Skip to main content
15,881,654 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

C++
CPoint ptArray[5];
ptArray[0] = CPoint(657, 79);
ptArray[1] = CPoint(675, 71);
ptArray[2] = CPoint(694, 66);
ptArray[3] = CPoint(912, 64);
ptArray[4] = CPoint(792, 66);
CRgn rgnObject;
rgnObject.CreatePolygonRgn(ptArray, 5, ALTERNATE);
CRect rectBounding;
rgnObject.GetRgnBox(rectBounding);


For bounding rect, I was expecting left = 657, right = 912, top = 64 and bottom 79 i.e. minimum and maximum X and Y coordinates.
Actual results are left = 660, right = 852, top = 65 and bottom 79

Can anyone explain this?

Thanks in advance.
Posted
Updated 4-Jul-11 2:21am
v3
Comments
Richard MacCutchan 4-Jul-11 8:21am    
Please use <pre> tags around your code.
Roger Gonsalves 4-Jul-11 22:47pm    
I was in little bit hurry, so forgot to do that.
Anyway, thanks for advice.
Richard MacCutchan 5-Jul-11 5:54am    
It takes less than a second, and only one mouse click!

The bounding rectangle actually bounds the region, however, some points (the first, fourth and fifth) defining the region actually aren't inside the region itself (you may verify this using the PtInRegion method). I think this is related to roundings happening in region calculation.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Jul-11 19:49pm    
If this is rounding error, it would be amazingly low accuracy, don't you think so? I could hardly accept this explanation. Did you try it in code? maybe OP's report is not accurate? This is the second report of incorrect point set operation I see in CodeProject. Lousy piece of Win32 code?
--SA
CPallini 5-Jul-11 5:50am    
Of course I tried. I don't know if it is acceptable or not it depends on the region algo definition (and Microsoft doesn't provide it in the documentation).
Suppose part of the region is a triangle: if one of the angles is small enough then, near the corrensponding vertex, the arc between the sides approaches zero.
Sergey Alexandrovich Kryukov 5-Jul-11 6:32am    
I think the real problem is the algorithm for non-convex regions, and not sure how and if is can be formulated correctly for self-intersecting boundary (which effectively stop being a "boundary"). Will it work?
--SA
CPallini 5-Jul-11 6:54am    
You are wrong: try it with a(n appropriate) triangle.
Sergey Alexandrovich Kryukov 6-Jul-11 17:32pm    
A sequence of connected segment is not a set of triangles. You can represent this picture with triangles, but some of those triangles will be "empty" and some -- the subsets of the region. Do you see my point? The sub-set is not a union of those rectangle. I am sure the right (and probably pretty simple) algorithm does exists, I just doubt it is that simple. I only asked you: will it work? I did not even make is my statement. I could easily check your references algorithm on a simple example with self-intersecting chain of segments and "empty" triangles inside, but I wanted first to ask you: did you check it up?

Also, did you check up if "my solution" (actually, a Windows solution, not my; I only posted it) works?

Thank you.
--SA
The solution is supposed to be implemented by the available method CRgn::PtInRegion, see http://msdn.microsoft.com/en-us/library/07zzbzfh(v=VS.71).aspx[^].

—SA
 
Share this answer
 
Comments
CPallini 5-Jul-11 6:50am    
Did you try it? I did. It works accordingly with their region algo definition (hence, for instance, it returns FALSE for the first OP point).
Sergey Alexandrovich Kryukov 6-Jul-11 17:37pm    
Sorry, I did not try it. That's why I said only "The solution is supposed to be implemented". Are you saying it does not work as expected? This disturbs me. I already saw two earlier reports of incorrect point-set operations with region in Windows.

A lousy Windows code? What do you think?

Thank you.
--SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900