473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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...
*/

Nov 2 '06 #1
2 5392
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:45***********************@news.wanadoo.nl...
/*
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...
*/

Nov 2 '06 #2
>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.
<SNIP code example>

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?
Nov 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Altramagnus | last post by:
I have a complicated Region object, which I need to draw the outline, but not fill How can I convert the Region object to GraphicsPath object? or How can I draw the outline of the Region object?
6
by: Altramagnus | last post by:
I have n number of circles. Some of them might overlap. I need to draw the outline of all circles but not those overlap areas. Initially, I am try to use a Region, because a Region object has a...
1
by: jay | last post by:
I have a bitmap and a graphicspath object. I draw pixels on m_Bitmap and I'm drawing text using m_Graphics GraphicsPath object. However, saving my work with m_Bitmap.Save doesn't save...
7
by: Crirus | last post by:
Hi Is that true that this IsVisible method is incredible slow? Seems that my app is much slower with only this added as a condition to draw something Crirus
1
by: Mike | last post by:
The .NET class libary presents this as an example of GraphicsPath.IsVisible: Public Sub IsVisibleExample(ByVal e As PaintEventArgs) Dim myPath As New GraphicsPath myPath.AddEllipse(0, 0, 100,...
1
by: NosherRees | last post by:
I'm using GraphicsPath to draw text onto a graphics object (PictureBox). My graphics object has been scaled so that the top left corner is 400000, 6000000 and the bottom right corner is 400100,...
3
by: iwasinnihon | last post by:
I have created a form that has a list box that displays information queried from a table. I then have a textbox under the form and three buttons under that(Add, Update, Delete). When the form is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.