## class Line – the code

```class Line{
Point endPointA,endPointB;
Line dualLine;

Line(Point ap,Point bp){              // with known endpoints
if(ap==bp) {
println( " *********** new Line: IDENTICAL endpoints,  a==b, NO LINE");
return;
}
endPointA=ap;
endPointB=bp;
}

Line(){                     // only the existence is known
}

void setDual(Line d){           // define the dual line
dualLine=d;
}

void eliminateUndefinedDual(){       // eliminate undefined dual
if(dualLine==null) return;
if(dualLine.undefined()) dualLine=null;
}

void setAnEndPoint(Point p){       //  set one endpoint (dual lines, orientation not important)
if(endPointA==null) {
endPointA=p;
return;
}
if(endPointB==null) {
endPointB=p;
return;
}
println(" setAnEndPoint: both are already occupied");
}

boolean undefined(){
if((endPointA==null)||(endPointB==null)) return true;
return ((endPointA.vec==null)||(endPointB.vec==null));

}
//---------------------------------------------------------------------------------------

void show(){
//  if (undefined()) return;
line(endPointA.vec.x,endPointA.vec.y,endPointB.vec.x,endPointB.vec.y);
}

//----------------------------------------------------------------------------------------------
//  return other endpoint than given endpoint, note: may be null

Point getOtherEndPoint(Point p){
if(endPointA==p) return endPointB;
if(endPointB==p) return endPointA;
println(" Problem in otherEndPointA:  point p not found");
Point nothing=null;
return nothing;
}

//  search for common endpoint

Point commonEndPoint(Line two){
if((endPointA==two.endPointA)||(endPointA==two.endPointB)) return endPointA;
if((endPointB==two.endPointA)||(endPointB==two.endPointB)) return endPointB;
println(" no common endpoint");
Point nothing=null;
return nothing;
}
}```
This entry was posted in programming and tagged , , . Bookmark the permalink.