element
Class Line

java.lang.Object
  |
  +--element.Line

public class Line
extends java.lang.Object
implements Drawable

A line segment object.


Constructor Summary
Line()
          Construct a trivial line segment at the origin.
Line(int x0, int y0, int x1, int y1)
          Construct a line segment from the explicit points.
Line(Line l)
          Construct a line segment from another.
Line(Pt p, Pt q)
          Construct a line segment from its two endpoints.
Line(Rect r)
          Construct a line segment from (left,top) to (right,bottom) of a rectangle.
 
Method Summary
 int bottom()
          Return the bottom-most coordinate of the segment.
 void bottom(int y)
          Move the line segment so that bottom is at y.
 Pt center()
          Determine the midpoint of the line segment.
 void center(Pt p)
          Adjust line so that midpoint falls at p.
 void clearOn(DrawingWindow d)
          Erase the line from the drawing window d in current mode.
 java.lang.Object clone()
          Return a copy of this line segment.
 boolean contains(Pt p)
          Return true if the point p is close to the line segment
 void drawOn(DrawingWindow d)
          Draw the line on the drawing window d in current mode.
 boolean equals(java.lang.Object other)
          Returns true if two line segments are equal
 void fillOn(DrawingWindow d)
          Draw the line on the drawing window d in current mode.
 int hashCode()
          Returns hash code for the line segment.
 int height()
          Determine the vertical span of the line segment
 Pt here()
          Returns one endpoint of the line.
 int left()
          Return the left-most coordinate of the segment.
 void left(int x)
          Move line segment so that left side is at x.
 int right()
          Return the right-most coordinate of the segment
 void right(int x)
          Move line segment so that right side is at x.
 Pt there()
          Returns other endpoint of the line.
 int top()
          Return the top-most coordinate of the segment.
 void top(int y)
          Move the line segment so that top is at y.
 java.lang.String toString()
          Return a string representation of the line segment
 int width()
          Determine the horizontal span of the line segment
protected static boolean within(int x, int low, int range)
          Determine if a value falls between two others.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Line

public Line()
Construct a trivial line segment at the origin.

Line

public Line(Line l)
Construct a line segment from another.
Parameters:
l - another line segment.

Line

public Line(Rect r)
Construct a line segment from (left,top) to (right,bottom) of a rectangle.
Parameters:
r - the rectangle.

Line

public Line(int x0,
            int y0,
            int x1,
            int y1)
Construct a line segment from the explicit points.
Parameters:
x0 - one x coordinate
y0 - one y coordinate
x1 - other x coordinate
y1 - other y coordinate

Line

public Line(Pt p,
            Pt q)
Construct a line segment from its two endpoints.
Parameters:
p - one endpoint
q - the other endpoint
Method Detail

left

public int left()
Return the left-most coordinate of the segment.
Specified by:
left in interface Drawable
Tags copied from interface: Drawable
Returns:
the leftmost coordinate of the bounding box of the object

right

public int right()
Return the right-most coordinate of the segment
Specified by:
right in interface Drawable
Tags copied from interface: Drawable
Returns:
the rightmost coordinate of the bounding box of the object

top

public int top()
Return the top-most coordinate of the segment.
Specified by:
top in interface Drawable
Tags copied from interface: Drawable
Returns:
the top coordinate of the bounding box of the object

bottom

public int bottom()
Return the bottom-most coordinate of the segment.
Specified by:
bottom in interface Drawable
Tags copied from interface: Drawable
Returns:
the bottom coordinate of the bounding box of the object

left

public void left(int x)
Move line segment so that left side is at x.
Parameters:
x - new left side of line segment

right

public void right(int x)
Move line segment so that right side is at x.
Parameters:
x - new right side of the line segment

top

public void top(int y)
Move the line segment so that top is at y.
Parameters:
y - new top side of the line segment.

bottom

public void bottom(int y)
Move the line segment so that bottom is at y.
Parameters:
y - new bottom side of the line segment

width

public int width()
Determine the horizontal span of the line segment
Specified by:
width in interface Drawable
Returns:
the horizontal span of the line segment

height

public int height()
Determine the vertical span of the line segment
Specified by:
height in interface Drawable
Returns:
the vertical span of the line segment

center

public Pt center()
Determine the midpoint of the line segment.
Specified by:
center in interface Drawable
Returns:
the midpoint of the line segment.

center

public void center(Pt p)
Adjust line so that midpoint falls at p.
Specified by:
center in interface Drawable
Parameters:
p - the new midpoint of the line.

here

public Pt here()
Returns one endpoint of the line.

there

public Pt there()
Returns other endpoint of the line.

within

protected static boolean within(int x,
                                int low,
                                int range)
Determine if a value falls between two others.
Returns:
true if low <= x <= range

contains

public boolean contains(Pt p)
Return true if the point p is close to the line segment
Parameters:
p - the point in question
Returns:
true if p is on the line segment

fillOn

public void fillOn(DrawingWindow d)
Draw the line on the drawing window d in current mode.
Specified by:
fillOn in interface Drawable
Parameters:
d - the target window d
See Also:
DrawingWindow.draw(element.Drawable), DrawingWindow.invertMode(), DrawingWindow.paintMode()

clearOn

public void clearOn(DrawingWindow d)
Erase the line from the drawing window d in current mode.
Specified by:
clearOn in interface Drawable
Parameters:
d - the target window d
See Also:
DrawingWindow.clear(element.Drawable), DrawingWindow.invertMode(), DrawingWindow.paintMode()

drawOn

public void drawOn(DrawingWindow d)
Draw the line on the drawing window d in current mode.
Specified by:
drawOn in interface Drawable
Parameters:
d - the target window d
See Also:
DrawingWindow.draw(element.Drawable), DrawingWindow.invertMode(), DrawingWindow.paintMode()

hashCode

public int hashCode()
Returns hash code for the line segment.
Overrides:
hashCode in class java.lang.Object
Returns:
hash code for the line segment

equals

public boolean equals(java.lang.Object other)
Returns true if two line segments are equal
Overrides:
equals in class java.lang.Object
Parameters:
other - the other line segment
Returns:
true if the segments have equal value

clone

public java.lang.Object clone()
Return a copy of this line segment.
Overrides:
clone in class java.lang.Object
Returns:
copy of this line segment.

toString

public java.lang.String toString()
Return a string representation of the line segment
Overrides:
toString in class java.lang.Object
Returns: