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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s