473,321 Members | 1,708 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,321 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 5386
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.