isPointInsideContour method
bool
isPointInsideContour(
- Point point, {
- bool raycasting = true,
})
Implementation
bool isPointInsideContour(Point point, {bool raycasting = true}) {
bool inside = false;
if(!raycasting) {
int i = 0;
int j = Points.length - 1;
for (; i < Points.length; j = i++) {
final pi = Points[i];
final pj = Points[j];
if (((pi.y > point.y) != (pj.y > point.y)) &&
(point.x <
(pj.x - pi.x) * (point.y - pi.y) / (pj.y - pi.y) + pi.x)) {
inside = !inside;
}
}
}else{
int count = 0;
final int n = Points.length;
for (int i = 0, j = n - 1; i < n; j = i++) {
final pi = Points[i];
final pj = Points[j];
if (((pi.y > point.y) != (pj.y > point.y)) &&
(point.x < (pj.x - pi.x) * (point.y - pi.y) / (pj.y - pi.y) + pi.x)) {
if (point.y <= pi.y) {
if (point.y <= pj.y) {
count++;
} else {
final num cross = (pj.x - pi.x) * (point.y - pi.y) - (pj.y - pi.y) * (point.x - pi.x);
if (cross > 0) {
count++;
}
}
} else if (point.y <= pj.y) {
final num cross = (pj.x - pi.x) * (point.y - pi.y) - (pj.y - pi.y) * (point.x - pi.x);
if (cross < 0) {
count++;
}
}
}
}
if (count % 2 == 1) {
inside = true;
}
}
return inside;
}