area method Null safety
Get Polygon area
This algorithm could be wrong when work with polygon that contains crossed lines
Implementation
static double area(List<Point> polygon) {
assert(polygon.length >= 3);
final n = polygon.length;
num x = 0, y = 0;
for (var i = 0; i < n; i++) {
final nextI = (i + 1) % n;
x += polygon[i].x * polygon[nextI].y;
y += polygon[i].y * polygon[nextI].x;
}
return (x - y) / 2;
}