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