Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   How long is a line? (http://www.velocityreviews.com/forums/t130642-how-long-is-a-line.html)

Chris Berg 01-23-2004 11:56 AM

How long is a line?
 
In java.awt.Graphics, this is what they say about drawLine(..):

/**
* Draws a line, using the current color, between the points
* <code>(x1,&nbsp;y1)</code> and <code>(x2,&nbsp;y2)</code>
* in this graphics context's coordinate system.
* @param x1 the first point's <i>x</i> coordinate.
* @param y1 the first point's <i>y</i> coordinate.
* @param x2 the second point's <i>x</i> coordinate.
* @param y2 the second point's <i>y</i> coordinate.
*/
public abstract void drawLine(int x1, int y1, int x2, int y2);

But how long is the line? Or, to be more precise, does it include both
end-points? The reason I ask, is that this seems to be different on
different platforms. On Sun VM on Win, and on MS VM, both end-points
are included, but on OSX on Mac w. IE, the last point is not, or so it
seems. Shouldn't Sun have been more precise here? Is it specified
better somewhere else in Sun's papers? And if not, is it really too
late now?

Chris


Steve W. Jackson 01-23-2004 03:33 PM

Re: How long is a line?
 
In article <hg2210pc7cilvnrf8tggphbdm97igqf8lo@4ax.com>,
Chris Berg <spam.spam.eggs@nd.spam> wrote:

>:In java.awt.Graphics, this is what they say about drawLine(..):
>:
>: /**
>: * Draws a line, using the current color, between the points
>: * <code>(x1,&nbsp;y1)</code> and <code>(x2,&nbsp;y2)</code>
>: * in this graphics context's coordinate system.
>: * @param x1 the first point's <i>x</i> coordinate.
>: * @param y1 the first point's <i>y</i> coordinate.
>: * @param x2 the second point's <i>x</i> coordinate.
>: * @param y2 the second point's <i>y</i> coordinate.
>: */
>: public abstract void drawLine(int x1, int y1, int x2, int y2);
>:
>:But how long is the line? Or, to be more precise, does it include both
>:end-points? The reason I ask, is that this seems to be different on
>:different platforms. On Sun VM on Win, and on MS VM, both end-points
>:are included, but on OSX on Mac w. IE, the last point is not, or so it
>:seems. Shouldn't Sun have been more precise here? Is it specified
>:better somewhere else in Sun's papers? And if not, is it really too
>:late now?
>:
>:Chris


My reading of that would likewise lead me to believe that both end
points are included. However, since Graphics is an abstract class, the
actual instances you get would (presumably) be provided by the host OS.
Perhaps Apple chose, for whatever reason, to implement it such that the
destination end point isn't drawn to. In my brief tinkering with my
application (I don't do applets), I saw no evidence of that, but I
didn't really look *that* closely. If indeed there's a problem, you're
probably best touching base with Java developers in the Mac community
for confirmation and/or workarounds if it's a problem. Pay a visit to <http://developer.apple.com/java/>.

= Steve =
--
Steve W. Jackson
Montgomery, Alabama

Chris Uppal 01-23-2004 04:11 PM

Re: How long is a line?
 
Chris Berg wrote:

> Shouldn't Sun have been more precise here? Is it specified
> better somewhere else in Sun's papers? And if not, is it really too
> late now?


From the class comment for java.awt.Graphics:

==============
Coordinates are infinitely thin and lie between the pixels of the
output device. Operations that draw the outline of a figure operate
by traversing an infinitely thin path between pixels with a pixel-sized
pen that hangs down and to the right of the anchor point on the path.

==============

So I think that Sun did specify that a line should include its endpoints.

However, see the package comment for java.awt.Graphics2D for the more complex
picture that obtains when the default settings are not used.

-- chris



Dale King 01-23-2004 09:27 PM

Re: How long is a line?
 
"Chris Berg" <spam.spam.eggs@nd.spam> wrote in message
news:hg2210pc7cilvnrf8tggphbdm97igqf8lo@4ax.com...
> In java.awt.Graphics, this is what they say about drawLine(..):
>
> /**
> * Draws a line, using the current color, between the points
> * <code>(x1,&nbsp;y1)</code> and <code>(x2,&nbsp;y2)</code>
> * in this graphics context's coordinate system.
> * @param x1 the first point's <i>x</i> coordinate.
> * @param y1 the first point's <i>y</i> coordinate.
> * @param x2 the second point's <i>x</i> coordinate.
> * @param y2 the second point's <i>y</i> coordinate.
> */
> public abstract void drawLine(int x1, int y1, int x2, int y2);
>
> But how long is the line? Or, to be more precise, does it include both
> end-points? The reason I ask, is that this seems to be different on
> different platforms. On Sun VM on Win, and on MS VM, both end-points
> are included, but on OSX on Mac w. IE, the last point is not, or so it
> seems. Shouldn't Sun have been more precise here? Is it specified
> better somewhere else in Sun's papers? And if not, is it really too
> late now?



For Java 1.1 (which includes M$ VM) all bets are off.

With Java2D API this is well specified and controllable. The line can even
extend beyond the endpoint, but that is under your control. With
anti-aliasing it is even possible to sort of draw in part of a pixel.

With Java2D you have to quit thinking of coordinates in as being pixels. The
mapping between coordinates is controlled by the AffineTransform.

You control how a shape is drawn by setting the Stroke on the Graphics2D
object. I don't believe this affects the old drawLine function however. It
does affect draw operations with Shape.

You can read the Java2D tutorial here:
http://java.sun.com/docs/books/tutorial/2d/index.html

Unfortunately none of this great Java2D stuff works with the MicroSlop VM.
--
Dale King




All times are GMT. The time now is 10:19 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.