source: node_modules/d3-geo/src/path/measure.js@ a762898

Last change on this file since a762898 was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 854 bytes
Line 
1import {Adder} from "d3-array";
2import {sqrt} from "../math.js";
3import noop from "../noop.js";
4
5var lengthSum = new Adder(),
6 lengthRing,
7 x00,
8 y00,
9 x0,
10 y0;
11
12var lengthStream = {
13 point: noop,
14 lineStart: function() {
15 lengthStream.point = lengthPointFirst;
16 },
17 lineEnd: function() {
18 if (lengthRing) lengthPoint(x00, y00);
19 lengthStream.point = noop;
20 },
21 polygonStart: function() {
22 lengthRing = true;
23 },
24 polygonEnd: function() {
25 lengthRing = null;
26 },
27 result: function() {
28 var length = +lengthSum;
29 lengthSum = new Adder();
30 return length;
31 }
32};
33
34function lengthPointFirst(x, y) {
35 lengthStream.point = lengthPoint;
36 x00 = x0 = x, y00 = y0 = y;
37}
38
39function lengthPoint(x, y) {
40 x0 -= x, y0 -= y;
41 lengthSum.add(sqrt(x0 * x0 + y0 * y0));
42 x0 = x, y0 = y;
43}
44
45export default lengthStream;
Note: See TracBrowser for help on using the repository browser.