예제 #1
0
 bool LineSegment::operator<(const LineSegment& other) const {
   clog << *this << " < " << other << endl;
   bool yasc_flag, ydesc_flag, xasc_flag, xdesc_flag;
   if(this->getLeftEndPoint().x < other.getLeftEndPoint().x) {
     ydesc_flag = ydesc(*this,other);
     yasc_flag = yasc(*this,other);
   } else {
     yasc_flag = ydesc(other,*this);
     ydesc_flag = yasc(other,*this);
   }
   if(this->getBottomEndPoint().y < other.getBottomEndPoint().y) {
     xdesc_flag = xdesc(*this,other);
     xasc_flag = xasc(*this,other);
   } else {
     xasc_flag = xdesc(other,*this);
     xdesc_flag = xasc(other,*this);
   }
   if(ydesc_flag) {
     clog << "ydesc flag" << endl;
     return true;
   } else if(yasc_flag) {
     clog << "yasc flag" << endl;
     return false;
   } else if(xdesc_flag) {
     clog << "xdesc flag" << endl;
     return true;
   } else if(xasc_flag) {
     clog << "xasc flag" << endl;
     return false;
   }
   clog << "equal?" << endl;
   // xasc or equal
   return false;
 }
예제 #2
0
  // returns true if left belongs above right in ascending order
  bool LineSegment::yasc(const LineSegment& left, const LineSegment& right) {
    // both vertical
    if(left.isVertical() && right.isVertical()) {
      if(left.getBottomEndPoint().y < right.getBottomEndPoint().y)
	return true;
      if(left.getBottomEndPoint().y > right.getBottomEndPoint().y)
	return false;
      return left.getTopEndPoint().y < right.getTopEndPoint().y;
    }
    // left is vertical
    if(left.isVertical())
      return left.getBottomEndPoint().y < right.getLeftEndPoint().y;
    // left.left, left.right, right.left colinear
    if(Point2D::colinear(left.getLeftEndPoint(),
			 left.getRightEndPoint(),
			 right.getLeftEndPoint())) {
      // all points colinear
      if(Point2D::colinear(left.getLeftEndPoint(),
			   left.getRightEndPoint(),
			   right.getRightEndPoint())) {
	return left.getBottomEndPoint().y < right.getBottomEndPoint().y;
      }
      // only 3 colinear
      return Point2D::leftTurn(left.getLeftEndPoint(),
			       left.getRightEndPoint(),
			       right.getRightEndPoint());
    }
    // normal case
    return Point2D::leftTurn(left.getLeftEndPoint(),
			     left.getRightEndPoint(),
			     right.getLeftEndPoint());
  }
예제 #3
0
  bool LineSegment::xasc(const LineSegment& bottom, const LineSegment& top) {
    // both horizontal
    if(bottom.isHorizontal() && top.isHorizontal())
      return bottom.getLeftEndPoint().x < top.getLeftEndPoint().x;
    // left is vertical
    if(bottom.isHorizontal())
      return bottom.getLeftEndPoint().x < top.getBottomEndPoint().x;
    // left.left, left.right, right.left colinear
    if(Point2D::colinear(bottom.getBottomEndPoint(),
			 bottom.getTopEndPoint(),
			 top.getBottomEndPoint()))
      return Point2D::leftTurn(bottom.getBottomEndPoint(),
			       bottom.getTopEndPoint(),
			       top.getTopEndPoint());
    // normal case
    return Point2D::leftTurn(bottom.getBottomEndPoint(),
			     bottom.getTopEndPoint(),
			     top.getBottomEndPoint());
  }