Click here to Skip to main content
16,018,318 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This doesn't make much sense to me... anyone can explain?
MIDL
Region x = new Region(new Rectangle(1, 1, 3, 3));
Console.WriteLine("" + x.IsVisible(new PointF(0f, 0f)));   // false
Console.WriteLine("" + x.IsVisible(new PointF(0.49f, 0.49f)));  // false
Console.WriteLine("" + x.IsVisible(new PointF(0.5f, 0.5f)));  // true!  ** unexpected, should start at 1,1
Console.WriteLine("" + x.IsVisible(new PointF(3.49f, 3.49f)));  //true
Console.WriteLine("" + x.IsVisible(new PointF(3.5f, 3.5f)));  // false!  ** unexpected, apparently right on the edge is out


Why is the rectangle seeminly starting at .5,.5? I asked it to be at 1,1...
Posted

1 solution

I guess it may be because of rounding (though usually rounding just ignores fractal part). Also, try using the same types (maybe PointF coordinates are being cast to your Rectangle coordinates type): change the constructor into
Region x = new Region(new RectangleF(1f, 1f, 3f, 3f));
 
Share this answer
 
Comments
rld1971 27-May-11 7:31am    
Oh I tried that already, no luck. Besides c# knows how to convert 1l to 1f... I could see some rounding issues at very small numbers, but not at 1.
So the question continues... :(
Timberbird 27-May-11 7:52am    
Oh, rounding to nearest integer. For numbers from 0 to 0.49 nearest integer is 0, while for anything from 0.5 to 1 it is 1. Same goes for 3.49 (nearest integer is 3) and 3.5 (nearest integer is 4).
My guess is that IsVisible internally compares Point object, not PointF. And MSDN says about those two types: "To convert a PointF to a Point, use Point.Round or Point.Truncate". That is, coordinates are rounded or truncated during cast

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