CDC::LineTo() clipping 
Author Message
 CDC::LineTo() clipping

I have a question about how windows clips line segments using the
CDC::LineTo() function.  I'm drawing some mapping coordinates which get
converted from a latitude/longitude coordinate to a pixel coordinate.  I
then draw lines between the points.

Depending upon how close in the user has zoomed in, the point to which I
need to draw may be way off the screen.  Windows seems to handle this OK up
to some undefined point but beyond that it starts drawing stray lines all
over the place.  For example, if I'm drawing from pixel location (100, 100)
to a pixel location (5000, 5000) which is off the screen, Windows does a
fine job at drawing the line and clipping it at the window's boundary.  But
if I try to draw to a pixel location much farther off the screen, say
(1000000, 1000000) then it starts drawing weird lines everywhere.

If I knew the maximum limit to which Windows to correct draw to offscreen
points then I could filter out points that are beyond that limit.  Does
anybody know what the limit is?

Phil McAdams



Fri, 23 Aug 2002 03:00:00 GMT  
 CDC::LineTo() clipping
If you are running on Win9x, you are running on a toy 16-bit OS, a
warmed-over Windows 3.1 GDI that was designed for the 8088. Your
scaling requires more than 16 bits of precision, and you are seeing
the truncation effects of the high-order 16 bits being discarded.
There are two solutions: scale it yourself so the only coordinates you
send to GDI fit in the 16-bit range, or move to a real operating
system with 32-bit GDI coordinates.
                        joe

On Mon, 6 Mar 2000 15:53:15 -0700, "Phil McAdams"

Quote:

>I have a question about how windows clips line segments using the
>CDC::LineTo() function.  I'm drawing some mapping coordinates which get
>converted from a latitude/longitude coordinate to a pixel coordinate.  I
>then draw lines between the points.

>Depending upon how close in the user has zoomed in, the point to which I
>need to draw may be way off the screen.  Windows seems to handle this OK up
>to some undefined point but beyond that it starts drawing stray lines all
>over the place.  For example, if I'm drawing from pixel location (100, 100)
>to a pixel location (5000, 5000) which is off the screen, Windows does a
>fine job at drawing the line and clipping it at the window's boundary.  But
>if I try to draw to a pixel location much farther off the screen, say
>(1000000, 1000000) then it starts drawing weird lines everywhere.

>If I knew the maximum limit to which Windows to correct draw to offscreen
>points then I could filter out points that are beyond that limit.  Does
>anybody know what the limit is?

>Phil McAdams

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Sat, 24 Aug 2002 03:00:00 GMT  
 CDC::LineTo() clipping
Phil!

You are running into a disgusting little problem. The first part is that
coordinates must be 16-bit in Win95/98 - that is well known. But the second
part is that some screen drivers wrap around when you hit the ceiling, while
others don't. I don't think it will help you to set an explicit clip rect
(you can always try - but if the coords wrap, the endpoints should still
fall inside the valid rect), but you might want to check into LineDDA for
more advanced line-drawing possibilities.

Johan Rosengren
Responsable Informatique
PACTA S.A.



Quote:
> I have a question about how windows clips line segments using the
> CDC::LineTo() function.  I'm drawing some mapping coordinates which get
> converted from a latitude/longitude coordinate to a pixel coordinate.  I
> then draw lines between the points.

> Depending upon how close in the user has zoomed in, the point to which I
> need to draw may be way off the screen.  Windows seems to handle this OK
up
> to some undefined point but beyond that it starts drawing stray lines all
> over the place.  For example, if I'm drawing from pixel location (100,
100)
> to a pixel location (5000, 5000) which is off the screen, Windows does a
> fine job at drawing the line and clipping it at the window's boundary.
But
> if I try to draw to a pixel location much farther off the screen, say
> (1000000, 1000000) then it starts drawing weird lines everywhere.

> If I knew the maximum limit to which Windows to correct draw to offscreen
> points then I could filter out points that are beyond that limit.  Does
> anybody know what the limit is?

> Phil McAdams



Sat, 24 Aug 2002 03:00:00 GMT  
 CDC::LineTo() clipping

Quote:

> I have a question about how windows clips line segments using the
> CDC::LineTo() function.  I'm drawing some mapping coordinates which get
> converted from a latitude/longitude coordinate to a pixel coordinate.  I
> then draw lines between the points.

> Depending upon how close in the user has zoomed in, the point to which I
> need to draw may be way off the screen.  Windows seems to handle this OK up
> to some undefined point but beyond that it starts drawing stray lines all
> over the place.  For example, if I'm drawing from pixel location (100, 100)
> to a pixel location (5000, 5000) which is off the screen, Windows does a
> fine job at drawing the line and clipping it at the window's boundary.  But
> if I try to draw to a pixel location much farther off the screen, say
> (1000000, 1000000) then it starts drawing weird lines everywhere.

> If I knew the maximum limit to which Windows to correct draw to offscreen
> points then I could filter out points that are beyond that limit.  Does
> anybody know what the limit is?

> Phil McAdams

I've run into this problem too. Windows 98 GDI can only handle 16 bit signed
coordinates,
i.e. points are limited to -32768 to +32767. Points outside this range will get
drawn in
strange locations. I solved it by scaling all coordinates such that they are
divided by a
scale factor. If the resulting window extent is greater than +/- 32000 then the
scale
factor is increased, if less than 1000 then the scale factor is reduced. Your
zoomin/
zoomout code will therefore need to modify the scale factor depending on the
data extent.

- Keith



Sat, 24 Aug 2002 03:00:00 GMT  
 CDC::LineTo() clipping
Thanks everyone.  I was afraid that it was really limited to a signed 16 bit
integer although it doesn't seem to specifically state that in the MFC help.
For my particular app it will work best for me to just not attempt to draw
lines that exceed 32767 (or negative).  Thanks!

Phil McAdams


Quote:
> I have a question about how windows clips line segments using the
> CDC::LineTo() function.  I'm drawing some mapping coordinates which get
> converted from a latitude/longitude coordinate to a pixel coordinate.  I
> then draw lines between the points.

> Depending upon how close in the user has zoomed in, the point to which I
> need to draw may be way off the screen.  Windows seems to handle this OK
up
> to some undefined point but beyond that it starts drawing stray lines all
> over the place.  For example, if I'm drawing from pixel location (100,
100)
> to a pixel location (5000, 5000) which is off the screen, Windows does a
> fine job at drawing the line and clipping it at the window's boundary.
But
> if I try to draw to a pixel location much farther off the screen, say
> (1000000, 1000000) then it starts drawing weird lines everywhere.

> If I knew the maximum limit to which Windows to correct draw to offscreen
> points then I could filter out points that are beyond that limit.  Does
> anybody know what the limit is?

> Phil McAdams



Sat, 24 Aug 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. does the LineTo perform a quick clip arithmetic?

2. Can CDC::LineTo() draw dot line like windows folder tree view

3. CDC::LineTo

4. CDC:LineTo() Problem?

5. CDC::LineTo and antialiasing

6. CDC::LineTo bug in 95?

7. CDC LineTo drawing bug ?

8. CDC::LineTo - doesn't always draw?

9. CDC::Clipping

10. clipping CDC's borders

11. CDC::GetPixel() returns a -1 as if the pixel is not in clip region

12. Is C# Clipping Like C++ Clipping?

 

 
Powered by phpBB® Forum Software