Answered by:
The precision of numbers is lost when initializing Gdiplus::PointF class instanse.

Question
-
Hello. For drawing lines (edges of triangles) I use the following GDI+ function:
Status DrawLine( IN const Pen *pen, IN const PointF & pt1, IN const PointF & pt2 );
I have the structure that I use.
// Represents the edge of a triangle that is part of the set // of triangles drawn in the application window that make up // the triangulation mesh. struct EdgeToDraw { EdgeToDraw() {} EdgeToDraw(long X_begin, long Y_begin, long X_end, long Y_end) { Begin.X = X_begin; Begin.Y = Y_begin; End.X = X_end; End.Y = Y_end; } // X and Y coordinates of begin edge vertex. PointF Begin; // X and Y coordinates of end edge vertex. PointF End; };
The thread of constructing a triangulation places the coordinates of the edges in the concurrent_queue container
concurrent_queue<EdgeToDraw> MeshEdgesBuffer;
and another thread takes them from there (in WndProc WM_PAINT) in order to draw. Below I show how I put instances of EdgeToDraw in a concurrent_queue container.
// Add an edge for the drawn triangulation mesh. MeshEdgesBuffer.push(EdgeToDraw(X_begin, Y_begin, X_end, Y_end));
But here, the accuracy of the added values is lost. For example if X_begin == -0.522 and Y_begin == 2.169 (where X_begin and Y_begin have double type), then MeshEdgesBuffer[0].Begin.X == 0 and MeshEdgesBuffer[0].Begin.Y == 2. And so on. But for me, the numbers to the right of the decimal point are very important. Highly. As I understand it, the PointF class is specifically designed to express coordinates with decimal point values. Please tell me what I am doing wrong and how can I make sure that the accuracy of numbers is not lost? That is, if X_begin == -0.522, then Begin.X is of the same value (-0.522) but not is 0 or 0.000. Thank you in advance.
Saturday, March 14, 2020 3:56 PM
Answers
-
The EdgeToDraw constructor takes long variables (an integer type), not doubles. Your values will be truncated.
- Marked as answer by Purple_Apple Saturday, March 14, 2020 4:42 PM
Saturday, March 14, 2020 4:10 PM -
I bag your pardon. I've got mistake in types (long inside double). Excuse me please.
- Marked as answer by Purple_Apple Saturday, March 14, 2020 4:12 PM
Saturday, March 14, 2020 4:12 PM
All replies
-
The EdgeToDraw constructor takes long variables (an integer type), not doubles. Your values will be truncated.
- Marked as answer by Purple_Apple Saturday, March 14, 2020 4:42 PM
Saturday, March 14, 2020 4:10 PM -
I bag your pardon. I've got mistake in types (long inside double). Excuse me please.
- Marked as answer by Purple_Apple Saturday, March 14, 2020 4:12 PM
Saturday, March 14, 2020 4:12 PM -
Yes, yes it's my fault. I was a little tired in the evening and because of this, inattention appeared. Thank you very much.Saturday, March 14, 2020 4:42 PM