How long is a line?

Discussion in 'Java' started by Chris Berg, Jan 23, 2004.

  1. Chris Berg

    Chris Berg Guest

    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
    Chris Berg, Jan 23, 2004
    #1
    1. Advertising

  2. In article <>,
    Chris Berg <> 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
    Steve W. Jackson, Jan 23, 2004
    #2
    1. Advertising

  3. Chris Berg

    Chris Uppal Guest

    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
    Chris Uppal, Jan 23, 2004
    #3
  4. Chris Berg

    Dale King Guest

    "Chris Berg" <> wrote in message
    news:...
    > 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
    Dale King, Jan 23, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    674
    Eric Sosman
    Jul 8, 2003
  2. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,186
    Peter Shaggy Haywood
    Sep 20, 2005
  3. Mathieu Dutour

    long long and long

    Mathieu Dutour, Jul 17, 2007, in forum: C Programming
    Replies:
    4
    Views:
    473
    santosh
    Jul 24, 2007
  4. Bart C

    Use of Long and Long Long

    Bart C, Jan 9, 2008, in forum: C Programming
    Replies:
    27
    Views:
    797
    Peter Nilsson
    Jan 15, 2008
  5. veryhotsausage
    Replies:
    1
    Views:
    1,799
    veryhotsausage
    Jul 4, 2008
Loading...

Share This Page