|
Last change
on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Prototype 1.1
|
-
Property mode
set to
100644
|
|
File size:
346 bytes
|
| Line | |
|---|
| 1 | export default function(polygon) {
|
|---|
| 2 | var i = -1,
|
|---|
| 3 | n = polygon.length,
|
|---|
| 4 | x = 0,
|
|---|
| 5 | y = 0,
|
|---|
| 6 | a,
|
|---|
| 7 | b = polygon[n - 1],
|
|---|
| 8 | c,
|
|---|
| 9 | k = 0;
|
|---|
| 10 |
|
|---|
| 11 | while (++i < n) {
|
|---|
| 12 | a = b;
|
|---|
| 13 | b = polygon[i];
|
|---|
| 14 | k += c = a[0] * b[1] - b[0] * a[1];
|
|---|
| 15 | x += (a[0] + b[0]) * c;
|
|---|
| 16 | y += (a[1] + b[1]) * c;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | return k *= 3, [x / k, y / k];
|
|---|
| 20 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.