How long is a line?

C

Chris Berg

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
 
S

Steve W. Jackson

Chris Berg said:
: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 =
 
C

Chris Uppal

Chris said:
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
 
D

Dale King

Chris Berg said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top