//copy constructor public Segment(Segment s) : base(s) { myPenWidth = s.myPenWidth; x1 = s.x1; x2 = s.x2; y1 = s.y1; y2 = s.y2; myPointA = s.myPointA; myPointB = s.myPointB; }
public void copy(Shape s) { Shape temp; if (s!=null) { temp = new Rect(0,0,1,1,Color.Black); //is s a rectangle...? if (temp.GetType() == s.GetType()) temp = new Rect((Rect)s); else { //is it an oval...? temp = new Oval(0,0,1,1,Color.Black); if (temp.GetType() == s.GetType()) temp = new Oval((Oval)s); else { //is it a line...? temp = new Segment(0,0,1,1,Color.Black,1); if (temp.GetType() == s.GetType()) temp = new Segment((Segment)s); else { //is it a triangle...? Point p1 = new Point(); Point p2 = new Point(); Point p3 = new Point(); temp = new Triangle(p1,p2,p3,Color.Black); if (temp.GetType() == s.GetType()) temp = new Triangle((Triangle)s); } } } //put the brand new copy into myShapes right after(above in the picture) the original myShapes.Insert(myShapes.IndexOf(s)+1,temp); } //if s is null, do nothing return; }