Integer vs single format in PointF function

Les 281 Reputation points
2021-03-04T20:08:40.667+00:00

I posted this initially in the wrong forum so excuse the double post.

I am working with graphing some functions and I need some clarity on the following code snippet.

For x = -175 To 175 Step 0.1
    y = -CSng((x ^ 2) / 100)
    pts.Add(New PointF(x, y))
Next
gPath.AddLines(pts.ToArray())


For x = -175 To 175 Step 0.1
    y = -CSng((x ^ 2) / 100)
    g.DrawLine(Pens.LightGray, New Point(x,-y), New Point(x, y))
Next

In the first code snippet PoinF appears to store the X value as an integer and the Y value as a decimal number which is great, no problem.
For example the x and y values are like:

X Y
-175 306.25

but in the second code snippet New point has to be only integer??

Can someone explain to me why thats the case? Perhaps the point function allows decimals and the Drawline does not?

Or does the PointF function convert automatically to integer?

And is one method better to use then the other since I am also using antialiasing to smooth my graphing functions more smoothly?

Thank you in advance

Les

Developer technologies | VB
0 comments No comments
{count} votes

Answer accepted by question author
  1. Xingyu Zhao-MSFT 5,381 Reputation points
    2021-03-05T01:56:18.137+00:00

    Hi @Les ,
    Point uses integer coordinates, but PointF uses floating coordinates.
    You need to use PointF parameters in Graphics.DrawLine function in your case.

    g.DrawLine(Pens.LightGray, New PointF(x, -y), New PointF(x, y))  
    

    Hope it could be helpful.

    Best Regards,
    Xingyu Zhao
    *
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.