@duoquote/polytini 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +120 -120
  3. package/dist/types/cli.d.cts +2 -2
  4. package/dist/types/deckgl.d.cts +72 -60
  5. package/dist/types/flexible.d.cts +92 -80
  6. package/dist/types/geojson.jsr.d.cts +111 -0
  7. package/dist/types/google.d.cts +48 -48
  8. package/dist/types/google.jsr.d.cts +72 -60
  9. package/dist/types/index.d.cts +109 -87
  10. package/dist/types/leaflet-auto.d.cts +4 -4
  11. package/dist/types/leaflet-auto.jsr.d.cts +2 -2
  12. package/dist/types/leaflet.d.cts +39 -39
  13. package/dist/types/leaflet.jsr.d.cts +15 -13
  14. package/dist/types/mapbox.d.cts +50 -50
  15. package/dist/types/mapbox.jsr.d.cts +5 -0
  16. package/dist/types/maplibre.d.cts +54 -54
  17. package/dist/types/maplibre.jsr.d.cts +92 -0
  18. package/dist/types/openlayers.d.cts +23 -23
  19. package/dist/types/openlayers.jsr.d.cts +42 -0
  20. package/dist/types/presets.d.cts +70 -66
  21. package/dist/types/turf.d.cts +33 -33
  22. package/dist/types/turf.jsr.d.cts +46 -0
  23. package/dist/types/wasm.d.cts +42 -33
  24. package/package.json +200 -200
  25. package/src/browser.js +15 -15
  26. package/src/bun.js +4 -4
  27. package/src/cli-lib.js +160 -160
  28. package/src/cli.js +7 -7
  29. package/src/core.js +268 -268
  30. package/src/deckgl.js +176 -176
  31. package/src/deno.js +12 -12
  32. package/src/error.js +15 -15
  33. package/src/fast.js +179 -179
  34. package/src/flexible.js +283 -283
  35. package/src/google.js +70 -70
  36. package/src/leaflet-auto.js +11 -11
  37. package/src/leaflet.js +44 -44
  38. package/src/mapbox.js +10 -10
  39. package/src/maplibre.js +57 -57
  40. package/src/node.js +17 -17
  41. package/src/openlayers.js +172 -172
  42. package/src/presets.js +242 -242
  43. package/src/text.js +111 -111
  44. package/src/turf.js +80 -80
  45. package/src/wasm-bytes.js +2 -2
  46. package/src/wasm.js +235 -235
  47. package/src/web.js +9 -9
  48. package/types/cli.d.ts +2 -2
  49. package/types/deckgl.d.ts +72 -60
  50. package/types/flexible.d.ts +92 -80
  51. package/types/geojson.jsr.d.ts +111 -0
  52. package/types/google.d.ts +48 -48
  53. package/types/google.jsr.d.ts +72 -60
  54. package/types/index.d.ts +109 -87
  55. package/types/leaflet-auto.d.ts +4 -4
  56. package/types/leaflet-auto.jsr.d.ts +2 -2
  57. package/types/leaflet.d.ts +39 -39
  58. package/types/leaflet.jsr.d.ts +15 -13
  59. package/types/mapbox.d.ts +50 -50
  60. package/types/mapbox.jsr.d.ts +5 -0
  61. package/types/maplibre.d.ts +54 -54
  62. package/types/maplibre.jsr.d.ts +92 -0
  63. package/types/openlayers.d.ts +23 -23
  64. package/types/openlayers.jsr.d.ts +42 -0
  65. package/types/presets.d.ts +70 -66
  66. package/types/turf.d.ts +33 -33
  67. package/types/turf.jsr.d.ts +46 -0
  68. package/types/wasm.d.ts +42 -33
package/src/deckgl.js CHANGED
@@ -1,176 +1,176 @@
1
- // deck.gl: encoded polylines straight into deck.gl's binary data format, one
2
- // typed array for all lines and no array per point.
3
- //
4
- // import { PathLayer } from '@deck.gl/layers';
5
- // import { binaryPaths } from '@duoquote/polytini/deckgl';
6
- // const data = binaryPaths(routes.map((r) => r.geometry), { precision: 6 });
7
- // new PathLayer({ id: 'routes', data, _pathType: 'open', getWidth: 3 });
8
- //
9
- // The result has the shape deck.gl 9 documents for PathLayer, TripsLayer and
10
- // SolidPolygonLayer:
11
- // { length, startIndices, attributes: { getPath: { value, size } } }
12
- // where startIndices has length + 1 entries, the last one the vertex count,
13
- // and value holds [lng, lat] or [lng, lat, z] per vertex. Positions always
14
- // come out as [lng, lat], whatever `order` the options or a preset say,
15
- // because that is what deck.gl reads.
16
- //
17
- // Each string is decoded twice over its characters: a first pass over all
18
- // strings counts the values (every value ends with exactly one character
19
- // below code 95), so one buffer of the right size is allocated, and a second
20
- // pass decodes into it. Strings the fast loop does not take (bad characters,
21
- // a cut-off value, values of more than 30 bits) go through polytini's exact
22
- // decoder, which throws a PolylineError in strict mode, the default.
23
- //
24
- // PolygonLayer, the composite layer, does not take binary data in deck.gl
25
- // 9.4: it calls getPolygon on every row to build its outlines, and binary
26
- // data has no rows (it fails with "Cannot read properties of undefined").
27
- // For filled polygons with outlines, use a SolidPolygonLayer with
28
- // binaryPolygons data plus a PathLayer with the same buffer as getPath:
29
- // new PathLayer({ data: { ...polys, attributes: { getPath: polys.attributes.getPolygon } }, _pathType: 'open' })
30
- //
31
- // No deck.gl code is imported.
32
- /* @ts-self-types="../types/deckgl.d.ts" */
33
- import { decodeFlat } from './web.js';
34
- import { opts, st, fail } from './core.js';
35
-
36
- // Decodes a 2D string into out[2k], out[2k + 1] as [lng, lat] from vertex k.
37
- // Returns the number of vertices, or -1 when the string needs the exact
38
- // decoder. Writes past the end of a typed array are dropped, and anything
39
- // written for a bad string is overwritten afterwards.
40
- function fill2(str, out, k, f) {
41
- const len = str.length, start = k;
42
- let i = 0, lat = 0, lng = 0, bad = 0, c, v, s;
43
- k *= 2;
44
- while (i < len) {
45
- c = str.charCodeAt(i++) - 63;
46
- bad |= c;
47
- v = c & 31;
48
- for (s = 5; c >= 32; s += 5) {
49
- c = str.charCodeAt(i++) - 63;
50
- bad |= c;
51
- v |= (c & 31) << s;
52
- }
53
- bad |= 30 - s;
54
- lat += (v >>> 1) ^ -(v & 1);
55
- c = str.charCodeAt(i++) - 63;
56
- bad |= c;
57
- v = c & 31;
58
- for (s = 5; c >= 32; s += 5) {
59
- c = str.charCodeAt(i++) - 63;
60
- bad |= c;
61
- v |= (c & 31) << s;
62
- }
63
- bad |= 30 - s;
64
- lng += (v >>> 1) ^ -(v & 1);
65
- out[k++] = lng / f;
66
- out[k++] = lat / f;
67
- }
68
- return bad & ~63 || i != len ? -1 : k / 2 - start;
69
- }
70
-
71
- // The same for d values per point (3 or 4): [lng, lat] plus z when size is
72
- // 3, and the last value into ts when ts is given.
73
- function fillN(str, out, ts, k, d, size, f, zf) {
74
- const len = str.length, start = k, sum = [0, 0, 0, 0];
75
- let i = 0, bad = 0, a, c, v, s, j;
76
- while (i < len) {
77
- for (a = 0; a < d; a++) {
78
- c = str.charCodeAt(i++) - 63;
79
- bad |= c;
80
- v = c & 31;
81
- for (s = 5; c >= 32; s += 5) {
82
- c = str.charCodeAt(i++) - 63;
83
- bad |= c;
84
- v |= (c & 31) << s;
85
- }
86
- bad |= 30 - s;
87
- sum[a] += (v >>> 1) ^ -(v & 1);
88
- }
89
- j = k * size;
90
- out[j] = sum[1] / f;
91
- out[j + 1] = sum[0] / f;
92
- if (size == 3) out[j + 2] = sum[2] / zf;
93
- if (ts) ts[k] = sum[d - 1] / zf;
94
- k++;
95
- }
96
- return bad & ~63 || i != len ? -1 : k - start;
97
- }
98
-
99
- // The exact decoder, for strings the fast loops gave up on. It returns at
100
- // most as many points as the first pass counted, so they fit.
101
- function slow(str, o, out, ts, k, d, size) {
102
- const flat = decodeFlat(str, o), n = flat.length / d;
103
- for (let p = 0; p < n; p++, k++) {
104
- for (let a = 0; a < size; a++) out[k * size + a] = flat[p * d + a];
105
- if (ts) ts[k] = flat[p * d + d - 1];
106
- }
107
- return n;
108
- }
109
-
110
- function build(encoded, o, polygons) {
111
- const list = typeof encoded == 'string' ? [encoded] : encoded;
112
- if (!Array.isArray(list)) fail('input', 'Expected a string or an array of strings');
113
- const f = opts(o), { dims: d, zf } = st, time = !polygons && o != null && typeof o == 'object' && !!o.timestamps;
114
- const size = time ? d - 1 : d;
115
- if (size < 2 || size > 3) fail('option', time ? 'timestamps need dimensions 3 or 4' : 'Invalid dimensions for deck.gl: use 2 or 3, or 4 with timestamps');
116
- const Type = o?.float32 ? Float32Array : Float64Array;
117
- const n = list.length;
118
- // Pass 1: an upper bound of the vertex count, exact for valid strings.
119
- // Polygons get room for one more vertex per ring to close it.
120
- let max = 0;
121
- for (let i = 0; i < n; i++) {
122
- const s = list[i];
123
- if (typeof s != 'string') fail('input', 'Expected a string', i);
124
- let values = 0;
125
- for (let j = 0; j < s.length; j++) values += (s.charCodeAt(j) - 95) >>> 31;
126
- max += ((values / d) | 0) + (polygons ? 1 : 0);
127
- }
128
- const out = new Type(max * size), ts = time ? new Float32Array(max) : null, starts = new Uint32Array(n + 1);
129
- const exact = { ...(typeof o == 'number' ? { precision: o } : o), order: 'lnglat' };
130
- // Pass 2: decode each string at the running vertex offset.
131
- let k = 0;
132
- for (let i = 0; i < n; i++) {
133
- const s = list[i];
134
- starts[i] = k;
135
- let m = d == 2 ? fill2(s, out, k, f) : fillN(s, out, ts, k, d, size, f, zf);
136
- if (m < 0) m = slow(s, exact, out, ts, k, d, size);
137
- if (polygons && m > 0) {
138
- // Close the ring if the last vertex is not the first.
139
- const a = k * size, b = (k + m - 1) * size;
140
- let open = false;
141
- for (let c = 0; c < size; c++) open ||= out[a + c] !== out[b + c];
142
- if (open) {
143
- for (let c = 0; c < size; c++) out[b + size + c] = out[a + c];
144
- m++;
145
- }
146
- }
147
- k += m;
148
- }
149
- starts[n] = k;
150
- const value = k * size < out.length ? out.subarray(0, k * size) : out;
151
- const attributes = polygons ? { getPolygon: { value, size } } : { getPath: { value, size } };
152
- if (ts) attributes.getTimestamps = { value: k < ts.length ? ts.subarray(0, k) : ts, size: 1 };
153
- return { length: n, startIndices: starts, attributes };
154
- }
155
-
156
- /**
157
- * Binary data for PathLayer and TripsLayer: one path per string. Options:
158
- * polytini options or a preset, plus `float32` (Float32Array instead of
159
- * Float64Array) and, for TripsLayer, `timestamps`: the last value of each
160
- * point (dimensions 3 or 4) goes to attributes.getTimestamps instead of the
161
- * positions. Timestamps are always a Float32Array: TripsLayer's timestamp
162
- * attribute is 32-bit, and deck.gl 9.4 drew nothing for a TripsLayer given
163
- * Float64Array timestamps (checked in test/deckgl.test.js). Keep them small,
164
- * for example seconds since the start of the trip.
165
- */
166
- export const binaryPaths = (encoded, options) => build(encoded, options, false);
167
-
168
- /**
169
- * Binary data for SolidPolygonLayer: one ring per string, closed (the first
170
- * vertex is repeated at the end when it is not there already). The binary
171
- * format has no holes. With _normalize: false deck.gl uses the rings as
172
- * they are, so for extruded polygons they must also be in the layer's
173
- * _windingOrder; leave _normalize on when the winding is unknown.
174
- * Options: polytini options or a preset, plus float32.
175
- */
176
- export const binaryPolygons = (encoded, options) => build(encoded, options, true);
1
+ // deck.gl: encoded polylines straight into deck.gl's binary data format, one
2
+ // typed array for all lines and no array per point.
3
+ //
4
+ // import { PathLayer } from '@deck.gl/layers';
5
+ // import { binaryPaths } from '@duoquote/polytini/deckgl';
6
+ // const data = binaryPaths(routes.map((r) => r.geometry), { precision: 6 });
7
+ // new PathLayer({ id: 'routes', data, _pathType: 'open', getWidth: 3 });
8
+ //
9
+ // The result has the shape deck.gl 9 documents for PathLayer, TripsLayer and
10
+ // SolidPolygonLayer:
11
+ // { length, startIndices, attributes: { getPath: { value, size } } }
12
+ // where startIndices has length + 1 entries, the last one the vertex count,
13
+ // and value holds [lng, lat] or [lng, lat, z] per vertex. Positions always
14
+ // come out as [lng, lat], whatever `order` the options or a preset say,
15
+ // because that is what deck.gl reads.
16
+ //
17
+ // Each string is decoded twice over its characters: a first pass over all
18
+ // strings counts the values (every value ends with exactly one character
19
+ // below code 95), so one buffer of the right size is allocated, and a second
20
+ // pass decodes into it. Strings the fast loop does not take (bad characters,
21
+ // a cut-off value, values of more than 30 bits) go through polytini's exact
22
+ // decoder, which throws a PolylineError in strict mode, the default.
23
+ //
24
+ // PolygonLayer, the composite layer, does not take binary data in deck.gl
25
+ // 9.4: it calls getPolygon on every row to build its outlines, and binary
26
+ // data has no rows (it fails with "Cannot read properties of undefined").
27
+ // For filled polygons with outlines, use a SolidPolygonLayer with
28
+ // binaryPolygons data plus a PathLayer with the same buffer as getPath:
29
+ // new PathLayer({ data: { ...polys, attributes: { getPath: polys.attributes.getPolygon } }, _pathType: 'open' })
30
+ //
31
+ // No deck.gl code is imported.
32
+ /* @ts-self-types="../types/deckgl.d.ts" */
33
+ import { decodeFlat } from './web.js';
34
+ import { opts, st, fail } from './core.js';
35
+
36
+ // Decodes a 2D string into out[2k], out[2k + 1] as [lng, lat] from vertex k.
37
+ // Returns the number of vertices, or -1 when the string needs the exact
38
+ // decoder. Writes past the end of a typed array are dropped, and anything
39
+ // written for a bad string is overwritten afterwards.
40
+ function fill2(str, out, k, f) {
41
+ const len = str.length, start = k;
42
+ let i = 0, lat = 0, lng = 0, bad = 0, c, v, s;
43
+ k *= 2;
44
+ while (i < len) {
45
+ c = str.charCodeAt(i++) - 63;
46
+ bad |= c;
47
+ v = c & 31;
48
+ for (s = 5; c >= 32; s += 5) {
49
+ c = str.charCodeAt(i++) - 63;
50
+ bad |= c;
51
+ v |= (c & 31) << s;
52
+ }
53
+ bad |= 30 - s;
54
+ lat += (v >>> 1) ^ -(v & 1);
55
+ c = str.charCodeAt(i++) - 63;
56
+ bad |= c;
57
+ v = c & 31;
58
+ for (s = 5; c >= 32; s += 5) {
59
+ c = str.charCodeAt(i++) - 63;
60
+ bad |= c;
61
+ v |= (c & 31) << s;
62
+ }
63
+ bad |= 30 - s;
64
+ lng += (v >>> 1) ^ -(v & 1);
65
+ out[k++] = lng / f;
66
+ out[k++] = lat / f;
67
+ }
68
+ return bad & ~63 || i != len ? -1 : k / 2 - start;
69
+ }
70
+
71
+ // The same for d values per point (3 or 4): [lng, lat] plus z when size is
72
+ // 3, and the last value into ts when ts is given.
73
+ function fillN(str, out, ts, k, d, size, f, zf) {
74
+ const len = str.length, start = k, sum = [0, 0, 0, 0];
75
+ let i = 0, bad = 0, a, c, v, s, j;
76
+ while (i < len) {
77
+ for (a = 0; a < d; a++) {
78
+ c = str.charCodeAt(i++) - 63;
79
+ bad |= c;
80
+ v = c & 31;
81
+ for (s = 5; c >= 32; s += 5) {
82
+ c = str.charCodeAt(i++) - 63;
83
+ bad |= c;
84
+ v |= (c & 31) << s;
85
+ }
86
+ bad |= 30 - s;
87
+ sum[a] += (v >>> 1) ^ -(v & 1);
88
+ }
89
+ j = k * size;
90
+ out[j] = sum[1] / f;
91
+ out[j + 1] = sum[0] / f;
92
+ if (size == 3) out[j + 2] = sum[2] / zf;
93
+ if (ts) ts[k] = sum[d - 1] / zf;
94
+ k++;
95
+ }
96
+ return bad & ~63 || i != len ? -1 : k - start;
97
+ }
98
+
99
+ // The exact decoder, for strings the fast loops gave up on. It returns at
100
+ // most as many points as the first pass counted, so they fit.
101
+ function slow(str, o, out, ts, k, d, size) {
102
+ const flat = decodeFlat(str, o), n = flat.length / d;
103
+ for (let p = 0; p < n; p++, k++) {
104
+ for (let a = 0; a < size; a++) out[k * size + a] = flat[p * d + a];
105
+ if (ts) ts[k] = flat[p * d + d - 1];
106
+ }
107
+ return n;
108
+ }
109
+
110
+ function build(encoded, o, polygons) {
111
+ const list = typeof encoded == 'string' ? [encoded] : encoded;
112
+ if (!Array.isArray(list)) fail('input', 'Expected a string or an array of strings');
113
+ const f = opts(o), { dims: d, zf } = st, time = !polygons && o != null && typeof o == 'object' && !!o.timestamps;
114
+ const size = time ? d - 1 : d;
115
+ if (size < 2 || size > 3) fail('option', time ? 'timestamps need dimensions 3 or 4' : 'Invalid dimensions for deck.gl: use 2 or 3, or 4 with timestamps');
116
+ const Type = o?.float32 ? Float32Array : Float64Array;
117
+ const n = list.length;
118
+ // Pass 1: an upper bound of the vertex count, exact for valid strings.
119
+ // Polygons get room for one more vertex per ring to close it.
120
+ let max = 0;
121
+ for (let i = 0; i < n; i++) {
122
+ const s = list[i];
123
+ if (typeof s != 'string') fail('input', 'Expected a string', i);
124
+ let values = 0;
125
+ for (let j = 0; j < s.length; j++) values += (s.charCodeAt(j) - 95) >>> 31;
126
+ max += ((values / d) | 0) + (polygons ? 1 : 0);
127
+ }
128
+ const out = new Type(max * size), ts = time ? new Float32Array(max) : null, starts = new Uint32Array(n + 1);
129
+ const exact = { ...(typeof o == 'number' ? { precision: o } : o), order: 'lnglat' };
130
+ // Pass 2: decode each string at the running vertex offset.
131
+ let k = 0;
132
+ for (let i = 0; i < n; i++) {
133
+ const s = list[i];
134
+ starts[i] = k;
135
+ let m = d == 2 ? fill2(s, out, k, f) : fillN(s, out, ts, k, d, size, f, zf);
136
+ if (m < 0) m = slow(s, exact, out, ts, k, d, size);
137
+ if (polygons && m > 0) {
138
+ // Close the ring if the last vertex is not the first.
139
+ const a = k * size, b = (k + m - 1) * size;
140
+ let open = false;
141
+ for (let c = 0; c < size; c++) open ||= out[a + c] !== out[b + c];
142
+ if (open) {
143
+ for (let c = 0; c < size; c++) out[b + size + c] = out[a + c];
144
+ m++;
145
+ }
146
+ }
147
+ k += m;
148
+ }
149
+ starts[n] = k;
150
+ const value = k * size < out.length ? out.subarray(0, k * size) : out;
151
+ const attributes = polygons ? { getPolygon: { value, size } } : { getPath: { value, size } };
152
+ if (ts) attributes.getTimestamps = { value: k < ts.length ? ts.subarray(0, k) : ts, size: 1 };
153
+ return { length: n, startIndices: starts, attributes };
154
+ }
155
+
156
+ /**
157
+ * Binary data for PathLayer and TripsLayer: one path per string. Options:
158
+ * polytini options or a preset, plus `float32` (Float32Array instead of
159
+ * Float64Array) and, for TripsLayer, `timestamps`: the last value of each
160
+ * point (dimensions 3 or 4) goes to attributes.getTimestamps instead of the
161
+ * positions. Timestamps are always a Float32Array: TripsLayer's timestamp
162
+ * attribute is 32-bit, and deck.gl 9.4 drew nothing for a TripsLayer given
163
+ * Float64Array timestamps (checked in test/deckgl.test.js). Keep them small,
164
+ * for example seconds since the start of the trip.
165
+ */
166
+ export const binaryPaths = (encoded, options) => build(encoded, options, false);
167
+
168
+ /**
169
+ * Binary data for SolidPolygonLayer: one ring per string, closed (the first
170
+ * vertex is repeated at the end when it is not there already). The binary
171
+ * format has no holes. With _normalize: false deck.gl uses the rings as
172
+ * they are, so for extruded polygons they must also be in the layer's
173
+ * _windingOrder; leave _normalize on when the winding is unknown.
174
+ * Options: polytini options or a preset, plus float32.
175
+ */
176
+ export const binaryPolygons = (encoded, options) => build(encoded, options, true);
package/src/deno.js CHANGED
@@ -1,12 +1,12 @@
1
- // Deno entry: the core plus the TextEncoder/TextDecoder byte paths in
2
- // text.js. Deno has no global Buffer, and node:buffer measured slower than
3
- // the portable core there (see the README), so this doesn't use it.
4
- /* @ts-self-types="../types/index.d.ts" */
5
- import { decode, encode } from './text.js';
6
- import { latLngs, toGeo, fromGeo } from './core.js';
7
-
8
- export { PolylineError } from './core.js';
9
- export { decode, decodeFlat, encode, encodeFlat } from './text.js';
10
- export const decodeLatLng = /* @__PURE__ */ latLngs(decode);
11
- export const toGeoJSON = /* @__PURE__ */ toGeo(decode);
12
- export const fromGeoJSON = /* @__PURE__ */ fromGeo(encode);
1
+ // Deno entry: the core plus the TextEncoder/TextDecoder byte paths in
2
+ // text.js. Deno has no global Buffer, and node:buffer measured slower than
3
+ // the portable core there (see the README), so this doesn't use it.
4
+ /* @ts-self-types="../types/index.d.ts" */
5
+ import { decode, encode } from './text.js';
6
+ import { latLngs, toGeo, fromGeo } from './core.js';
7
+
8
+ export { PolylineError } from './core.js';
9
+ export { decode, decodeFlat, encode, encodeFlat } from './text.js';
10
+ export const decodeLatLng = /* @__PURE__ */ latLngs(decode);
11
+ export const toGeoJSON = /* @__PURE__ */ toGeo(decode);
12
+ export const fromGeoJSON = /* @__PURE__ */ fromGeo(encode);
package/src/error.js CHANGED
@@ -1,15 +1,15 @@
1
- // The error type every entry point and subpath throws. Its own module, so
2
- // subpaths that only need the error (like /flexible) don't pull in the
3
- // Google-format code.
4
- export class PolylineError extends Error {
5
- constructor(code, message, index) {
6
- super(index == null ? message : message + ' at ' + index);
7
- this.name = 'PolylineError';
8
- this.code = code;
9
- this.index = index;
10
- }
11
- }
12
-
13
- export const fail = (code, message, index) => {
14
- throw new PolylineError(code, message, index);
15
- };
1
+ // The error type every entry point and subpath throws. Its own module, so
2
+ // subpaths that only need the error (like /flexible) don't pull in the
3
+ // Google-format code.
4
+ export class PolylineError extends Error {
5
+ constructor(code, message, index) {
6
+ super(index == null ? message : message + ' at ' + index);
7
+ this.name = 'PolylineError';
8
+ this.code = code;
9
+ this.index = index;
10
+ }
11
+ }
12
+
13
+ export const fail = (code, message, index) => {
14
+ throw new PolylineError(code, message, index);
15
+ };