You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
export default function(polygon) { |
|
var i = -1, |
|
n = polygon.length, |
|
x = 0, |
|
y = 0, |
|
a, |
|
b = polygon[n - 1], |
|
c, |
|
k = 0; |
|
|
|
while (++i < n) { |
|
a = b; |
|
b = polygon[i]; |
|
k += c = a[0] * b[1] - b[0] * a[1]; |
|
x += (a[0] + b[0]) * c; |
|
y += (a[1] + b[1]) * c; |
|
} |
|
|
|
return k *= 3, [x / k, y / k]; |
|
}
|
|
|