computational.geometry
Class Segment

java.lang.Object
  extended by computational.geometry.Segment
All Implemented Interfaces:
Shape, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
Polygon.Edge

public class Segment
extends java.lang.Object
implements Shape, java.lang.Cloneable, java.io.Serializable

See Also:
Serialized Form

Constructor Summary
Segment(int x0, int y0, int x1, int y1)
          CONSTRUCTORS
Segment(Point p0, Point p1)
           
Segment(java.lang.String label, int x0, int y0, int x1, int y1)
           
Segment(java.lang.String label, Point p0, Point p1)
           
 
Method Summary
 Rectangle boundingBox()
           
 java.lang.Object clone()
          Object Extension
 boolean contains(Point p)
          Tells whether the shape encloses a given point.
 void draw(java.awt.Graphics gfx)
          Draws the shape, using the current graphics context's color.
 void drawArrows(java.awt.Graphics gfx)
           
 void drawLabels(java.awt.Graphics gfx)
          Draws the shape's associated labels, using the graphics context's color.
 void drawPoints(java.awt.Graphics gfx)
          Draws the shape's defining points, using the graphics context's color.
 boolean equals(java.lang.Object obj)
          Determines whether or not two segments are equal.
 java.lang.String getLabel()
          Returns the string label associated to this segment.
 java.util.List getPoints()
          Returns a list containing copies of the shape's defining points.
 boolean intersect(Segment s)
           
 double length()
           
 boolean movePoint(Point p, int dx, int dy)
          GET /SET METHODS
 void setLabel(java.lang.String label)
          Sets the segment's label.
 java.lang.String toString()
          Returns a string representation of this segment.
 void translate(int dx, int dy)
          Translates the shape by the given amount.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Segment

public Segment(int x0,
               int y0,
               int x1,
               int y1)
CONSTRUCTORS


Segment

public Segment(Point p0,
               Point p1)

Segment

public Segment(java.lang.String label,
               int x0,
               int y0,
               int x1,
               int y1)

Segment

public Segment(java.lang.String label,
               Point p0,
               Point p1)
Method Detail

boundingBox

public Rectangle boundingBox()

clone

public java.lang.Object clone()
Object Extension

Overrides:
clone in class java.lang.Object

contains

public boolean contains(Point p)
Description copied from interface: Shape
Tells whether the shape encloses a given point. To the aims of this test, we consider the shape to be closed, so that a point lying on the shape's boundaries results as enclosed in the shape.

Specified by:
contains in interface Shape
Parameters:
p - the point we test for encloseness.
Returns:
true iff the point is enclosed in the shape.

draw

public void draw(java.awt.Graphics gfx)
Description copied from interface: Shape
Draws the shape, using the current graphics context's color.

Specified by:
draw in interface Shape
Parameters:
gfx - the graphics context where this shape has to be drawn.

drawArrows

public void drawArrows(java.awt.Graphics gfx)

drawLabels

public void drawLabels(java.awt.Graphics gfx)
Description copied from interface: Shape
Draws the shape's associated labels, using the graphics context's color.

Specified by:
drawLabels in interface Shape
Parameters:
gfx - the graphics context where this shape's labels have to be drawn.

drawPoints

public void drawPoints(java.awt.Graphics gfx)
Description copied from interface: Shape
Draws the shape's defining points, using the graphics context's color.

Specified by:
drawPoints in interface Shape
Parameters:
gfx - the graphics context where this shape's points have to be drawn.

equals

public boolean equals(java.lang.Object obj)
Determines whether or not two segments are equal. Two instances of Segment are equal if their extreme points are equal.

Overrides:
equals in class java.lang.Object
Parameters:
obj - an object to be compared with this Segment
Returns:
true if the object to be compared is an instance of Segment and has the same extreme points; false otherwise.

getLabel

public java.lang.String getLabel()
Returns the string label associated to this segment. The returned string may possibly be empty, but may never be null.

Specified by:
getLabel in interface Shape
Returns:
the string label associated to this segment.

getPoints

public java.util.List getPoints()
Description copied from interface: Shape
Returns a list containing copies of the shape's defining points.

Specified by:
getPoints in interface Shape
Returns:
the shape's cloned defining points.

intersect

public boolean intersect(Segment s)

length

public double length()

movePoint

public boolean movePoint(Point p,
                         int dx,
                         int dy)
GET /SET METHODS


setLabel

public void setLabel(java.lang.String label)
Sets the segment's label.

Specified by:
setLabel in interface Shape
Parameters:
the - segment's new label.

toString

public java.lang.String toString()
Returns a string representation of this segment. The string is composed of the segment's label (if any), and the segment's extreme points.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this segment.

translate

public void translate(int dx,
                      int dy)
Description copied from interface: Shape
Translates the shape by the given amount.

Specified by:
translate in interface Shape
Parameters:
dx - the amount to translate along the X-axis