1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import adder from "../adder";
import {abs} from "../math";
import noop from "../noop";
var areaSum = adder(),
areaRingSum = adder(),
x00,
y00,
x0,
y0;
var areaStream = {
point: noop,
lineStart: noop,
lineEnd: noop,
polygonStart: function() {
areaStream.lineStart = areaRingStart;
areaStream.lineEnd = areaRingEnd;
},
polygonEnd: function() {
areaStream.lineStart = areaStream.lineEnd = areaStream.point = noop;
areaSum.add(abs(areaRingSum));
areaRingSum.reset();
},
result: function() {
var area = areaSum / 2;
areaSum.reset();
return area;
}
};
function areaRingStart() {
areaStream.point = areaPointFirst;
}
function areaPointFirst(x, y) {
areaStream.point = areaPoint;
x00 = x0 = x, y00 = y0 = y;
}
function areaPoint(x, y) {
areaRingSum.add(y0 * x - x0 * y);
x0 = x, y0 = y;
}
function areaRingEnd() {
areaPoint(x00, y00);
}
export default areaStream;