Home All Groups Group Topic Archive Search About

GraphicsPath.IsVisible broken?

Author
9 Jun 2006 10:09 PM
Mike
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?

Author
12 Jun 2006 8:34 AM
Larry Lard
Mike wrote:
Show quoteHide quote
> 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.

I wouldn't be so sure about that. Remember that in GDI+ the unit of
measure is the pixel. If you check what an ellipse produced with those
arguments actually looks like (eg, new WinForms project, drop a
picturebox on the form, add this code

    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        With e.Graphics
            .FillEllipse(Brushes.Red, 0, 0, 1.0, 1.0)
        End With
    End Sub

and play with the parameters) you will see that it doesn't actually
include any pixels at all, so IsVisible will always return false (I
suspect). These aren't idealised mathematical coordinates - they are
very much tied to the actual pixels produced.

--
Larry Lard
Replies to group please