|
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:
973 bytes
|
| Line | |
|---|
| 1 | import {Adder} from "d3-array";
|
|---|
| 2 | import {abs} from "../math.js";
|
|---|
| 3 | import noop from "../noop.js";
|
|---|
| 4 |
|
|---|
| 5 | var areaSum = new Adder(),
|
|---|
| 6 | areaRingSum = new Adder(),
|
|---|
| 7 | x00,
|
|---|
| 8 | y00,
|
|---|
| 9 | x0,
|
|---|
| 10 | y0;
|
|---|
| 11 |
|
|---|
| 12 | var areaStream = {
|
|---|
| 13 | point: noop,
|
|---|
| 14 | lineStart: noop,
|
|---|
| 15 | lineEnd: noop,
|
|---|
| 16 | polygonStart: function() {
|
|---|
| 17 | areaStream.lineStart = areaRingStart;
|
|---|
| 18 | areaStream.lineEnd = areaRingEnd;
|
|---|
| 19 | },
|
|---|
| 20 | polygonEnd: function() {
|
|---|
| 21 | areaStream.lineStart = areaStream.lineEnd = areaStream.point = noop;
|
|---|
| 22 | areaSum.add(abs(areaRingSum));
|
|---|
| 23 | areaRingSum = new Adder();
|
|---|
| 24 | },
|
|---|
| 25 | result: function() {
|
|---|
| 26 | var area = areaSum / 2;
|
|---|
| 27 | areaSum = new Adder();
|
|---|
| 28 | return area;
|
|---|
| 29 | }
|
|---|
| 30 | };
|
|---|
| 31 |
|
|---|
| 32 | function areaRingStart() {
|
|---|
| 33 | areaStream.point = areaPointFirst;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | function areaPointFirst(x, y) {
|
|---|
| 37 | areaStream.point = areaPoint;
|
|---|
| 38 | x00 = x0 = x, y00 = y0 = y;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | function areaPoint(x, y) {
|
|---|
| 42 | areaRingSum.add(y0 * x - x0 * y);
|
|---|
| 43 | x0 = x, y0 = y;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | function areaRingEnd() {
|
|---|
| 47 | areaPoint(x00, y00);
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | export default areaStream;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.