GraphicsPath.IsVisible(): Unexpected Results 
November 2nd, 2006, 06:35 PM
| | | GraphicsPath.IsVisible(): Unexpected Results
/*
GraphicsPath.IsVisible() gives unexpected results. I fill a
System.Drawing.Drawing2D.GraphicsPath-object with PointF-structures
that define the unit-square (0,0), (1,0), (1,1) and (0,1). Then I
test 3 different PointF-structures to see if they fall inside the unit-
square and the results are clearly wrong:
Point(-0.2, -0.2) falls inside the unit square... WRONG!!!
Point(0.2, 0.2) falls inside the unit square...
Point(0.7, 0.7) falls outside the unit square... WRONG!!!
It seems that the float numbers get rounded to the nearest integer, but
that is not what I want.
*/
//class TestGraphicsPath
class TestGraphicsPath
{
//data member graphicspath
System.Drawing.Drawing2D.GraphicsPath graphicspath=new
System.Drawing.Drawing2D.GraphicsPath();
//constructor
TestGraphicsPath()
{
graphicspath.AddLines
(
new System.Drawing.PointF[]
{
new System.Drawing.PointF(0f,0f),
new System.Drawing.PointF(1f,0f),
new System.Drawing.PointF(1f,1f),
new System.Drawing.PointF(0f,1f),
new System.Drawing.PointF(0f,0f),
}
);
TestPoint(new System.Drawing.PointF(-.2f,-.2f));
TestPoint(new System.Drawing.PointF(.2f,.2f));
TestPoint(new System.Drawing.PointF(.7f,.7f));
}
//TestPoint
void TestPoint(System.Drawing.PointF a)
{
System.Console.Write("Point({0}, {1}) falls ",a.X,a.Y);
System.Console.Write(graphicspath.IsVisible(a)?"in side ":"outside ");
System.Console.WriteLine("the unit square...");
}
//Main
static void Main()
{
new TestGraphicsPath();
}
}
/*
____________________
output:
Point(-0,2, -0,2) falls inside the unit square...
Point(0,2, 0,2) falls inside the unit square...
Point(0,7, 0,7) falls outside the unit square...
*/ | 
November 2nd, 2006, 07:25 PM
| | | Re: GraphicsPath.IsVisible(): Unexpected Results
GraphicsPath objects do indeed convert floats to integers. Oops on the part
of the GDI+ team eh?
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Martijn Mulder" <i@mwrote in message
news:454a4c0c$0$77246$dbd4f001@news.wanadoo.nl... Quote:
/*
GraphicsPath.IsVisible() gives unexpected results. I fill a
System.Drawing.Drawing2D.GraphicsPath-object with PointF-structures
that define the unit-square (0,0), (1,0), (1,1) and (0,1). Then I
test 3 different PointF-structures to see if they fall inside the unit-
square and the results are clearly wrong:
>
Point(-0.2, -0.2) falls inside the unit square... WRONG!!!
Point(0.2, 0.2) falls inside the unit square...
Point(0.7, 0.7) falls outside the unit square... WRONG!!!
>
It seems that the float numbers get rounded to the nearest integer, but
that is not what I want.
*/
>
>
>
//class TestGraphicsPath
class TestGraphicsPath
{
>
>
//data member graphicspath
System.Drawing.Drawing2D.GraphicsPath graphicspath=new
System.Drawing.Drawing2D.GraphicsPath();
>
>
//constructor
TestGraphicsPath()
{
graphicspath.AddLines
(
new System.Drawing.PointF[]
{
new System.Drawing.PointF(0f,0f),
new System.Drawing.PointF(1f,0f),
new System.Drawing.PointF(1f,1f),
new System.Drawing.PointF(0f,1f),
new System.Drawing.PointF(0f,0f),
}
);
TestPoint(new System.Drawing.PointF(-.2f,-.2f));
TestPoint(new System.Drawing.PointF(.2f,.2f));
TestPoint(new System.Drawing.PointF(.7f,.7f));
}
>
>
//TestPoint
void TestPoint(System.Drawing.PointF a)
{
System.Console.Write("Point({0}, {1}) falls ",a.X,a.Y);
System.Console.Write(graphicspath.IsVisible(a)?"in side ":"outside ");
System.Console.WriteLine("the unit square...");
}
>
>
//Main
static void Main()
{
new TestGraphicsPath();
}
}
>
>
>
/*
____________________
output:
>
Point(-0,2, -0,2) falls inside the unit square...
Point(0,2, 0,2) falls inside the unit square...
Point(0,7, 0,7) falls outside the unit square...
*/
>
>
>
| | 
November 3rd, 2006, 08:05 AM
| | | Re: GraphicsPath.IsVisible(): Unexpected Results
>GraphicsPath.IsVisible() gives unexpected results. I fill a Quote: Quote:
>System.Drawing.Drawing2D.GraphicsPath-object with PointF-structures
>that define the unit-square (0,0), (1,0), (1,1) and (0,1). Then I
>test 3 different PointF-structures to see if they fall inside the unit-
>square and the results are clearly wrong:
>>
>Point(-0.2, -0.2) falls inside the unit square... WRONG!!!
>Point(0.2, 0.2) falls inside the unit square...
>Point(0.7, 0.7) falls outside the unit square... WRONG!!!
>>
>It seems that the float numbers get rounded to the nearest integer, but
>that is not what I want.
| | <SNIP code example> Quote:
GraphicsPath objects do indeed convert floats to integers. Oops on the
part of the GDI+ team eh?
|
Is this sloppy enough to call it a bug? | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,662 network members.
|