001package scene;
002
003import java.awt.Color;
004
005/**
006   A LineSegment object has two Vertex objects that represent the endpoints of the line segment.
007*/
008public class LineSegment
009{
010   public Vertex[] v = new Vertex[2]; // the vertices of this line segment
011
012   /**
013      Create a LineSegment object with references to the two given Vertex objects.
014
015      @param v0 1st endpoint of te new LineSegment
016      @param v1 2nd endpoint of the new LineSegment
017   */
018   public LineSegment(Vertex v0, Vertex v1)
019   {
020      v[0] = v0;
021      v[1] = v1;
022   }
023
024
025   /**
026      Create a LineSegment object with references to the two Vertex
027      objects in the given LineSegment object.
028
029      Notice that this is a "shallow copy" of the given LineSegment object.
030
031      @param ls LineSegment to make a shallow copy of
032   */
033   public LineSegment(LineSegment ls)
034   {
035      this( ls.v[0], ls.v[1] );
036   }
037
038
039   /**
040      Give this LineSegment a uniform color.
041
042      @param c Color for this LineSegment
043   */
044   public void setColor(Color c)
045   {
046      v[0].setColor(c);
047      v[1].setColor(c);
048   }
049
050   /**
051      Give this LineSegment a uniform, but randomly chosen, color.
052   */
053   public void setColorRandom()
054   {
055      v[0].setColorRandom();
056      v[1].setColor(v[0]);
057   }
058
059
060   /**
061      For debugging.
062
063      @return String representation of this LineSegment object
064   */
065   public String toString()
066   {
067      String result = "Line Segment:\n";
068      result += v[0].toString();
069      result += v[1].toString();
070      return result;
071   }
072}