#ifndef CXX_COURSE_LINESEG_H
#define CXX_COURSE_LINESEG_H

// include the header necessary for input/output
#include <iostream.h>
#include "ratpoint.h"
#include "rational.h"
#include "line.h"
#include "ray.h"

// class declaration begins here
class lineseg
{
  public:
    // constructors and destructor 
    lineseg ();
    lineseg ( const lineseg & x );
    lineseg ( const ratpoint & rp1 , const ratpoint & rp2 ) ;
    ~lineseg ( );

    // accessors
    bool vert ( ) const { return myline.vert(); }
    rational slope () const { return myline.slope(); }
    rational xcept () const { return myline.xcept(); }
    line ln () const { return myline; }
    ratpoint startpt () const { return mystartpt; }
    bool dir () const { return mydir; }

    void makelineseg ( const ratpoint & rp1, const ratpoint & rp2 );
    
    // other functions
    bool hitpoint ( const ratpoint & x ); // lineseg goes through this point?
    bool intersect ( const lineseg & x ); // lineseg intersects other lineseg @ 1point?
    bool intersect ( const line & x ); // lineseg intersects other lineseg @ 1point?
    ratpoint intersection ( const lineseg & x ); // What is intersection?
    ratpoint intersection ( const line & x ); // What is intersection?
    void reverse ( void ) ; // reverse direction of lineseg

    // overloading of the assignment operator =
    lineseg & operator = ( const lineseg & x );

    // overloading of the input and output operator
    friend ostream & operator << ( ostream & out , const lineseg & x);

  private:
    line myline;
    ratpoint mystartpt;
    bool mydir; 

    // error handling routine
    static void error ( char *text )
      {
        cerr << "lineseg error: " << text << endl;
        exit(1);
      }

};
// class declaration ends here

#endif


