// 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()); }