Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GraphicsPath.IsVisible broken?

0 views
Skip to first unread message

Mike

unread,
Jun 9, 2006, 6:51:22 PM6/9/06
to
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, 100)
Dim visible As Boolean = myPath.IsVisible(50, 50, e.Graphics)
MessageBox.Show(visible.ToString())
End Sub

This seems to work quite well, it pops up a box that is true, as it should
be. However, if you alter the code:

Public Sub IsVisibleExample(ByVal e As PaintEventArgs)
Dim myPath As New GraphicsPath
myPath.AddEllipse(0.0, 0.0, 1.0, 1.0)
Dim visible As Boolean = myPath.IsVisible(0.5, 0.5, e.Graphics)
MessageBox.Show(visible.ToString())
End Sub

To use those floating points on a smaller scale, the returned value is
false. Now, obviously, that point is within the bounds of the ellipse, and
method explicitly takes Singles, it's not doing a conversion here or anything.

Does anyone know what the reason for this discrepancy is?

Frank Hileman

unread,
Jun 9, 2006, 8:37:22 PM6/9/06
to
Hi,

The GraphicsPath will draw one pixel less in width and height when filling,
if antialiasing is off. The IsVisible method seems consistent with that
interpretation.

Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio graphics editor

"Mike" <Mi...@discussions.microsoft.com> wrote in message
news:AF5CB9E0-AF09-4E75...@microsoft.com...

Gabriela Alonso

unread,
Jul 20, 2006, 4:17:26 PM7/20/06
to
I just ran into a similar situation. All you have to do is scale both the GraphicsPath and the point you´re testing by the same proportion.

Following your example:
(sorry if the syntax is not correct. I usually use C#)

Public Sub IsVisibleExample(ByVal e As PaintEventArgs)
Dim myPath As New GraphicsPath
myPath.AddEllipse(0.0, 0.0, 1.0, 1.0)

myPath.Transform(new Matrix(100, 0, 0, 100, 0, 0)) '(1)

Dim visible As Boolean = myPath.IsVisible(0.5 * 100, 0.5 * 100, e.Graphics) '(2)
MessageBox.Show(visible.ToString())
End Sub

(1) Scale by 100 units in both the x and y dimensions. NOTE: If yopu´re planning to use the GraphicsPath again (for drawing it for example) do not scale it, scale a copy instead. The Transform method transforms the object that calls it.

(2) To scale a point just multiply the x and y coordinates by the desired factor.

So, that´s it. The higher the number you use as scale factor the more precise your IsVisible approach will be.

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/

0 new messages