#include "lineseg.h"
#include <assert.h>

// constructors and desctructor 
lineseg::lineseg ( void ) {
}

lineseg::lineseg ( const lineseg & xxx )
{
  myray1 = xxx.ray1();
  myray2 = xxx.ray2();
}

lineseg::lineseg ( const ratpoint & rp1, const ratpoint & rp2 ) {
  myray1 = ray(rp1,rp2);
  myray2 = ray(rp2,rp1);
}

void lineseg::makelineseg ( const ratpoint & rp1, const ratpoint & rp2 ) {
  myray1 = ray(rp1,rp2);
  myray2 = ray(rp2,rp1);
}

lineseg::~lineseg ( ) {
}

// overloading of the assignment operator =
lineseg & lineseg::operator = ( const lineseg & x )
{
  myray1 = x.ray1();
  myray2 = x.ray2();

  // return a reference to THIS object so that we
  // can write x =.y() = z = ...
  return *this;
}

// overloading of the output operator
ostream & operator << ( ostream & out , const lineseg & x )
{
  return
  out << "Segment from " << x.myray1.startpt() << " to " << x.myray2.startpt();
}

bool lineseg::hitpoint ( ratpoint & x ) {
  return(myray1.hitpoint(x) && myray2.hitpoint(x));
}

bool lineseg::intersect (line & x) {
  return (myray1.intersect(x) && myray2.intersect(x));
}

bool lineseg::intersect (ray & x) {
  return (myray1.intersect(x) && myray2.intersect(x));
}

bool lineseg::intersect (lineseg & x) {
  return (x.intersect(myray1) && x.intersect(myray2));
}

ratpoint lineseg::intersection (line & x) {
  return(myray1.intersection(x));
}

ratpoint lineseg::intersection (ray & x) {
  return(myray1.intersection(x));
}

ratpoint lineseg::intersection (lineseg & x) {
  return(x.intersection(myray1));
}

void lineseg::reverse (void) {
  ray tempray;
  tempray = myray1;
  myray1 = myray2;
  myray2 = tempray;
}
