intersects method
Implementation
bool intersects(Line line) {
final PointsOrientation o1 = getOrientation(source, target, line.source);
final PointsOrientation o2 = getOrientation(source, target, line.target);
final PointsOrientation o3 =
getOrientation(line.source, line.target, source);
final PointsOrientation o4 =
getOrientation(line.source, line.target, target);
if (o1 != o2 && o3 != o4) {
return true;
}
// source, target and line.source are colinear and line.source lies on segment this.source-this.target
if (o1 == PointsOrientation.collinear &&
onSegmentPoints(source, line.source, target)) {
return true;
}
// source, target and line.source are collinear and line.target lies on segment source-target
if (o2 == PointsOrientation.collinear &&
onSegmentPoints(source, line.target, target)) {
return true;
}
// line.source, line.target and source are collinear and source lies on segment line.source-line.target
if (o3 == PointsOrientation.collinear &&
onSegmentPoints(line.source, source, line.target)) {
return true;
}
// line.source, line.target and target are collinear and target lies on segment line.source-line.target
if (o4 == PointsOrientation.collinear &&
onSegmentPoints(line.source, target, line.target)) {
return true;
}
return false;
}