Esempio n. 1
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());
  }
Esempio n. 2
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());
  }