processPolygon function
Processes a polygon to determine the right and left tangents.
Implementation
List<Position> processPolygon(List<Position> polygonCoords,
Position pointCoords, double eprev, Position rtan, Position ltan) {
for (int i = 0; i < polygonCoords.length; i++) {
final currentCoords = polygonCoords[i];
var nextCoords = polygonCoords[(i + 1) % polygonCoords.length];
final enext = isLeft(currentCoords, nextCoords, pointCoords);
if (eprev <= 0 && enext > 0) {
if (!isBelow(pointCoords, currentCoords, rtan)) {
rtan = currentCoords;
}
} else if (eprev > 0 && enext <= 0) {
if (!isAbove(pointCoords, currentCoords, ltan)) {
ltan = currentCoords;
}
} else if (eprev > 0 && enext <= 0) {
if (!isAbove(pointCoords, currentCoords, ltan)) {
ltan = currentCoords;
}
}
eprev = enext.toDouble();
}
return [rtan, ltan];
}