insideOrOutsideOfLine2 static method
判断某个点是在在两个点连线的里边还是外边2
Implementation
static int insideOrOutsideOfLine2(Offset left, Offset right, Offset point,
{required bool inRight}) {
if (inRight && left.dx < right.dx && left.dy > right.dy) {
//判断左上角
if (point.dx.inRange(left.dx, right.dx) &&
point.dy.inRange(left.dy, right.dy)) {
final slope1 = calculateSlope(left, right);
final slope2 = calculateSlope(left, point);
if (slope2 > slope1) {
return 1; //里边
} else if (slope2 < slope1) {
return -1; //外边
}
}
} else if (!inRight && left.dx < right.dx && left.dy < right.dy) {
//判断右上角
if (point.dx.inRange(left.dx, right.dx) &&
point.dy.inRange(left.dy, right.dy)) {
final slope1 = calculateSlope(left, right);
final slope2 = calculateSlope(point, right);
if (slope2 > slope1) {
return 1; //里边
} else if (slope2 < slope1) {
return -1; //外边
}
}
} else if (!inRight && left.dx < right.dx && left.dy > right.dy) {
//判断右下角
if (point.dx.inRange(left.dx, right.dx) &&
point.dy.inRange(left.dy, right.dy)) {
final slope1 = calculateSlope(left, right);
final slope2 = calculateSlope(left, point);
if (slope2 > slope1) {
return -1; //外边
} else if (slope2 < slope1) {
return 1; //里边
}
}
} else if (inRight && left.dx < right.dx && left.dy < right.dy) {
//判断左下角
if (point.dx.inRange(left.dx, right.dx) &&
point.dy.inRange(left.dy, right.dy)) {
final slope1 = calculateSlope(left, right);
final slope2 = calculateSlope(point, right);
if (slope2 > slope1) {
return -1; //外边
} else if (slope2 < slope1) {
return 1; //里边
}
}
}
return 0; //相等
}