#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 myray1.vert(); }
    rational slope () const { return myray1.slope(); }
    rational xcept () const { return myray1.xcept(); }
    line ln () const { return myray1.ln(); }
    ratpoint pt1 () const { return myray1.startpt(); }
    ratpoint pt2 () const { return myray2.startpt(); }
    ray ray1 () const { return myray1; }
    ray ray2 () const { return myray2; }

    void makelineseg ( const ratpoint & rp1, const ratpoint & rp2 );
    
    // other functions
    bool hitpoint ( ratpoint & x ); // lineseg goes through this point?
    bool intersect ( lineseg & x ); // lineseg other lineseg @ 1point?
    bool intersect ( ray & x ); // lineseg other lineseg @ 1point?
    bool intersect ( line & x ); // lineseg other lineseg @ 1point?
    ratpoint intersection ( lineseg & x ); // What is intersection?
    ratpoint intersection ( ray & x ); // What is intersection?
    ratpoint intersection ( 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:
    ray myray1;
    ray myray2;

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

};
// class declaration ends here

#endif


