@turf/isobands 6.4.0 → 7.0.0-alpha.0

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.
package/dist/js/index.js CHANGED
@@ -1,3564 +1,14 @@
1
- 'use strict';
2
-
3
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
-
5
- var invariant = require('@turf/invariant');
6
- var meta = require('@turf/meta');
7
- var helpers = require('@turf/helpers');
8
- var bbox = _interopDefault(require('@turf/bbox'));
9
- var area = _interopDefault(require('@turf/area'));
10
- var booleanPointInPolygon = _interopDefault(require('@turf/boolean-point-in-polygon'));
11
- var explode = _interopDefault(require('@turf/explode'));
12
- var objectAssign = _interopDefault(require('object-assign'));
13
-
14
- /**
15
- * Takes a {@link Point} grid and returns a correspondent matrix {Array<Array<number>>}
16
- * of the 'property' values
17
- *
18
- * @name gridToMatrix
19
- * @param {FeatureCollection<Point>} grid of points
20
- * @param {Object} [options={}] Optional parameters
21
- * @param {string} [options.zProperty='elevation'] the property name in `points` from which z-values will be pulled
22
- * @param {boolean} [options.flip=false] returns the matrix upside-down
23
- * @param {boolean} [options.flags=false] flags, adding a `matrixPosition` array field ([row, column]) to its properties,
24
- * the grid points with coordinates on the matrix
25
- * @returns {Array<Array<number>>} matrix of property values
26
- * @example
27
- * var extent = [-70.823364, -33.553984, -70.473175, -33.302986];
28
- * var cellSize = 3;
29
- * var grid = turf.pointGrid(extent, cellSize);
30
- * // add a random property to each point between 0 and 60
31
- * for (var i = 0; i < grid.features.length; i++) {
32
- * grid.features[i].properties.elevation = (Math.random() * 60);
33
- * }
34
- * gridToMatrix(grid);
35
- * //= [
36
- * [ 1, 13, 10, 9, 10, 13, 18],
37
- * [34, 8, 5, 4, 5, 8, 13],
38
- * [10, 5, 2, 1, 2, 5, 4],
39
- * [ 0, 4, 56, 19, 1, 4, 9],
40
- * [10, 5, 2, 1, 2, 5, 10],
41
- * [57, 8, 5, 4, 5, 0, 57],
42
- * [ 3, 13, 10, 9, 5, 13, 18],
43
- * [18, 13, 10, 9, 78, 13, 18]
44
- * ]
45
- */
46
- function gridToMatrix(grid, options) {
47
- // Optional parameters
48
- options = options || {};
49
- if (!helpers.isObject(options)) throw new Error("options is invalid");
50
- var zProperty = options.zProperty || "elevation";
51
- var flip = options.flip;
52
- var flags = options.flags;
53
-
54
- // validation
55
- invariant.collectionOf(grid, "Point", "input must contain Points");
56
-
57
- var pointsMatrix = sortPointsByLatLng(grid, flip);
58
-
59
- var matrix = [];
60
- // create property matrix from sorted points
61
- // looping order matters here
62
- for (var r = 0; r < pointsMatrix.length; r++) {
63
- var pointRow = pointsMatrix[r];
64
- var row = [];
65
- for (var c = 0; c < pointRow.length; c++) {
66
- var point = pointRow[c];
67
- // Check if zProperty exist
68
- if (point.properties[zProperty]) row.push(point.properties[zProperty]);
69
- else row.push(0);
70
- // add flags
71
- if (flags === true) point.properties.matrixPosition = [r, c];
72
- }
73
- matrix.push(row);
74
- }
75
-
76
- return matrix;
77
- }
78
-
79
- /**
80
- * Sorts points by latitude and longitude, creating a 2-dimensional array of points
81
- *
82
- * @private
83
- * @param {FeatureCollection<Point>} points GeoJSON Point features
84
- * @param {boolean} [flip=false] returns the matrix upside-down
85
- * @returns {Array<Array<Point>>} points ordered by latitude and longitude
86
- */
87
- function sortPointsByLatLng(points, flip) {
88
- var pointsByLatitude = {};
89
-
90
- // divide points by rows with the same latitude
91
- meta.featureEach(points, function (point) {
92
- var lat = invariant.getCoords(point)[1];
93
- if (!pointsByLatitude[lat]) pointsByLatitude[lat] = [];
94
- pointsByLatitude[lat].push(point);
95
- });
96
-
97
- // sort points (with the same latitude) by longitude
98
- var orderedRowsByLatitude = Object.keys(pointsByLatitude).map(function (lat) {
99
- var row = pointsByLatitude[lat];
100
- var rowOrderedByLongitude = row.sort(function (a, b) {
101
- return invariant.getCoords(a)[0] - invariant.getCoords(b)[0];
102
- });
103
- return rowOrderedByLongitude;
104
- });
105
-
106
- // sort rows (of points with the same latitude) by latitude
107
- var pointMatrix = orderedRowsByLatitude.sort(function (a, b) {
108
- if (flip) return invariant.getCoords(a[0])[1] - invariant.getCoords(b[0])[1];
109
- else return invariant.getCoords(b[0])[1] - invariant.getCoords(a[0])[1];
110
- });
111
-
112
- return pointMatrix;
113
- }
114
-
115
- /*!
116
- * @license GNU Affero General Public License.
117
- * Copyright (c) 2015, 2015 Ronny Lorenz <ronny@tbi.univie.ac.at>
118
- * v. 1.2.0
119
- * https://github.com/RaumZeit/MarchingSquares.js
120
- *
121
- * MarchingSquaresJS is free software: you can redistribute it and/or modify
122
- * it under the terms of the GNU Affero General Public License as published by
123
- * the Free Software Foundation, either version 3 of the License, or
124
- * (at your option) any later version.
125
- *
126
- * MarchingSquaresJS is distributed in the hope that it will be useful,
127
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
128
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
129
- * GNU Affero General Public License for more details.
130
- *
131
- * As additional permission under GNU Affero General Public License version 3
132
- * section 7, third-party projects (personal or commercial) may distribute,
133
- * include, or link against UNMODIFIED VERSIONS of MarchingSquaresJS without the
134
- * requirement that said third-party project for that reason alone becomes
135
- * subject to any requirement of the GNU Affero General Public License version 3.
136
- * Any modifications to MarchingSquaresJS, however, must be shared with the public
137
- * and made available.
138
- *
139
- * In summary this:
140
- * - allows you to use MarchingSquaresJS at no cost
141
- * - allows you to use MarchingSquaresJS for both personal and commercial purposes
142
- * - allows you to distribute UNMODIFIED VERSIONS of MarchingSquaresJS under any
143
- * license as long as this license notice is included
144
- * - enables you to keep the source code of your program that uses MarchingSquaresJS
145
- * undisclosed
146
- * - forces you to share any modifications you have made to MarchingSquaresJS,
147
- * e.g. bug-fixes
148
- *
149
- * You should have received a copy of the GNU Affero General Public License
150
- * along with MarchingSquaresJS. If not, see <http://www.gnu.org/licenses/>.
151
- */
152
- var defaultSettings = {
153
- successCallback: null,
154
- verbose: false,
155
- polygons: false,
156
- };
157
-
158
- var settings = {};
159
-
160
- /*
161
- Compute isobands(s) of a scalar 2D field given a certain
162
- threshold and a bandwidth by applying the Marching Squares
163
- Algorithm. The function returns a list of path coordinates
164
- either for individual polygons within each grid cell, or the
165
- outline of connected polygons.
166
- */
167
- function isoBands(data, minV, bandwidth, options) {
168
- /* process options */
169
- options = options ? options : {};
170
-
171
- var optionKeys = Object.keys(defaultSettings);
172
-
173
- for (var i = 0; i < optionKeys.length; i++) {
174
- var key = optionKeys[i];
175
- var val = options[key];
176
- val =
177
- typeof val !== "undefined" && val !== null ? val : defaultSettings[key];
178
-
179
- settings[key] = val;
180
- }
181
-
182
- if (settings.verbose)
183
- console.log(
184
- "MarchingSquaresJS-isoBands: computing isobands for [" +
185
- minV +
186
- ":" +
187
- (minV + bandwidth) +
188
- "]"
189
- );
190
-
191
- var grid = computeBandGrid(data, minV, bandwidth);
192
-
193
- var ret;
194
- if (settings.polygons) {
195
- if (settings.verbose)
196
- console.log(
197
- "MarchingSquaresJS-isoBands: returning single polygons for each grid cell"
198
- );
199
- ret = BandGrid2Areas(grid);
200
- } else {
201
- if (settings.verbose)
202
- console.log(
203
- "MarchingSquaresJS-isoBands: returning polygon paths for entire data grid"
204
- );
205
- ret = BandGrid2AreaPaths(grid);
206
- }
207
-
208
- if (typeof settings.successCallback === "function")
209
- settings.successCallback(ret);
210
-
211
- return ret;
212
- }
213
-
214
- /*
215
- Thats all for the public interface, below follows the actual
216
- implementation
217
- */
218
-
219
- /* Some private variables */
220
- var Node0 = 64;
221
- var Node1 = 16;
222
- var Node2 = 4;
223
- var Node3 = 1;
224
-
225
- /*
226
- The look-up tables for tracing back the contour path
227
- of isoBands
228
- */
229
-
230
- var isoBandNextXTL = [];
231
- var isoBandNextYTL = [];
232
- var isoBandNextOTL = [];
233
-
234
- var isoBandNextXTR = [];
235
- var isoBandNextYTR = [];
236
- var isoBandNextOTR = [];
237
-
238
- var isoBandNextXRT = [];
239
- var isoBandNextYRT = [];
240
- var isoBandNextORT = [];
241
-
242
- var isoBandNextXRB = [];
243
- var isoBandNextYRB = [];
244
- var isoBandNextORB = [];
245
-
246
- var isoBandNextXBL = [];
247
- var isoBandNextYBL = [];
248
- var isoBandNextOBL = [];
249
-
250
- var isoBandNextXBR = [];
251
- var isoBandNextYBR = [];
252
- var isoBandNextOBR = [];
253
-
254
- var isoBandNextXLT = [];
255
- var isoBandNextYLT = [];
256
- var isoBandNextOLT = [];
257
-
258
- var isoBandNextXLB = [];
259
- var isoBandNextYLB = [];
260
- var isoBandNextOLB = [];
261
-
262
- isoBandNextXRT[85] = isoBandNextXRB[85] = -1;
263
- isoBandNextYRT[85] = isoBandNextYRB[85] = 0;
264
- isoBandNextORT[85] = isoBandNextORB[85] = 1;
265
- isoBandNextXLT[85] = isoBandNextXLB[85] = 1;
266
- isoBandNextYLT[85] = isoBandNextYLB[85] = 0;
267
- isoBandNextOLT[85] = isoBandNextOLB[85] = 1;
268
-
269
- isoBandNextXTL[85] = isoBandNextXTR[85] = 0;
270
- isoBandNextYTL[85] = isoBandNextYTR[85] = -1;
271
- isoBandNextOTL[85] = isoBandNextOBL[85] = 0;
272
- isoBandNextXBR[85] = isoBandNextXBL[85] = 0;
273
- isoBandNextYBR[85] = isoBandNextYBL[85] = 1;
274
- isoBandNextOTR[85] = isoBandNextOBR[85] = 1;
275
-
276
- /* triangle cases */
277
- isoBandNextXLB[1] = isoBandNextXLB[169] = 0;
278
- isoBandNextYLB[1] = isoBandNextYLB[169] = -1;
279
- isoBandNextOLB[1] = isoBandNextOLB[169] = 0;
280
- isoBandNextXBL[1] = isoBandNextXBL[169] = -1;
281
- isoBandNextYBL[1] = isoBandNextYBL[169] = 0;
282
- isoBandNextOBL[1] = isoBandNextOBL[169] = 0;
283
-
284
- isoBandNextXRB[4] = isoBandNextXRB[166] = 0;
285
- isoBandNextYRB[4] = isoBandNextYRB[166] = -1;
286
- isoBandNextORB[4] = isoBandNextORB[166] = 1;
287
- isoBandNextXBR[4] = isoBandNextXBR[166] = 1;
288
- isoBandNextYBR[4] = isoBandNextYBR[166] = 0;
289
- isoBandNextOBR[4] = isoBandNextOBR[166] = 0;
290
-
291
- isoBandNextXRT[16] = isoBandNextXRT[154] = 0;
292
- isoBandNextYRT[16] = isoBandNextYRT[154] = 1;
293
- isoBandNextORT[16] = isoBandNextORT[154] = 1;
294
- isoBandNextXTR[16] = isoBandNextXTR[154] = 1;
295
- isoBandNextYTR[16] = isoBandNextYTR[154] = 0;
296
- isoBandNextOTR[16] = isoBandNextOTR[154] = 1;
297
-
298
- isoBandNextXLT[64] = isoBandNextXLT[106] = 0;
299
- isoBandNextYLT[64] = isoBandNextYLT[106] = 1;
300
- isoBandNextOLT[64] = isoBandNextOLT[106] = 0;
301
- isoBandNextXTL[64] = isoBandNextXTL[106] = -1;
302
- isoBandNextYTL[64] = isoBandNextYTL[106] = 0;
303
- isoBandNextOTL[64] = isoBandNextOTL[106] = 1;
304
-
305
- /* single trapezoid cases */
306
- isoBandNextXLT[2] = isoBandNextXLT[168] = 0;
307
- isoBandNextYLT[2] = isoBandNextYLT[168] = -1;
308
- isoBandNextOLT[2] = isoBandNextOLT[168] = 1;
309
- isoBandNextXLB[2] = isoBandNextXLB[168] = 0;
310
- isoBandNextYLB[2] = isoBandNextYLB[168] = -1;
311
- isoBandNextOLB[2] = isoBandNextOLB[168] = 0;
312
- isoBandNextXBL[2] = isoBandNextXBL[168] = -1;
313
- isoBandNextYBL[2] = isoBandNextYBL[168] = 0;
314
- isoBandNextOBL[2] = isoBandNextOBL[168] = 0;
315
- isoBandNextXBR[2] = isoBandNextXBR[168] = -1;
316
- isoBandNextYBR[2] = isoBandNextYBR[168] = 0;
317
- isoBandNextOBR[2] = isoBandNextOBR[168] = 1;
318
-
319
- isoBandNextXRT[8] = isoBandNextXRT[162] = 0;
320
- isoBandNextYRT[8] = isoBandNextYRT[162] = -1;
321
- isoBandNextORT[8] = isoBandNextORT[162] = 0;
322
- isoBandNextXRB[8] = isoBandNextXRB[162] = 0;
323
- isoBandNextYRB[8] = isoBandNextYRB[162] = -1;
324
- isoBandNextORB[8] = isoBandNextORB[162] = 1;
325
- isoBandNextXBL[8] = isoBandNextXBL[162] = 1;
326
- isoBandNextYBL[8] = isoBandNextYBL[162] = 0;
327
- isoBandNextOBL[8] = isoBandNextOBL[162] = 1;
328
- isoBandNextXBR[8] = isoBandNextXBR[162] = 1;
329
- isoBandNextYBR[8] = isoBandNextYBR[162] = 0;
330
- isoBandNextOBR[8] = isoBandNextOBR[162] = 0;
331
-
332
- isoBandNextXRT[32] = isoBandNextXRT[138] = 0;
333
- isoBandNextYRT[32] = isoBandNextYRT[138] = 1;
334
- isoBandNextORT[32] = isoBandNextORT[138] = 1;
335
- isoBandNextXRB[32] = isoBandNextXRB[138] = 0;
336
- isoBandNextYRB[32] = isoBandNextYRB[138] = 1;
337
- isoBandNextORB[32] = isoBandNextORB[138] = 0;
338
- isoBandNextXTL[32] = isoBandNextXTL[138] = 1;
339
- isoBandNextYTL[32] = isoBandNextYTL[138] = 0;
340
- isoBandNextOTL[32] = isoBandNextOTL[138] = 0;
341
- isoBandNextXTR[32] = isoBandNextXTR[138] = 1;
342
- isoBandNextYTR[32] = isoBandNextYTR[138] = 0;
343
- isoBandNextOTR[32] = isoBandNextOTR[138] = 1;
344
-
345
- isoBandNextXLB[128] = isoBandNextXLB[42] = 0;
346
- isoBandNextYLB[128] = isoBandNextYLB[42] = 1;
347
- isoBandNextOLB[128] = isoBandNextOLB[42] = 1;
348
- isoBandNextXLT[128] = isoBandNextXLT[42] = 0;
349
- isoBandNextYLT[128] = isoBandNextYLT[42] = 1;
350
- isoBandNextOLT[128] = isoBandNextOLT[42] = 0;
351
- isoBandNextXTL[128] = isoBandNextXTL[42] = -1;
352
- isoBandNextYTL[128] = isoBandNextYTL[42] = 0;
353
- isoBandNextOTL[128] = isoBandNextOTL[42] = 1;
354
- isoBandNextXTR[128] = isoBandNextXTR[42] = -1;
355
- isoBandNextYTR[128] = isoBandNextYTR[42] = 0;
356
- isoBandNextOTR[128] = isoBandNextOTR[42] = 0;
357
-
358
- /* single rectangle cases */
359
- isoBandNextXRB[5] = isoBandNextXRB[165] = -1;
360
- isoBandNextYRB[5] = isoBandNextYRB[165] = 0;
361
- isoBandNextORB[5] = isoBandNextORB[165] = 0;
362
- isoBandNextXLB[5] = isoBandNextXLB[165] = 1;
363
- isoBandNextYLB[5] = isoBandNextYLB[165] = 0;
364
- isoBandNextOLB[5] = isoBandNextOLB[165] = 0;
365
-
366
- isoBandNextXBR[20] = isoBandNextXBR[150] = 0;
367
- isoBandNextYBR[20] = isoBandNextYBR[150] = 1;
368
- isoBandNextOBR[20] = isoBandNextOBR[150] = 1;
369
- isoBandNextXTR[20] = isoBandNextXTR[150] = 0;
370
- isoBandNextYTR[20] = isoBandNextYTR[150] = -1;
371
- isoBandNextOTR[20] = isoBandNextOTR[150] = 1;
372
-
373
- isoBandNextXRT[80] = isoBandNextXRT[90] = -1;
374
- isoBandNextYRT[80] = isoBandNextYRT[90] = 0;
375
- isoBandNextORT[80] = isoBandNextORT[90] = 1;
376
- isoBandNextXLT[80] = isoBandNextXLT[90] = 1;
377
- isoBandNextYLT[80] = isoBandNextYLT[90] = 0;
378
- isoBandNextOLT[80] = isoBandNextOLT[90] = 1;
379
-
380
- isoBandNextXBL[65] = isoBandNextXBL[105] = 0;
381
- isoBandNextYBL[65] = isoBandNextYBL[105] = 1;
382
- isoBandNextOBL[65] = isoBandNextOBL[105] = 0;
383
- isoBandNextXTL[65] = isoBandNextXTL[105] = 0;
384
- isoBandNextYTL[65] = isoBandNextYTL[105] = -1;
385
- isoBandNextOTL[65] = isoBandNextOTL[105] = 0;
386
-
387
- isoBandNextXRT[160] = isoBandNextXRT[10] = -1;
388
- isoBandNextYRT[160] = isoBandNextYRT[10] = 0;
389
- isoBandNextORT[160] = isoBandNextORT[10] = 1;
390
- isoBandNextXRB[160] = isoBandNextXRB[10] = -1;
391
- isoBandNextYRB[160] = isoBandNextYRB[10] = 0;
392
- isoBandNextORB[160] = isoBandNextORB[10] = 0;
393
- isoBandNextXLB[160] = isoBandNextXLB[10] = 1;
394
- isoBandNextYLB[160] = isoBandNextYLB[10] = 0;
395
- isoBandNextOLB[160] = isoBandNextOLB[10] = 0;
396
- isoBandNextXLT[160] = isoBandNextXLT[10] = 1;
397
- isoBandNextYLT[160] = isoBandNextYLT[10] = 0;
398
- isoBandNextOLT[160] = isoBandNextOLT[10] = 1;
399
-
400
- isoBandNextXBR[130] = isoBandNextXBR[40] = 0;
401
- isoBandNextYBR[130] = isoBandNextYBR[40] = 1;
402
- isoBandNextOBR[130] = isoBandNextOBR[40] = 1;
403
- isoBandNextXBL[130] = isoBandNextXBL[40] = 0;
404
- isoBandNextYBL[130] = isoBandNextYBL[40] = 1;
405
- isoBandNextOBL[130] = isoBandNextOBL[40] = 0;
406
- isoBandNextXTL[130] = isoBandNextXTL[40] = 0;
407
- isoBandNextYTL[130] = isoBandNextYTL[40] = -1;
408
- isoBandNextOTL[130] = isoBandNextOTL[40] = 0;
409
- isoBandNextXTR[130] = isoBandNextXTR[40] = 0;
410
- isoBandNextYTR[130] = isoBandNextYTR[40] = -1;
411
- isoBandNextOTR[130] = isoBandNextOTR[40] = 1;
412
-
413
- /* single hexagon cases */
414
- isoBandNextXRB[37] = isoBandNextXRB[133] = 0;
415
- isoBandNextYRB[37] = isoBandNextYRB[133] = 1;
416
- isoBandNextORB[37] = isoBandNextORB[133] = 1;
417
- isoBandNextXLB[37] = isoBandNextXLB[133] = 0;
418
- isoBandNextYLB[37] = isoBandNextYLB[133] = 1;
419
- isoBandNextOLB[37] = isoBandNextOLB[133] = 0;
420
- isoBandNextXTL[37] = isoBandNextXTL[133] = -1;
421
- isoBandNextYTL[37] = isoBandNextYTL[133] = 0;
422
- isoBandNextOTL[37] = isoBandNextOTL[133] = 0;
423
- isoBandNextXTR[37] = isoBandNextXTR[133] = 1;
424
- isoBandNextYTR[37] = isoBandNextYTR[133] = 0;
425
- isoBandNextOTR[37] = isoBandNextOTR[133] = 0;
426
-
427
- isoBandNextXBR[148] = isoBandNextXBR[22] = -1;
428
- isoBandNextYBR[148] = isoBandNextYBR[22] = 0;
429
- isoBandNextOBR[148] = isoBandNextOBR[22] = 0;
430
- isoBandNextXLB[148] = isoBandNextXLB[22] = 0;
431
- isoBandNextYLB[148] = isoBandNextYLB[22] = -1;
432
- isoBandNextOLB[148] = isoBandNextOLB[22] = 1;
433
- isoBandNextXLT[148] = isoBandNextXLT[22] = 0;
434
- isoBandNextYLT[148] = isoBandNextYLT[22] = 1;
435
- isoBandNextOLT[148] = isoBandNextOLT[22] = 1;
436
- isoBandNextXTR[148] = isoBandNextXTR[22] = -1;
437
- isoBandNextYTR[148] = isoBandNextYTR[22] = 0;
438
- isoBandNextOTR[148] = isoBandNextOTR[22] = 1;
439
-
440
- isoBandNextXRT[82] = isoBandNextXRT[88] = 0;
441
- isoBandNextYRT[82] = isoBandNextYRT[88] = -1;
442
- isoBandNextORT[82] = isoBandNextORT[88] = 1;
443
- isoBandNextXBR[82] = isoBandNextXBR[88] = 1;
444
- isoBandNextYBR[82] = isoBandNextYBR[88] = 0;
445
- isoBandNextOBR[82] = isoBandNextOBR[88] = 1;
446
- isoBandNextXBL[82] = isoBandNextXBL[88] = -1;
447
- isoBandNextYBL[82] = isoBandNextYBL[88] = 0;
448
- isoBandNextOBL[82] = isoBandNextOBL[88] = 1;
449
- isoBandNextXLT[82] = isoBandNextXLT[88] = 0;
450
- isoBandNextYLT[82] = isoBandNextYLT[88] = -1;
451
- isoBandNextOLT[82] = isoBandNextOLT[88] = 0;
452
-
453
- isoBandNextXRT[73] = isoBandNextXRT[97] = 0;
454
- isoBandNextYRT[73] = isoBandNextYRT[97] = 1;
455
- isoBandNextORT[73] = isoBandNextORT[97] = 0;
456
- isoBandNextXRB[73] = isoBandNextXRB[97] = 0;
457
- isoBandNextYRB[73] = isoBandNextYRB[97] = -1;
458
- isoBandNextORB[73] = isoBandNextORB[97] = 0;
459
- isoBandNextXBL[73] = isoBandNextXBL[97] = 1;
460
- isoBandNextYBL[73] = isoBandNextYBL[97] = 0;
461
- isoBandNextOBL[73] = isoBandNextOBL[97] = 0;
462
- isoBandNextXTL[73] = isoBandNextXTL[97] = 1;
463
- isoBandNextYTL[73] = isoBandNextYTL[97] = 0;
464
- isoBandNextOTL[73] = isoBandNextOTL[97] = 1;
465
-
466
- isoBandNextXRT[145] = isoBandNextXRT[25] = 0;
467
- isoBandNextYRT[145] = isoBandNextYRT[25] = -1;
468
- isoBandNextORT[145] = isoBandNextORT[25] = 0;
469
- isoBandNextXBL[145] = isoBandNextXBL[25] = 1;
470
- isoBandNextYBL[145] = isoBandNextYBL[25] = 0;
471
- isoBandNextOBL[145] = isoBandNextOBL[25] = 1;
472
- isoBandNextXLB[145] = isoBandNextXLB[25] = 0;
473
- isoBandNextYLB[145] = isoBandNextYLB[25] = 1;
474
- isoBandNextOLB[145] = isoBandNextOLB[25] = 1;
475
- isoBandNextXTR[145] = isoBandNextXTR[25] = -1;
476
- isoBandNextYTR[145] = isoBandNextYTR[25] = 0;
477
- isoBandNextOTR[145] = isoBandNextOTR[25] = 0;
478
-
479
- isoBandNextXRB[70] = isoBandNextXRB[100] = 0;
480
- isoBandNextYRB[70] = isoBandNextYRB[100] = 1;
481
- isoBandNextORB[70] = isoBandNextORB[100] = 0;
482
- isoBandNextXBR[70] = isoBandNextXBR[100] = -1;
483
- isoBandNextYBR[70] = isoBandNextYBR[100] = 0;
484
- isoBandNextOBR[70] = isoBandNextOBR[100] = 1;
485
- isoBandNextXLT[70] = isoBandNextXLT[100] = 0;
486
- isoBandNextYLT[70] = isoBandNextYLT[100] = -1;
487
- isoBandNextOLT[70] = isoBandNextOLT[100] = 1;
488
- isoBandNextXTL[70] = isoBandNextXTL[100] = 1;
489
- isoBandNextYTL[70] = isoBandNextYTL[100] = 0;
490
- isoBandNextOTL[70] = isoBandNextOTL[100] = 0;
491
-
492
- /* single pentagon cases */
493
- isoBandNextXRB[101] = isoBandNextXRB[69] = 0;
494
- isoBandNextYRB[101] = isoBandNextYRB[69] = 1;
495
- isoBandNextORB[101] = isoBandNextORB[69] = 0;
496
- isoBandNextXTL[101] = isoBandNextXTL[69] = 1;
497
- isoBandNextYTL[101] = isoBandNextYTL[69] = 0;
498
- isoBandNextOTL[101] = isoBandNextOTL[69] = 0;
499
-
500
- isoBandNextXLB[149] = isoBandNextXLB[21] = 0;
501
- isoBandNextYLB[149] = isoBandNextYLB[21] = 1;
502
- isoBandNextOLB[149] = isoBandNextOLB[21] = 1;
503
- isoBandNextXTR[149] = isoBandNextXTR[21] = -1;
504
- isoBandNextYTR[149] = isoBandNextYTR[21] = 0;
505
- isoBandNextOTR[149] = isoBandNextOTR[21] = 0;
506
-
507
- isoBandNextXBR[86] = isoBandNextXBR[84] = -1;
508
- isoBandNextYBR[86] = isoBandNextYBR[84] = 0;
509
- isoBandNextOBR[86] = isoBandNextOBR[84] = 1;
510
- isoBandNextXLT[86] = isoBandNextXLT[84] = 0;
511
- isoBandNextYLT[86] = isoBandNextYLT[84] = -1;
512
- isoBandNextOLT[86] = isoBandNextOLT[84] = 1;
513
-
514
- isoBandNextXRT[89] = isoBandNextXRT[81] = 0;
515
- isoBandNextYRT[89] = isoBandNextYRT[81] = -1;
516
- isoBandNextORT[89] = isoBandNextORT[81] = 0;
517
- isoBandNextXBL[89] = isoBandNextXBL[81] = 1;
518
- isoBandNextYBL[89] = isoBandNextYBL[81] = 0;
519
- isoBandNextOBL[89] = isoBandNextOBL[81] = 1;
520
-
521
- isoBandNextXRT[96] = isoBandNextXRT[74] = 0;
522
- isoBandNextYRT[96] = isoBandNextYRT[74] = 1;
523
- isoBandNextORT[96] = isoBandNextORT[74] = 0;
524
- isoBandNextXRB[96] = isoBandNextXRB[74] = -1;
525
- isoBandNextYRB[96] = isoBandNextYRB[74] = 0;
526
- isoBandNextORB[96] = isoBandNextORB[74] = 1;
527
- isoBandNextXLT[96] = isoBandNextXLT[74] = 1;
528
- isoBandNextYLT[96] = isoBandNextYLT[74] = 0;
529
- isoBandNextOLT[96] = isoBandNextOLT[74] = 0;
530
- isoBandNextXTL[96] = isoBandNextXTL[74] = 1;
531
- isoBandNextYTL[96] = isoBandNextYTL[74] = 0;
532
- isoBandNextOTL[96] = isoBandNextOTL[74] = 1;
533
-
534
- isoBandNextXRT[24] = isoBandNextXRT[146] = 0;
535
- isoBandNextYRT[24] = isoBandNextYRT[146] = -1;
536
- isoBandNextORT[24] = isoBandNextORT[146] = 1;
537
- isoBandNextXBR[24] = isoBandNextXBR[146] = 1;
538
- isoBandNextYBR[24] = isoBandNextYBR[146] = 0;
539
- isoBandNextOBR[24] = isoBandNextOBR[146] = 1;
540
- isoBandNextXBL[24] = isoBandNextXBL[146] = 0;
541
- isoBandNextYBL[24] = isoBandNextYBL[146] = 1;
542
- isoBandNextOBL[24] = isoBandNextOBL[146] = 1;
543
- isoBandNextXTR[24] = isoBandNextXTR[146] = 0;
544
- isoBandNextYTR[24] = isoBandNextYTR[146] = -1;
545
- isoBandNextOTR[24] = isoBandNextOTR[146] = 0;
546
-
547
- isoBandNextXRB[6] = isoBandNextXRB[164] = -1;
548
- isoBandNextYRB[6] = isoBandNextYRB[164] = 0;
549
- isoBandNextORB[6] = isoBandNextORB[164] = 1;
550
- isoBandNextXBR[6] = isoBandNextXBR[164] = -1;
551
- isoBandNextYBR[6] = isoBandNextYBR[164] = 0;
552
- isoBandNextOBR[6] = isoBandNextOBR[164] = 0;
553
- isoBandNextXLB[6] = isoBandNextXLB[164] = 0;
554
- isoBandNextYLB[6] = isoBandNextYLB[164] = -1;
555
- isoBandNextOLB[6] = isoBandNextOLB[164] = 1;
556
- isoBandNextXLT[6] = isoBandNextXLT[164] = 1;
557
- isoBandNextYLT[6] = isoBandNextYLT[164] = 0;
558
- isoBandNextOLT[6] = isoBandNextOLT[164] = 0;
559
-
560
- isoBandNextXBL[129] = isoBandNextXBL[41] = 0;
561
- isoBandNextYBL[129] = isoBandNextYBL[41] = 1;
562
- isoBandNextOBL[129] = isoBandNextOBL[41] = 1;
563
- isoBandNextXLB[129] = isoBandNextXLB[41] = 0;
564
- isoBandNextYLB[129] = isoBandNextYLB[41] = 1;
565
- isoBandNextOLB[129] = isoBandNextOLB[41] = 0;
566
- isoBandNextXTL[129] = isoBandNextXTL[41] = -1;
567
- isoBandNextYTL[129] = isoBandNextYTL[41] = 0;
568
- isoBandNextOTL[129] = isoBandNextOTL[41] = 0;
569
- isoBandNextXTR[129] = isoBandNextXTR[41] = 0;
570
- isoBandNextYTR[129] = isoBandNextYTR[41] = -1;
571
- isoBandNextOTR[129] = isoBandNextOTR[41] = 0;
572
-
573
- isoBandNextXBR[66] = isoBandNextXBR[104] = 0;
574
- isoBandNextYBR[66] = isoBandNextYBR[104] = 1;
575
- isoBandNextOBR[66] = isoBandNextOBR[104] = 0;
576
- isoBandNextXBL[66] = isoBandNextXBL[104] = -1;
577
- isoBandNextYBL[66] = isoBandNextYBL[104] = 0;
578
- isoBandNextOBL[66] = isoBandNextOBL[104] = 1;
579
- isoBandNextXLT[66] = isoBandNextXLT[104] = 0;
580
- isoBandNextYLT[66] = isoBandNextYLT[104] = -1;
581
- isoBandNextOLT[66] = isoBandNextOLT[104] = 0;
582
- isoBandNextXTL[66] = isoBandNextXTL[104] = 0;
583
- isoBandNextYTL[66] = isoBandNextYTL[104] = -1;
584
- isoBandNextOTL[66] = isoBandNextOTL[104] = 1;
585
-
586
- isoBandNextXRT[144] = isoBandNextXRT[26] = -1;
587
- isoBandNextYRT[144] = isoBandNextYRT[26] = 0;
588
- isoBandNextORT[144] = isoBandNextORT[26] = 0;
589
- isoBandNextXLB[144] = isoBandNextXLB[26] = 1;
590
- isoBandNextYLB[144] = isoBandNextYLB[26] = 0;
591
- isoBandNextOLB[144] = isoBandNextOLB[26] = 1;
592
- isoBandNextXLT[144] = isoBandNextXLT[26] = 0;
593
- isoBandNextYLT[144] = isoBandNextYLT[26] = 1;
594
- isoBandNextOLT[144] = isoBandNextOLT[26] = 1;
595
- isoBandNextXTR[144] = isoBandNextXTR[26] = -1;
596
- isoBandNextYTR[144] = isoBandNextYTR[26] = 0;
597
- isoBandNextOTR[144] = isoBandNextOTR[26] = 1;
598
-
599
- isoBandNextXRB[36] = isoBandNextXRB[134] = 0;
600
- isoBandNextYRB[36] = isoBandNextYRB[134] = 1;
601
- isoBandNextORB[36] = isoBandNextORB[134] = 1;
602
- isoBandNextXBR[36] = isoBandNextXBR[134] = 0;
603
- isoBandNextYBR[36] = isoBandNextYBR[134] = 1;
604
- isoBandNextOBR[36] = isoBandNextOBR[134] = 0;
605
- isoBandNextXTL[36] = isoBandNextXTL[134] = 0;
606
- isoBandNextYTL[36] = isoBandNextYTL[134] = -1;
607
- isoBandNextOTL[36] = isoBandNextOTL[134] = 1;
608
- isoBandNextXTR[36] = isoBandNextXTR[134] = 1;
609
- isoBandNextYTR[36] = isoBandNextYTR[134] = 0;
610
- isoBandNextOTR[36] = isoBandNextOTR[134] = 0;
611
-
612
- isoBandNextXRT[9] = isoBandNextXRT[161] = -1;
613
- isoBandNextYRT[9] = isoBandNextYRT[161] = 0;
614
- isoBandNextORT[9] = isoBandNextORT[161] = 0;
615
- isoBandNextXRB[9] = isoBandNextXRB[161] = 0;
616
- isoBandNextYRB[9] = isoBandNextYRB[161] = -1;
617
- isoBandNextORB[9] = isoBandNextORB[161] = 0;
618
- isoBandNextXBL[9] = isoBandNextXBL[161] = 1;
619
- isoBandNextYBL[9] = isoBandNextYBL[161] = 0;
620
- isoBandNextOBL[9] = isoBandNextOBL[161] = 0;
621
- isoBandNextXLB[9] = isoBandNextXLB[161] = 1;
622
- isoBandNextYLB[9] = isoBandNextYLB[161] = 0;
623
- isoBandNextOLB[9] = isoBandNextOLB[161] = 1;
624
-
625
- /* 8-sided cases */
626
- isoBandNextXRT[136] = 0;
627
- isoBandNextYRT[136] = 1;
628
- isoBandNextORT[136] = 1;
629
- isoBandNextXRB[136] = 0;
630
- isoBandNextYRB[136] = 1;
631
- isoBandNextORB[136] = 0;
632
- isoBandNextXBR[136] = -1;
633
- isoBandNextYBR[136] = 0;
634
- isoBandNextOBR[136] = 1;
635
- isoBandNextXBL[136] = -1;
636
- isoBandNextYBL[136] = 0;
637
- isoBandNextOBL[136] = 0;
638
- isoBandNextXLB[136] = 0;
639
- isoBandNextYLB[136] = -1;
640
- isoBandNextOLB[136] = 0;
641
- isoBandNextXLT[136] = 0;
642
- isoBandNextYLT[136] = -1;
643
- isoBandNextOLT[136] = 1;
644
- isoBandNextXTL[136] = 1;
645
- isoBandNextYTL[136] = 0;
646
- isoBandNextOTL[136] = 0;
647
- isoBandNextXTR[136] = 1;
648
- isoBandNextYTR[136] = 0;
649
- isoBandNextOTR[136] = 1;
650
-
651
- isoBandNextXRT[34] = 0;
652
- isoBandNextYRT[34] = -1;
653
- isoBandNextORT[34] = 0;
654
- isoBandNextXRB[34] = 0;
655
- isoBandNextYRB[34] = -1;
656
- isoBandNextORB[34] = 1;
657
- isoBandNextXBR[34] = 1;
658
- isoBandNextYBR[34] = 0;
659
- isoBandNextOBR[34] = 0;
660
- isoBandNextXBL[34] = 1;
661
- isoBandNextYBL[34] = 0;
662
- isoBandNextOBL[34] = 1;
663
- isoBandNextXLB[34] = 0;
664
- isoBandNextYLB[34] = 1;
665
- isoBandNextOLB[34] = 1;
666
- isoBandNextXLT[34] = 0;
667
- isoBandNextYLT[34] = 1;
668
- isoBandNextOLT[34] = 0;
669
- isoBandNextXTL[34] = -1;
670
- isoBandNextYTL[34] = 0;
671
- isoBandNextOTL[34] = 1;
672
- isoBandNextXTR[34] = -1;
673
- isoBandNextYTR[34] = 0;
674
- isoBandNextOTR[34] = 0;
675
-
676
- isoBandNextXRT[35] = 0;
677
- isoBandNextYRT[35] = 1;
678
- isoBandNextORT[35] = 1;
679
- isoBandNextXRB[35] = 0;
680
- isoBandNextYRB[35] = -1;
681
- isoBandNextORB[35] = 1;
682
- isoBandNextXBR[35] = 1;
683
- isoBandNextYBR[35] = 0;
684
- isoBandNextOBR[35] = 0;
685
- isoBandNextXBL[35] = -1;
686
- isoBandNextYBL[35] = 0;
687
- isoBandNextOBL[35] = 0;
688
- isoBandNextXLB[35] = 0;
689
- isoBandNextYLB[35] = -1;
690
- isoBandNextOLB[35] = 0;
691
- isoBandNextXLT[35] = 0;
692
- isoBandNextYLT[35] = 1;
693
- isoBandNextOLT[35] = 0;
694
- isoBandNextXTL[35] = -1;
695
- isoBandNextYTL[35] = 0;
696
- isoBandNextOTL[35] = 1;
697
- isoBandNextXTR[35] = 1;
698
- isoBandNextYTR[35] = 0;
699
- isoBandNextOTR[35] = 1;
700
-
701
- /* 6-sided cases */
702
- isoBandNextXRT[153] = 0;
703
- isoBandNextYRT[153] = 1;
704
- isoBandNextORT[153] = 1;
705
- isoBandNextXBL[153] = -1;
706
- isoBandNextYBL[153] = 0;
707
- isoBandNextOBL[153] = 0;
708
- isoBandNextXLB[153] = 0;
709
- isoBandNextYLB[153] = -1;
710
- isoBandNextOLB[153] = 0;
711
- isoBandNextXTR[153] = 1;
712
- isoBandNextYTR[153] = 0;
713
- isoBandNextOTR[153] = 1;
714
-
715
- isoBandNextXRB[102] = 0;
716
- isoBandNextYRB[102] = -1;
717
- isoBandNextORB[102] = 1;
718
- isoBandNextXBR[102] = 1;
719
- isoBandNextYBR[102] = 0;
720
- isoBandNextOBR[102] = 0;
721
- isoBandNextXLT[102] = 0;
722
- isoBandNextYLT[102] = 1;
723
- isoBandNextOLT[102] = 0;
724
- isoBandNextXTL[102] = -1;
725
- isoBandNextYTL[102] = 0;
726
- isoBandNextOTL[102] = 1;
727
-
728
- isoBandNextXRT[155] = 0;
729
- isoBandNextYRT[155] = -1;
730
- isoBandNextORT[155] = 0;
731
- isoBandNextXBL[155] = 1;
732
- isoBandNextYBL[155] = 0;
733
- isoBandNextOBL[155] = 1;
734
- isoBandNextXLB[155] = 0;
735
- isoBandNextYLB[155] = 1;
736
- isoBandNextOLB[155] = 1;
737
- isoBandNextXTR[155] = -1;
738
- isoBandNextYTR[155] = 0;
739
- isoBandNextOTR[155] = 0;
740
-
741
- isoBandNextXRB[103] = 0;
742
- isoBandNextYRB[103] = 1;
743
- isoBandNextORB[103] = 0;
744
- isoBandNextXBR[103] = -1;
745
- isoBandNextYBR[103] = 0;
746
- isoBandNextOBR[103] = 1;
747
- isoBandNextXLT[103] = 0;
748
- isoBandNextYLT[103] = -1;
749
- isoBandNextOLT[103] = 1;
750
- isoBandNextXTL[103] = 1;
751
- isoBandNextYTL[103] = 0;
752
- isoBandNextOTL[103] = 0;
753
-
754
- /* 7-sided cases */
755
- isoBandNextXRT[152] = 0;
756
- isoBandNextYRT[152] = 1;
757
- isoBandNextORT[152] = 1;
758
- isoBandNextXBR[152] = -1;
759
- isoBandNextYBR[152] = 0;
760
- isoBandNextOBR[152] = 1;
761
- isoBandNextXBL[152] = -1;
762
- isoBandNextYBL[152] = 0;
763
- isoBandNextOBL[152] = 0;
764
- isoBandNextXLB[152] = 0;
765
- isoBandNextYLB[152] = -1;
766
- isoBandNextOLB[152] = 0;
767
- isoBandNextXLT[152] = 0;
768
- isoBandNextYLT[152] = -1;
769
- isoBandNextOLT[152] = 1;
770
- isoBandNextXTR[152] = 1;
771
- isoBandNextYTR[152] = 0;
772
- isoBandNextOTR[152] = 1;
773
-
774
- isoBandNextXRT[156] = 0;
775
- isoBandNextYRT[156] = -1;
776
- isoBandNextORT[156] = 1;
777
- isoBandNextXBR[156] = 1;
778
- isoBandNextYBR[156] = 0;
779
- isoBandNextOBR[156] = 1;
780
- isoBandNextXBL[156] = -1;
781
- isoBandNextYBL[156] = 0;
782
- isoBandNextOBL[156] = 0;
783
- isoBandNextXLB[156] = 0;
784
- isoBandNextYLB[156] = -1;
785
- isoBandNextOLB[156] = 0;
786
- isoBandNextXLT[156] = 0;
787
- isoBandNextYLT[156] = 1;
788
- isoBandNextOLT[156] = 1;
789
- isoBandNextXTR[156] = -1;
790
- isoBandNextYTR[156] = 0;
791
- isoBandNextOTR[156] = 1;
792
-
793
- isoBandNextXRT[137] = 0;
794
- isoBandNextYRT[137] = 1;
795
- isoBandNextORT[137] = 1;
796
- isoBandNextXRB[137] = 0;
797
- isoBandNextYRB[137] = 1;
798
- isoBandNextORB[137] = 0;
799
- isoBandNextXBL[137] = -1;
800
- isoBandNextYBL[137] = 0;
801
- isoBandNextOBL[137] = 0;
802
- isoBandNextXLB[137] = 0;
803
- isoBandNextYLB[137] = -1;
804
- isoBandNextOLB[137] = 0;
805
- isoBandNextXTL[137] = 1;
806
- isoBandNextYTL[137] = 0;
807
- isoBandNextOTL[137] = 0;
808
- isoBandNextXTR[137] = 1;
809
- isoBandNextYTR[137] = 0;
810
- isoBandNextOTR[137] = 1;
811
-
812
- isoBandNextXRT[139] = 0;
813
- isoBandNextYRT[139] = 1;
814
- isoBandNextORT[139] = 1;
815
- isoBandNextXRB[139] = 0;
816
- isoBandNextYRB[139] = -1;
817
- isoBandNextORB[139] = 0;
818
- isoBandNextXBL[139] = 1;
819
- isoBandNextYBL[139] = 0;
820
- isoBandNextOBL[139] = 0;
821
- isoBandNextXLB[139] = 0;
822
- isoBandNextYLB[139] = 1;
823
- isoBandNextOLB[139] = 0;
824
- isoBandNextXTL[139] = -1;
825
- isoBandNextYTL[139] = 0;
826
- isoBandNextOTL[139] = 0;
827
- isoBandNextXTR[139] = 1;
828
- isoBandNextYTR[139] = 0;
829
- isoBandNextOTR[139] = 1;
830
-
831
- isoBandNextXRT[98] = 0;
832
- isoBandNextYRT[98] = -1;
833
- isoBandNextORT[98] = 0;
834
- isoBandNextXRB[98] = 0;
835
- isoBandNextYRB[98] = -1;
836
- isoBandNextORB[98] = 1;
837
- isoBandNextXBR[98] = 1;
838
- isoBandNextYBR[98] = 0;
839
- isoBandNextOBR[98] = 0;
840
- isoBandNextXBL[98] = 1;
841
- isoBandNextYBL[98] = 0;
842
- isoBandNextOBL[98] = 1;
843
- isoBandNextXLT[98] = 0;
844
- isoBandNextYLT[98] = 1;
845
- isoBandNextOLT[98] = 0;
846
- isoBandNextXTL[98] = -1;
847
- isoBandNextYTL[98] = 0;
848
- isoBandNextOTL[98] = 1;
849
-
850
- isoBandNextXRT[99] = 0;
851
- isoBandNextYRT[99] = 1;
852
- isoBandNextORT[99] = 0;
853
- isoBandNextXRB[99] = 0;
854
- isoBandNextYRB[99] = -1;
855
- isoBandNextORB[99] = 1;
856
- isoBandNextXBR[99] = 1;
857
- isoBandNextYBR[99] = 0;
858
- isoBandNextOBR[99] = 0;
859
- isoBandNextXBL[99] = -1;
860
- isoBandNextYBL[99] = 0;
861
- isoBandNextOBL[99] = 1;
862
- isoBandNextXLT[99] = 0;
863
- isoBandNextYLT[99] = -1;
864
- isoBandNextOLT[99] = 0;
865
- isoBandNextXTL[99] = 1;
866
- isoBandNextYTL[99] = 0;
867
- isoBandNextOTL[99] = 1;
868
-
869
- isoBandNextXRB[38] = 0;
870
- isoBandNextYRB[38] = -1;
871
- isoBandNextORB[38] = 1;
872
- isoBandNextXBR[38] = 1;
873
- isoBandNextYBR[38] = 0;
874
- isoBandNextOBR[38] = 0;
875
- isoBandNextXLB[38] = 0;
876
- isoBandNextYLB[38] = 1;
877
- isoBandNextOLB[38] = 1;
878
- isoBandNextXLT[38] = 0;
879
- isoBandNextYLT[38] = 1;
880
- isoBandNextOLT[38] = 0;
881
- isoBandNextXTL[38] = -1;
882
- isoBandNextYTL[38] = 0;
883
- isoBandNextOTL[38] = 1;
884
- isoBandNextXTR[38] = -1;
885
- isoBandNextYTR[38] = 0;
886
- isoBandNextOTR[38] = 0;
887
-
888
- isoBandNextXRB[39] = 0;
889
- isoBandNextYRB[39] = 1;
890
- isoBandNextORB[39] = 1;
891
- isoBandNextXBR[39] = -1;
892
- isoBandNextYBR[39] = 0;
893
- isoBandNextOBR[39] = 0;
894
- isoBandNextXLB[39] = 0;
895
- isoBandNextYLB[39] = -1;
896
- isoBandNextOLB[39] = 1;
897
- isoBandNextXLT[39] = 0;
898
- isoBandNextYLT[39] = 1;
899
- isoBandNextOLT[39] = 0;
900
- isoBandNextXTL[39] = -1;
901
- isoBandNextYTL[39] = 0;
902
- isoBandNextOTL[39] = 1;
903
- isoBandNextXTR[39] = 1;
904
- isoBandNextYTR[39] = 0;
905
- isoBandNextOTR[39] = 0;
906
-
907
- /*
908
- Define helper functions for the polygon_table
909
- */
910
-
911
- /* triangle cases */
912
- var p00 = function (cell) {
913
- return [
914
- [cell.bottomleft, 0],
915
- [0, 0],
916
- [0, cell.leftbottom],
917
- ];
918
- };
919
- var p01 = function (cell) {
920
- return [
921
- [1, cell.rightbottom],
922
- [1, 0],
923
- [cell.bottomright, 0],
924
- ];
925
- };
926
- var p02 = function (cell) {
927
- return [
928
- [cell.topright, 1],
929
- [1, 1],
930
- [1, cell.righttop],
931
- ];
932
- };
933
- var p03 = function (cell) {
934
- return [
935
- [0, cell.lefttop],
936
- [0, 1],
937
- [cell.topleft, 1],
938
- ];
939
- };
940
- /* trapezoid cases */
941
- var p04 = function (cell) {
942
- return [
943
- [cell.bottomright, 0],
944
- [cell.bottomleft, 0],
945
- [0, cell.leftbottom],
946
- [0, cell.lefttop],
947
- ];
948
- };
949
- var p05 = function (cell) {
950
- return [
951
- [cell.bottomright, 0],
952
- [cell.bottomleft, 0],
953
- [1, cell.righttop],
954
- [1, cell.rightbottom],
955
- ];
956
- };
957
- var p06 = function (cell) {
958
- return [
959
- [1, cell.righttop],
960
- [1, cell.rightbottom],
961
- [cell.topleft, 1],
962
- [cell.topright, 1],
963
- ];
964
- };
965
- var p07 = function (cell) {
966
- return [
967
- [0, cell.leftbottom],
968
- [0, cell.lefttop],
969
- [cell.topleft, 1],
970
- [cell.topright, 1],
971
- ];
972
- };
973
- /* rectangle cases */
974
- var p08 = function (cell) {
975
- return [
976
- [0, 0],
977
- [0, cell.leftbottom],
978
- [1, cell.rightbottom],
979
- [1, 0],
980
- ];
981
- };
982
- var p09 = function (cell) {
983
- return [
984
- [1, 0],
985
- [cell.bottomright, 0],
986
- [cell.topright, 1],
987
- [1, 1],
988
- ];
989
- };
990
- var p10 = function (cell) {
991
- return [
992
- [1, 1],
993
- [1, cell.righttop],
994
- [0, cell.lefttop],
995
- [0, 1],
996
- ];
997
- };
998
- var p11 = function (cell) {
999
- return [
1000
- [cell.bottomleft, 0],
1001
- [0, 0],
1002
- [0, 1],
1003
- [cell.topleft, 1],
1004
- ];
1005
- };
1006
- var p12 = function (cell) {
1007
- return [
1008
- [1, cell.righttop],
1009
- [1, cell.rightbottom],
1010
- [0, cell.leftbottom],
1011
- [0, cell.lefttop],
1012
- ];
1013
- };
1014
- var p13 = function (cell) {
1015
- return [
1016
- [cell.topleft, 1],
1017
- [cell.topright, 1],
1018
- [cell.bottomright, 0],
1019
- [cell.bottomleft, 0],
1020
- ];
1021
- };
1022
- /* square case */
1023
- var p14 = function () {
1024
- return [
1025
- [0, 0],
1026
- [0, 1],
1027
- [1, 1],
1028
- [1, 0],
1029
- ];
1030
- };
1031
- /* pentagon cases */
1032
- var p15 = function (cell) {
1033
- return [
1034
- [1, cell.rightbottom],
1035
- [1, 0],
1036
- [0, 0],
1037
- [0, 1],
1038
- [cell.topleft, 1],
1039
- ];
1040
- };
1041
- /* 1211 || 1011 */
1042
- var p16 = function (cell) {
1043
- return [
1044
- [cell.topright, 1],
1045
- [1, 1],
1046
- [1, 0],
1047
- [0, 0],
1048
- [0, cell.leftbottom],
1049
- ];
1050
- };
1051
- /* 2111 || 0111 */
1052
- var p17 = function (cell) {
1053
- return [
1054
- [1, 0],
1055
- [cell.bottomright, 0],
1056
- [0, cell.lefttop],
1057
- [0, 1],
1058
- [1, 1],
1059
- ];
1060
- };
1061
- /* 1112 || 1110 */
1062
- var p18 = function (cell) {
1063
- return [
1064
- [1, 1],
1065
- [1, cell.righttop],
1066
- [cell.bottomleft, 0],
1067
- [0, 0],
1068
- [0, 1],
1069
- ];
1070
- };
1071
- /* 1121 || 1101 */
1072
- var p19 = function (cell) {
1073
- return [
1074
- [1, cell.righttop],
1075
- [1, cell.rightbottom],
1076
- [0, cell.lefttop],
1077
- [0, 1],
1078
- [cell.topleft, 1],
1079
- ];
1080
- };
1081
- /* 1200 || 1022 */
1082
- var p20 = function (cell) {
1083
- return [
1084
- [1, 1],
1085
- [1, cell.righttop],
1086
- [cell.bottomright, 0],
1087
- [cell.bottomleft, 0],
1088
- [cell.topright, 1],
1089
- ];
1090
- };
1091
- /* 0120 || 2102 */
1092
- var p21 = function (cell) {
1093
- return [
1094
- [1, cell.rightbottom],
1095
- [1, 0],
1096
- [cell.bottomright, 0],
1097
- [0, cell.leftbottom],
1098
- [0, cell.lefttop],
1099
- ];
1100
- };
1101
- /* 0012 || 2210 */
1102
- var p22 = function (cell) {
1103
- return [
1104
- [cell.topright, 1],
1105
- [cell.bottomleft, 0],
1106
- [0, 0],
1107
- [0, cell.leftbottom],
1108
- [cell.topleft, 1],
1109
- ];
1110
- };
1111
- /* 2001 || 0221 */
1112
- var p23 = function (cell) {
1113
- return [
1114
- [cell.bottomright, 0],
1115
- [cell.bottomleft, 0],
1116
- [0, cell.lefttop],
1117
- [0, 1],
1118
- [cell.topleft, 1],
1119
- ];
1120
- };
1121
- /* 1002 || 1220 */
1122
- var p24 = function (cell) {
1123
- return [
1124
- [1, 1],
1125
- [1, cell.righttop],
1126
- [0, cell.leftbottom],
1127
- [0, cell.lefttop],
1128
- [cell.topright, 1],
1129
- ];
1130
- };
1131
- /* 2100 || 0122 */
1132
- var p25 = function (cell) {
1133
- return [
1134
- [1, cell.rightbottom],
1135
- [1, 0],
1136
- [cell.bottomright, 0],
1137
- [cell.topleft, 1],
1138
- [cell.topright, 1],
1139
- ];
1140
- };
1141
- /* 0210 || 2012 */
1142
- var p26 = function (cell) {
1143
- return [
1144
- [1, cell.righttop],
1145
- [1, cell.rightbottom],
1146
- [cell.bottomleft, 0],
1147
- [0, 0],
1148
- [0, cell.leftbottom],
1149
- ];
1150
- };
1151
- /* 0021 || 2201 */
1152
- /*hexagon cases */
1153
- var p27 = function (cell) {
1154
- return [
1155
- [1, cell.rightbottom],
1156
- [1, 0],
1157
- [0, 0],
1158
- [0, cell.leftbottom],
1159
- [cell.topleft, 1],
1160
- [cell.topright, 1],
1161
- ];
1162
- };
1163
- /* 0211 || 2011 */
1164
- var p28 = function (cell) {
1165
- return [
1166
- [1, 1],
1167
- [1, 0],
1168
- [cell.bottomright, 0],
1169
- [0, cell.leftbottom],
1170
- [0, cell.lefttop],
1171
- [cell.topright, 1],
1172
- ];
1173
- };
1174
- /* 2110 || 0112 */
1175
- var p29 = function (cell) {
1176
- return [
1177
- [1, 1],
1178
- [1, cell.righttop],
1179
- [cell.bottomright, 0],
1180
- [cell.bottomleft, 0],
1181
- [0, cell.lefttop],
1182
- [0, 1],
1183
- ];
1184
- };
1185
- /* 1102 || 1120 */
1186
- var p30 = function (cell) {
1187
- return [
1188
- [1, cell.righttop],
1189
- [1, cell.rightbottom],
1190
- [cell.bottomleft, 0],
1191
- [0, 0],
1192
- [0, 1],
1193
- [cell.topleft, 1],
1194
- ];
1195
- };
1196
- /* 1021 || 1201 */
1197
- var p31 = function (cell) {
1198
- return [
1199
- [1, 1],
1200
- [1, cell.righttop],
1201
- [cell.bottomleft, 0],
1202
- [0, 0],
1203
- [0, cell.leftbottom],
1204
- [cell.topright, 1],
1205
- ];
1206
- };
1207
- /* 2101 || 0121 */
1208
- var p32 = function (cell) {
1209
- return [
1210
- [1, cell.rightbottom],
1211
- [1, 0],
1212
- [cell.bottomright, 0],
1213
- [0, cell.lefttop],
1214
- [0, 1],
1215
- [cell.topleft, 1],
1216
- ];
1217
- };
1218
- /* 1012 || 1210 */
1219
- /* 8-sided cases */
1220
- var p33 = function (cell) {
1221
- return [
1222
- [1, cell.righttop],
1223
- [1, cell.rightbottom],
1224
- [cell.bottomright, 0],
1225
- [cell.bottomleft, 0],
1226
- [0, cell.leftbottom],
1227
- [0, cell.lefttop],
1228
- [cell.topleft, 1],
1229
- [cell.topright, 1],
1230
- ];
1231
- };
1232
- /* flipped == 1 state for 0202 and 2020 */
1233
- /* 6-sided cases */
1234
- var p34 = function (cell) {
1235
- return [
1236
- [1, 1],
1237
- [1, cell.righttop],
1238
- [cell.bottomleft, 0],
1239
- [0, 0],
1240
- [0, cell.leftbottom],
1241
- [cell.topright, 1],
1242
- ];
1243
- };
1244
- /* 0101 with flipped == 1 || 2121 with flipped == 1 */
1245
- var p35 = function (cell) {
1246
- return [
1247
- [1, cell.rightbottom],
1248
- [1, 0],
1249
- [cell.bottomright, 0],
1250
- [0, cell.lefttop],
1251
- [0, 1],
1252
- [cell.topleft, 1],
1253
- ];
1254
- };
1255
- /* 1010 with flipped == 1 || 1212 with flipped == 1 */
1256
- /* 7-sided cases */
1257
- var p36 = function (cell) {
1258
- return [
1259
- [1, 1],
1260
- [1, cell.righttop],
1261
- [cell.bottomright, 0],
1262
- [cell.bottomleft, 0],
1263
- [0, cell.leftbottom],
1264
- [0, cell.lefttop],
1265
- [cell.topright, 1],
1266
- ];
1267
- };
1268
- /* 2120 with flipped == 1 || 0102 with flipped == 1 */
1269
- var p37 = function (cell) {
1270
- return [
1271
- [1, cell.righttop],
1272
- [1, cell.rightbottom],
1273
- [cell.bottomleft, 0],
1274
- [0, 0],
1275
- [0, cell.leftbottom],
1276
- [cell.topleft, 1],
1277
- [cell.topright, 1],
1278
- ];
1279
- };
1280
- /* 2021 with flipped == 1 || 0201 with flipped == 1 */
1281
- var p38 = function (cell) {
1282
- return [
1283
- [1, cell.righttop],
1284
- [1, cell.rightbottom],
1285
- [cell.bottomright, 0],
1286
- [cell.bottomleft, 0],
1287
- [0, cell.lefttop],
1288
- [0, 1],
1289
- [cell.topleft, 1],
1290
- ];
1291
- };
1292
- /* 1202 with flipped == 1 || 1020 with flipped == 1 */
1293
- var p39 = function (cell) {
1294
- return [
1295
- [1, cell.rightbottom],
1296
- [1, 0],
1297
- [cell.bottomright, 0],
1298
- [0, cell.leftbottom],
1299
- [0, cell.lefttop],
1300
- [cell.topleft, 1],
1301
- [cell.topright, 1],
1302
- ];
1303
- };
1304
- /* 0212 with flipped == 1 || 2010 with flipped == 1 */
1305
-
1306
- /*
1307
- The lookup tables for edge number given the polygon
1308
- is entered at a specific location
1309
- */
1310
-
1311
- var isoBandEdgeRT = [];
1312
- var isoBandEdgeRB = [];
1313
- var isoBandEdgeBR = [];
1314
- var isoBandEdgeBL = [];
1315
- var isoBandEdgeLB = [];
1316
- var isoBandEdgeLT = [];
1317
- var isoBandEdgeTL = [];
1318
- var isoBandEdgeTR = [];
1319
-
1320
- /* triangle cases */
1321
- isoBandEdgeBL[1] = isoBandEdgeLB[1] = 18;
1322
- isoBandEdgeBL[169] = isoBandEdgeLB[169] = 18;
1323
- isoBandEdgeBR[4] = isoBandEdgeRB[4] = 12;
1324
- isoBandEdgeBR[166] = isoBandEdgeRB[166] = 12;
1325
- isoBandEdgeRT[16] = isoBandEdgeTR[16] = 4;
1326
- isoBandEdgeRT[154] = isoBandEdgeTR[154] = 4;
1327
- isoBandEdgeLT[64] = isoBandEdgeTL[64] = 22;
1328
- isoBandEdgeLT[106] = isoBandEdgeTL[106] = 22;
1329
-
1330
- /* trapezoid cases */
1331
- isoBandEdgeBR[2] = isoBandEdgeLT[2] = 17;
1332
- isoBandEdgeBL[2] = isoBandEdgeLB[2] = 18;
1333
- isoBandEdgeBR[168] = isoBandEdgeLT[168] = 17;
1334
- isoBandEdgeBL[168] = isoBandEdgeLB[168] = 18;
1335
- isoBandEdgeRT[8] = isoBandEdgeBL[8] = 9;
1336
- isoBandEdgeRB[8] = isoBandEdgeBR[8] = 12;
1337
- isoBandEdgeRT[162] = isoBandEdgeBL[162] = 9;
1338
- isoBandEdgeRB[162] = isoBandEdgeBR[162] = 12;
1339
- isoBandEdgeRT[32] = isoBandEdgeTR[32] = 4;
1340
- isoBandEdgeRB[32] = isoBandEdgeTL[32] = 1;
1341
- isoBandEdgeRT[138] = isoBandEdgeTR[138] = 4;
1342
- isoBandEdgeRB[138] = isoBandEdgeTL[138] = 1;
1343
- isoBandEdgeLB[128] = isoBandEdgeTR[128] = 21;
1344
- isoBandEdgeLT[128] = isoBandEdgeTL[128] = 22;
1345
- isoBandEdgeLB[42] = isoBandEdgeTR[42] = 21;
1346
- isoBandEdgeLT[42] = isoBandEdgeTL[42] = 22;
1347
-
1348
- /* rectangle cases */
1349
- isoBandEdgeRB[5] = isoBandEdgeLB[5] = 14;
1350
- isoBandEdgeRB[165] = isoBandEdgeLB[165] = 14;
1351
- isoBandEdgeBR[20] = isoBandEdgeTR[20] = 6;
1352
- isoBandEdgeBR[150] = isoBandEdgeTR[150] = 6;
1353
- isoBandEdgeRT[80] = isoBandEdgeLT[80] = 11;
1354
- isoBandEdgeRT[90] = isoBandEdgeLT[90] = 11;
1355
- isoBandEdgeBL[65] = isoBandEdgeTL[65] = 3;
1356
- isoBandEdgeBL[105] = isoBandEdgeTL[105] = 3;
1357
- isoBandEdgeRT[160] = isoBandEdgeLT[160] = 11;
1358
- isoBandEdgeRB[160] = isoBandEdgeLB[160] = 14;
1359
- isoBandEdgeRT[10] = isoBandEdgeLT[10] = 11;
1360
- isoBandEdgeRB[10] = isoBandEdgeLB[10] = 14;
1361
- isoBandEdgeBR[130] = isoBandEdgeTR[130] = 6;
1362
- isoBandEdgeBL[130] = isoBandEdgeTL[130] = 3;
1363
- isoBandEdgeBR[40] = isoBandEdgeTR[40] = 6;
1364
- isoBandEdgeBL[40] = isoBandEdgeTL[40] = 3;
1365
-
1366
- /* pentagon cases */
1367
- isoBandEdgeRB[101] = isoBandEdgeTL[101] = 1;
1368
- isoBandEdgeRB[69] = isoBandEdgeTL[69] = 1;
1369
- isoBandEdgeLB[149] = isoBandEdgeTR[149] = 21;
1370
- isoBandEdgeLB[21] = isoBandEdgeTR[21] = 21;
1371
- isoBandEdgeBR[86] = isoBandEdgeLT[86] = 17;
1372
- isoBandEdgeBR[84] = isoBandEdgeLT[84] = 17;
1373
- isoBandEdgeRT[89] = isoBandEdgeBL[89] = 9;
1374
- isoBandEdgeRT[81] = isoBandEdgeBL[81] = 9;
1375
- isoBandEdgeRT[96] = isoBandEdgeTL[96] = 0;
1376
- isoBandEdgeRB[96] = isoBandEdgeLT[96] = 15;
1377
- isoBandEdgeRT[74] = isoBandEdgeTL[74] = 0;
1378
- isoBandEdgeRB[74] = isoBandEdgeLT[74] = 15;
1379
- isoBandEdgeRT[24] = isoBandEdgeBR[24] = 8;
1380
- isoBandEdgeBL[24] = isoBandEdgeTR[24] = 7;
1381
- isoBandEdgeRT[146] = isoBandEdgeBR[146] = 8;
1382
- isoBandEdgeBL[146] = isoBandEdgeTR[146] = 7;
1383
- isoBandEdgeRB[6] = isoBandEdgeLT[6] = 15;
1384
- isoBandEdgeBR[6] = isoBandEdgeLB[6] = 16;
1385
- isoBandEdgeRB[164] = isoBandEdgeLT[164] = 15;
1386
- isoBandEdgeBR[164] = isoBandEdgeLB[164] = 16;
1387
- isoBandEdgeBL[129] = isoBandEdgeTR[129] = 7;
1388
- isoBandEdgeLB[129] = isoBandEdgeTL[129] = 20;
1389
- isoBandEdgeBL[41] = isoBandEdgeTR[41] = 7;
1390
- isoBandEdgeLB[41] = isoBandEdgeTL[41] = 20;
1391
- isoBandEdgeBR[66] = isoBandEdgeTL[66] = 2;
1392
- isoBandEdgeBL[66] = isoBandEdgeLT[66] = 19;
1393
- isoBandEdgeBR[104] = isoBandEdgeTL[104] = 2;
1394
- isoBandEdgeBL[104] = isoBandEdgeLT[104] = 19;
1395
- isoBandEdgeRT[144] = isoBandEdgeLB[144] = 10;
1396
- isoBandEdgeLT[144] = isoBandEdgeTR[144] = 23;
1397
- isoBandEdgeRT[26] = isoBandEdgeLB[26] = 10;
1398
- isoBandEdgeLT[26] = isoBandEdgeTR[26] = 23;
1399
- isoBandEdgeRB[36] = isoBandEdgeTR[36] = 5;
1400
- isoBandEdgeBR[36] = isoBandEdgeTL[36] = 2;
1401
- isoBandEdgeRB[134] = isoBandEdgeTR[134] = 5;
1402
- isoBandEdgeBR[134] = isoBandEdgeTL[134] = 2;
1403
- isoBandEdgeRT[9] = isoBandEdgeLB[9] = 10;
1404
- isoBandEdgeRB[9] = isoBandEdgeBL[9] = 13;
1405
- isoBandEdgeRT[161] = isoBandEdgeLB[161] = 10;
1406
- isoBandEdgeRB[161] = isoBandEdgeBL[161] = 13;
1407
-
1408
- /* hexagon cases */
1409
- isoBandEdgeRB[37] = isoBandEdgeTR[37] = 5;
1410
- isoBandEdgeLB[37] = isoBandEdgeTL[37] = 20;
1411
- isoBandEdgeRB[133] = isoBandEdgeTR[133] = 5;
1412
- isoBandEdgeLB[133] = isoBandEdgeTL[133] = 20;
1413
- isoBandEdgeBR[148] = isoBandEdgeLB[148] = 16;
1414
- isoBandEdgeLT[148] = isoBandEdgeTR[148] = 23;
1415
- isoBandEdgeBR[22] = isoBandEdgeLB[22] = 16;
1416
- isoBandEdgeLT[22] = isoBandEdgeTR[22] = 23;
1417
- isoBandEdgeRT[82] = isoBandEdgeBR[82] = 8;
1418
- isoBandEdgeBL[82] = isoBandEdgeLT[82] = 19;
1419
- isoBandEdgeRT[88] = isoBandEdgeBR[88] = 8;
1420
- isoBandEdgeBL[88] = isoBandEdgeLT[88] = 19;
1421
- isoBandEdgeRT[73] = isoBandEdgeTL[73] = 0;
1422
- isoBandEdgeRB[73] = isoBandEdgeBL[73] = 13;
1423
- isoBandEdgeRT[97] = isoBandEdgeTL[97] = 0;
1424
- isoBandEdgeRB[97] = isoBandEdgeBL[97] = 13;
1425
- isoBandEdgeRT[145] = isoBandEdgeBL[145] = 9;
1426
- isoBandEdgeLB[145] = isoBandEdgeTR[145] = 21;
1427
- isoBandEdgeRT[25] = isoBandEdgeBL[25] = 9;
1428
- isoBandEdgeLB[25] = isoBandEdgeTR[25] = 21;
1429
- isoBandEdgeRB[70] = isoBandEdgeTL[70] = 1;
1430
- isoBandEdgeBR[70] = isoBandEdgeLT[70] = 17;
1431
- isoBandEdgeRB[100] = isoBandEdgeTL[100] = 1;
1432
- isoBandEdgeBR[100] = isoBandEdgeLT[100] = 17;
1433
-
1434
- /* 8-sided cases */
1435
- isoBandEdgeRT[34] = isoBandEdgeBL[34] = 9;
1436
- isoBandEdgeRB[34] = isoBandEdgeBR[34] = 12;
1437
- isoBandEdgeLB[34] = isoBandEdgeTR[34] = 21;
1438
- isoBandEdgeLT[34] = isoBandEdgeTL[34] = 22;
1439
- isoBandEdgeRT[136] = isoBandEdgeTR[136] = 4;
1440
- isoBandEdgeRB[136] = isoBandEdgeTL[136] = 1;
1441
- isoBandEdgeBR[136] = isoBandEdgeLT[136] = 17;
1442
- isoBandEdgeBL[136] = isoBandEdgeLB[136] = 18;
1443
- isoBandEdgeRT[35] = isoBandEdgeTR[35] = 4;
1444
- isoBandEdgeRB[35] = isoBandEdgeBR[35] = 12;
1445
- isoBandEdgeBL[35] = isoBandEdgeLB[35] = 18;
1446
- isoBandEdgeLT[35] = isoBandEdgeTL[35] = 22;
1447
-
1448
- /* 6-sided cases */
1449
- isoBandEdgeRT[153] = isoBandEdgeTR[153] = 4;
1450
- isoBandEdgeBL[153] = isoBandEdgeLB[153] = 18;
1451
- isoBandEdgeRB[102] = isoBandEdgeBR[102] = 12;
1452
- isoBandEdgeLT[102] = isoBandEdgeTL[102] = 22;
1453
- isoBandEdgeRT[155] = isoBandEdgeBL[155] = 9;
1454
- isoBandEdgeLB[155] = isoBandEdgeTR[155] = 23;
1455
- isoBandEdgeRB[103] = isoBandEdgeTL[103] = 1;
1456
- isoBandEdgeBR[103] = isoBandEdgeLT[103] = 17;
1457
-
1458
- /* 7-sided cases */
1459
- isoBandEdgeRT[152] = isoBandEdgeTR[152] = 4;
1460
- isoBandEdgeBR[152] = isoBandEdgeLT[152] = 17;
1461
- isoBandEdgeBL[152] = isoBandEdgeLB[152] = 18;
1462
- isoBandEdgeRT[156] = isoBandEdgeBR[156] = 8;
1463
- isoBandEdgeBL[156] = isoBandEdgeLB[156] = 18;
1464
- isoBandEdgeLT[156] = isoBandEdgeTR[156] = 23;
1465
- isoBandEdgeRT[137] = isoBandEdgeTR[137] = 4;
1466
- isoBandEdgeRB[137] = isoBandEdgeTL[137] = 1;
1467
- isoBandEdgeBL[137] = isoBandEdgeLB[137] = 18;
1468
- isoBandEdgeRT[139] = isoBandEdgeTR[139] = 4;
1469
- isoBandEdgeRB[139] = isoBandEdgeBL[139] = 13;
1470
- isoBandEdgeLB[139] = isoBandEdgeTL[139] = 20;
1471
- isoBandEdgeRT[98] = isoBandEdgeBL[98] = 9;
1472
- isoBandEdgeRB[98] = isoBandEdgeBR[98] = 12;
1473
- isoBandEdgeLT[98] = isoBandEdgeTL[98] = 22;
1474
- isoBandEdgeRT[99] = isoBandEdgeTL[99] = 0;
1475
- isoBandEdgeRB[99] = isoBandEdgeBR[99] = 12;
1476
- isoBandEdgeBL[99] = isoBandEdgeLT[99] = 19;
1477
- isoBandEdgeRB[38] = isoBandEdgeBR[38] = 12;
1478
- isoBandEdgeLB[38] = isoBandEdgeTR[38] = 21;
1479
- isoBandEdgeLT[38] = isoBandEdgeTL[38] = 22;
1480
- isoBandEdgeRB[39] = isoBandEdgeTR[39] = 5;
1481
- isoBandEdgeBR[39] = isoBandEdgeLB[39] = 16;
1482
- isoBandEdgeLT[39] = isoBandEdgeTL[39] = 22;
1483
-
1484
- /*
1485
- The lookup tables for all different polygons that
1486
- may appear within a grid cell
1487
- */
1488
-
1489
- var polygon_table = [];
1490
-
1491
- /* triangle cases */
1492
- polygon_table[1] = polygon_table[169] = p00; /* 2221 || 0001 */
1493
- polygon_table[4] = polygon_table[166] = p01; /* 2212 || 0010 */
1494
- polygon_table[16] = polygon_table[154] = p02; /* 2122 || 0100 */
1495
- polygon_table[64] = polygon_table[106] = p03; /* 1222 || 1000 */
1496
-
1497
- /* trapezoid cases */
1498
- polygon_table[168] = polygon_table[2] = p04; /* 2220 || 0002 */
1499
- polygon_table[162] = polygon_table[8] = p05; /* 2202 || 0020 */
1500
- polygon_table[138] = polygon_table[32] = p06; /* 2022 || 0200 */
1501
- polygon_table[42] = polygon_table[128] = p07; /* 0222 || 2000 */
1502
-
1503
- /* rectangle cases */
1504
- polygon_table[5] = polygon_table[165] = p08; /* 0011 || 2211 */
1505
- polygon_table[20] = polygon_table[150] = p09; /* 0110 || 2112 */
1506
- polygon_table[80] = polygon_table[90] = p10; /* 1100 || 1122 */
1507
- polygon_table[65] = polygon_table[105] = p11; /* 1001 || 1221 */
1508
- polygon_table[160] = polygon_table[10] = p12; /* 2200 || 0022 */
1509
- polygon_table[130] = polygon_table[40] = p13; /* 2002 || 0220 */
1510
-
1511
- /* square case */
1512
- polygon_table[85] = p14; /* 1111 */
1513
-
1514
- /* pentagon cases */
1515
- polygon_table[101] = polygon_table[69] = p15; /* 1211 || 1011 */
1516
- polygon_table[149] = polygon_table[21] = p16; /* 2111 || 0111 */
1517
- polygon_table[86] = polygon_table[84] = p17; /* 1112 || 1110 */
1518
- polygon_table[89] = polygon_table[81] = p18; /* 1121 || 1101 */
1519
- polygon_table[96] = polygon_table[74] = p19; /* 1200 || 1022 */
1520
- polygon_table[24] = polygon_table[146] = p20; /* 0120 || 2102 */
1521
- polygon_table[6] = polygon_table[164] = p21; /* 0012 || 2210 */
1522
- polygon_table[129] = polygon_table[41] = p22; /* 2001 || 0221 */
1523
- polygon_table[66] = polygon_table[104] = p23; /* 1002 || 1220 */
1524
- polygon_table[144] = polygon_table[26] = p24; /* 2100 || 0122 */
1525
- polygon_table[36] = polygon_table[134] = p25; /* 0210 || 2012 */
1526
- polygon_table[9] = polygon_table[161] = p26; /* 0021 || 2201 */
1527
-
1528
- /* hexagon cases */
1529
- polygon_table[37] = polygon_table[133] = p27; /* 0211 || 2011 */
1530
- polygon_table[148] = polygon_table[22] = p28; /* 2110 || 0112 */
1531
- polygon_table[82] = polygon_table[88] = p29; /* 1102 || 1120 */
1532
- polygon_table[73] = polygon_table[97] = p30; /* 1021 || 1201 */
1533
- polygon_table[145] = polygon_table[25] = p31; /* 2101 || 0121 */
1534
- polygon_table[70] = polygon_table[100] = p32; /* 1012 || 1210 */
1535
-
1536
- /* 8-sided cases */
1537
- polygon_table[34] = function (c) {
1538
- return [p07(c), p05(c)];
1539
- }; /* 0202 || 2020 with flipped == 0 */
1540
- polygon_table[35] = p33; /* flipped == 1 state for 0202 and 2020 */
1541
- polygon_table[136] = function (c) {
1542
- return [p06(c), p04(c)];
1543
- }; /* 2020 || 0202 with flipped == 0 */
1544
-
1545
- /* 6-sided cases */
1546
- polygon_table[153] = function (c) {
1547
- return [p02(c), p00(c)];
1548
- }; /* 0101 with flipped == 0 || 2121 with flipped == 2 */
1549
- polygon_table[102] = function (c) {
1550
- return [p01(c), p03(c)];
1551
- }; /* 1010 with flipped == 0 || 1212 with flipped == 2 */
1552
- polygon_table[155] = p34; /* 0101 with flipped == 1 || 2121 with flipped == 1 */
1553
- polygon_table[103] = p35; /* 1010 with flipped == 1 || 1212 with flipped == 1 */
1554
-
1555
- /* 7-sided cases */
1556
- polygon_table[152] = function (c) {
1557
- return [p02(c), p04(c)];
1558
- }; /* 2120 with flipped == 2 || 0102 with flipped == 0 */
1559
- polygon_table[156] = p36; /* 2120 with flipped == 1 || 0102 with flipped == 1 */
1560
- polygon_table[137] = function (c) {
1561
- return [p06(c), p00(c)];
1562
- }; /* 2021 with flipped == 2 || 0201 with flipped == 0 */
1563
- polygon_table[139] = p37; /* 2021 with flipped == 1 || 0201 with flipped == 1 */
1564
- polygon_table[98] = function (c) {
1565
- return [p05(c), p03(c)];
1566
- }; /* 1202 with flipped == 2 || 1020 with flipped == 0 */
1567
- polygon_table[99] = p38; /* 1202 with flipped == 1 || 1020 with flipped == 1 */
1568
- polygon_table[38] = function (c) {
1569
- return [p01(c), p07(c)];
1570
- }; /* 0212 with flipped == 2 || 2010 with flipped == 0 */
1571
- polygon_table[39] = p39; /* 0212 with flipped == 1 || 2010 with flipped == 1 */
1572
-
1573
- /*
1574
- ####################################
1575
- Some small helper functions
1576
- ####################################
1577
- */
1578
-
1579
- /* assume that x1 == 1 && x0 == 0 */
1580
- function interpolateX(y, y0, y1) {
1581
- return (y - y0) / (y1 - y0);
1582
- }
1583
-
1584
- function isArray(myArray) {
1585
- return myArray.constructor.toString().indexOf("Array") > -1;
1586
- }
1587
-
1588
- /*
1589
- ####################################
1590
- Below is the actual Marching Squares implementation
1591
- ####################################
1592
- */
1593
-
1594
- function computeBandGrid(data, minV, bandwidth) {
1595
- var rows = data.length - 1;
1596
- var cols = data[0].length - 1;
1597
- var BandGrid = { rows: rows, cols: cols, cells: [] };
1598
-
1599
- var maxV = minV + Math.abs(bandwidth);
1600
-
1601
- for (var j = 0; j < rows; ++j) {
1602
- BandGrid.cells[j] = [];
1603
- for (var i = 0; i < cols; ++i) {
1604
- /* compose the 4-trit corner representation */
1605
- var cval = 0;
1606
-
1607
- var tl = data[j + 1][i];
1608
- var tr = data[j + 1][i + 1];
1609
- var br = data[j][i + 1];
1610
- var bl = data[j][i];
1611
-
1612
- if (isNaN(tl) || isNaN(tr) || isNaN(br) || isNaN(bl)) {
1613
- continue;
1614
- }
1615
-
1616
- cval |= tl < minV ? 0 : tl > maxV ? 128 : 64;
1617
- cval |= tr < minV ? 0 : tr > maxV ? 32 : 16;
1618
- cval |= br < minV ? 0 : br > maxV ? 8 : 4;
1619
- cval |= bl < minV ? 0 : bl > maxV ? 2 : 1;
1620
-
1621
- var cval_real = +cval;
1622
-
1623
- /* resolve ambiguity via averaging */
1624
- var flipped = 0;
1625
- if (
1626
- cval === 17 /* 0101 */ ||
1627
- cval === 18 /* 0102 */ ||
1628
- cval === 33 /* 0201 */ ||
1629
- cval === 34 /* 0202 */ ||
1630
- cval === 38 /* 0212 */ ||
1631
- cval === 68 /* 1010 */ ||
1632
- cval === 72 /* 1020 */ ||
1633
- cval === 98 /* 1202 */ ||
1634
- cval === 102 /* 1212 */ ||
1635
- cval === 132 /* 2010 */ ||
1636
- cval === 136 /* 2020 */ ||
1637
- cval === 137 /* 2021 */ ||
1638
- cval === 152 /* 2120 */ ||
1639
- cval === 153 /* 2121 */
1640
- ) {
1641
- var average = (tl + tr + br + bl) / 4;
1642
- /* set flipped state */
1643
- flipped = average > maxV ? 2 : average < minV ? 0 : 1;
1644
-
1645
- /* adjust cval for flipped cases */
1646
-
1647
- /* 8-sided cases */
1648
- if (cval === 34) {
1649
- if (flipped === 1) {
1650
- cval = 35;
1651
- } else if (flipped === 0) {
1652
- cval = 136;
1653
- }
1654
- } else if (cval === 136) {
1655
- if (flipped === 1) {
1656
- cval = 35;
1657
- flipped = 4;
1658
- } else if (flipped === 0) {
1659
- cval = 34;
1660
- }
1661
- } else if (cval === 17) {
1662
- /* 6-sided polygon cases */
1663
- if (flipped === 1) {
1664
- cval = 155;
1665
- flipped = 4;
1666
- } else if (flipped === 0) {
1667
- cval = 153;
1668
- }
1669
- } else if (cval === 68) {
1670
- if (flipped === 1) {
1671
- cval = 103;
1672
- flipped = 4;
1673
- } else if (flipped === 0) {
1674
- cval = 102;
1675
- }
1676
- } else if (cval === 153) {
1677
- if (flipped === 1) cval = 155;
1678
- } else if (cval === 102) {
1679
- if (flipped === 1) cval = 103;
1680
- } else if (cval === 152) {
1681
- /* 7-sided polygon cases */
1682
- if (flipped < 2) {
1683
- cval = 156;
1684
- flipped = 1;
1685
- }
1686
- } else if (cval === 137) {
1687
- if (flipped < 2) {
1688
- cval = 139;
1689
- flipped = 1;
1690
- }
1691
- } else if (cval === 98) {
1692
- if (flipped < 2) {
1693
- cval = 99;
1694
- flipped = 1;
1695
- }
1696
- } else if (cval === 38) {
1697
- if (flipped < 2) {
1698
- cval = 39;
1699
- flipped = 1;
1700
- }
1701
- } else if (cval === 18) {
1702
- if (flipped > 0) {
1703
- cval = 156;
1704
- flipped = 4;
1705
- } else {
1706
- cval = 152;
1707
- }
1708
- } else if (cval === 33) {
1709
- if (flipped > 0) {
1710
- cval = 139;
1711
- flipped = 4;
1712
- } else {
1713
- cval = 137;
1714
- }
1715
- } else if (cval === 72) {
1716
- if (flipped > 0) {
1717
- cval = 99;
1718
- flipped = 4;
1719
- } else {
1720
- cval = 98;
1721
- }
1722
- } else if (cval === 132) {
1723
- if (flipped > 0) {
1724
- cval = 39;
1725
- flipped = 4;
1726
- } else {
1727
- cval = 38;
1728
- }
1729
- }
1730
- }
1731
-
1732
- /* add cell to BandGrid if it contains at least one polygon-side */
1733
- if (cval != 0 && cval != 170) {
1734
- var topleft,
1735
- topright,
1736
- bottomleft,
1737
- bottomright,
1738
- righttop,
1739
- rightbottom,
1740
- lefttop,
1741
- leftbottom;
1742
-
1743
- topleft = topright = bottomleft = bottomright = righttop = rightbottom = lefttop = leftbottom = 0.5;
1744
-
1745
- var edges = [];
1746
-
1747
- /* do interpolation here */
1748
- /* 1st Triangles */
1749
- if (cval === 1) {
1750
- /* 0001 */
1751
- bottomleft = 1 - interpolateX(minV, br, bl);
1752
- leftbottom = 1 - interpolateX(minV, tl, bl);
1753
- edges.push(isoBandEdgeBL[cval]);
1754
- } else if (cval === 169) {
1755
- /* 2221 */
1756
- bottomleft = interpolateX(maxV, bl, br);
1757
- leftbottom = interpolateX(maxV, bl, tl);
1758
- edges.push(isoBandEdgeBL[cval]);
1759
- } else if (cval === 4) {
1760
- /* 0010 */
1761
- rightbottom = 1 - interpolateX(minV, tr, br);
1762
- bottomright = interpolateX(minV, bl, br);
1763
- edges.push(isoBandEdgeRB[cval]);
1764
- } else if (cval === 166) {
1765
- /* 2212 */
1766
- rightbottom = interpolateX(maxV, br, tr);
1767
- bottomright = 1 - interpolateX(maxV, br, bl);
1768
- edges.push(isoBandEdgeRB[cval]);
1769
- } else if (cval === 16) {
1770
- /* 0100 */
1771
- righttop = interpolateX(minV, br, tr);
1772
- topright = interpolateX(minV, tl, tr);
1773
- edges.push(isoBandEdgeRT[cval]);
1774
- } else if (cval === 154) {
1775
- /* 2122 */
1776
- righttop = 1 - interpolateX(maxV, tr, br);
1777
- topright = 1 - interpolateX(maxV, tr, tl);
1778
- edges.push(isoBandEdgeRT[cval]);
1779
- } else if (cval === 64) {
1780
- /* 1000 */
1781
- lefttop = interpolateX(minV, bl, tl);
1782
- topleft = 1 - interpolateX(minV, tr, tl);
1783
- edges.push(isoBandEdgeLT[cval]);
1784
- } else if (cval === 106) {
1785
- /* 1222 */
1786
- lefttop = 1 - interpolateX(maxV, tl, bl);
1787
- topleft = interpolateX(maxV, tl, tr);
1788
- edges.push(isoBandEdgeLT[cval]);
1789
- } else if (cval === 168) {
1790
- /* 2nd Trapezoids */
1791
- /* 2220 */
1792
- bottomright = interpolateX(maxV, bl, br);
1793
- bottomleft = interpolateX(minV, bl, br);
1794
- leftbottom = interpolateX(minV, bl, tl);
1795
- lefttop = interpolateX(maxV, bl, tl);
1796
- edges.push(isoBandEdgeBR[cval]);
1797
- edges.push(isoBandEdgeBL[cval]);
1798
- } else if (cval === 2) {
1799
- /* 0002 */
1800
- bottomright = 1 - interpolateX(minV, br, bl);
1801
- bottomleft = 1 - interpolateX(maxV, br, bl);
1802
- leftbottom = 1 - interpolateX(maxV, tl, bl);
1803
- lefttop = 1 - interpolateX(minV, tl, bl);
1804
- edges.push(isoBandEdgeBR[cval]);
1805
- edges.push(isoBandEdgeBL[cval]);
1806
- } else if (cval === 162) {
1807
- /* 2202 */
1808
- righttop = interpolateX(maxV, br, tr);
1809
- rightbottom = interpolateX(minV, br, tr);
1810
- bottomright = 1 - interpolateX(minV, br, bl);
1811
- bottomleft = 1 - interpolateX(maxV, br, bl);
1812
- edges.push(isoBandEdgeBR[cval]);
1813
- edges.push(isoBandEdgeBL[cval]);
1814
- } else if (cval === 8) {
1815
- /* 0020 */
1816
- righttop = 1 - interpolateX(minV, tr, br);
1817
- rightbottom = 1 - interpolateX(maxV, tr, br);
1818
- bottomright = interpolateX(maxV, bl, br);
1819
- bottomleft = interpolateX(minV, bl, br);
1820
- edges.push(isoBandEdgeRT[cval]);
1821
- edges.push(isoBandEdgeRB[cval]);
1822
- } else if (cval === 138) {
1823
- /* 2022 */
1824
- righttop = 1 - interpolateX(minV, tr, br);
1825
- rightbottom = 1 - interpolateX(maxV, tr, br);
1826
- topleft = 1 - interpolateX(maxV, tr, tl);
1827
- topright = 1 - interpolateX(minV, tr, tl);
1828
- edges.push(isoBandEdgeRT[cval]);
1829
- edges.push(isoBandEdgeRB[cval]);
1830
- } else if (cval === 32) {
1831
- /* 0200 */
1832
- righttop = interpolateX(maxV, br, tr);
1833
- rightbottom = interpolateX(minV, br, tr);
1834
- topleft = interpolateX(minV, tl, tr);
1835
- topright = interpolateX(maxV, tl, tr);
1836
- edges.push(isoBandEdgeRT[cval]);
1837
- edges.push(isoBandEdgeRB[cval]);
1838
- } else if (cval === 42) {
1839
- /* 0222 */
1840
- leftbottom = 1 - interpolateX(maxV, tl, bl);
1841
- lefttop = 1 - interpolateX(minV, tl, bl);
1842
- topleft = interpolateX(minV, tl, tr);
1843
- topright = interpolateX(maxV, tl, tr);
1844
- edges.push(isoBandEdgeLB[cval]);
1845
- edges.push(isoBandEdgeLT[cval]);
1846
- } else if (cval === 128) {
1847
- /* 2000 */
1848
- leftbottom = interpolateX(minV, bl, tl);
1849
- lefttop = interpolateX(maxV, bl, tl);
1850
- topleft = 1 - interpolateX(maxV, tr, tl);
1851
- topright = 1 - interpolateX(minV, tr, tl);
1852
- edges.push(isoBandEdgeLB[cval]);
1853
- edges.push(isoBandEdgeLT[cval]);
1854
- }
1855
-
1856
- /* 3rd rectangle cases */
1857
- if (cval === 5) {
1858
- /* 0011 */
1859
- rightbottom = 1 - interpolateX(minV, tr, br);
1860
- leftbottom = 1 - interpolateX(minV, tl, bl);
1861
- edges.push(isoBandEdgeRB[cval]);
1862
- } else if (cval === 165) {
1863
- /* 2211 */
1864
- rightbottom = interpolateX(maxV, br, tr);
1865
- leftbottom = interpolateX(maxV, bl, tl);
1866
- edges.push(isoBandEdgeRB[cval]);
1867
- } else if (cval === 20) {
1868
- /* 0110 */
1869
- bottomright = interpolateX(minV, bl, br);
1870
- topright = interpolateX(minV, tl, tr);
1871
- edges.push(isoBandEdgeBR[cval]);
1872
- } else if (cval === 150) {
1873
- /* 2112 */
1874
- bottomright = 1 - interpolateX(maxV, br, bl);
1875
- topright = 1 - interpolateX(maxV, tr, tl);
1876
- edges.push(isoBandEdgeBR[cval]);
1877
- } else if (cval === 80) {
1878
- /* 1100 */
1879
- righttop = interpolateX(minV, br, tr);
1880
- lefttop = interpolateX(minV, bl, tl);
1881
- edges.push(isoBandEdgeRT[cval]);
1882
- } else if (cval === 90) {
1883
- /* 1122 */
1884
- righttop = 1 - interpolateX(maxV, tr, br);
1885
- lefttop = 1 - interpolateX(maxV, tl, bl);
1886
- edges.push(isoBandEdgeRT[cval]);
1887
- } else if (cval === 65) {
1888
- /* 1001 */
1889
- bottomleft = 1 - interpolateX(minV, br, bl);
1890
- topleft = 1 - interpolateX(minV, tr, tl);
1891
- edges.push(isoBandEdgeBL[cval]);
1892
- } else if (cval === 105) {
1893
- /* 1221 */
1894
- bottomleft = interpolateX(maxV, bl, br);
1895
- topleft = interpolateX(maxV, tl, tr);
1896
- edges.push(isoBandEdgeBL[cval]);
1897
- } else if (cval === 160) {
1898
- /* 2200 */
1899
- righttop = interpolateX(maxV, br, tr);
1900
- rightbottom = interpolateX(minV, br, tr);
1901
- leftbottom = interpolateX(minV, bl, tl);
1902
- lefttop = interpolateX(maxV, bl, tl);
1903
- edges.push(isoBandEdgeRT[cval]);
1904
- edges.push(isoBandEdgeRB[cval]);
1905
- } else if (cval === 10) {
1906
- /* 0022 */
1907
- righttop = 1 - interpolateX(minV, tr, br);
1908
- rightbottom = 1 - interpolateX(maxV, tr, br);
1909
- leftbottom = 1 - interpolateX(maxV, tl, bl);
1910
- lefttop = 1 - interpolateX(minV, tl, bl);
1911
- edges.push(isoBandEdgeRT[cval]);
1912
- edges.push(isoBandEdgeRB[cval]);
1913
- } else if (cval === 130) {
1914
- /* 2002 */
1915
- bottomright = 1 - interpolateX(minV, br, bl);
1916
- bottomleft = 1 - interpolateX(maxV, br, bl);
1917
- topleft = 1 - interpolateX(maxV, tr, tl);
1918
- topright = 1 - interpolateX(minV, tr, tl);
1919
- edges.push(isoBandEdgeBR[cval]);
1920
- edges.push(isoBandEdgeBL[cval]);
1921
- } else if (cval === 40) {
1922
- /* 0220 */
1923
- bottomright = interpolateX(maxV, bl, br);
1924
- bottomleft = interpolateX(minV, bl, br);
1925
- topleft = interpolateX(minV, tl, tr);
1926
- topright = interpolateX(maxV, tl, tr);
1927
- edges.push(isoBandEdgeBR[cval]);
1928
- edges.push(isoBandEdgeBL[cval]);
1929
- } else if (cval === 101) {
1930
- /* 4th single pentagon cases */
1931
- /* 1211 */
1932
- rightbottom = interpolateX(maxV, br, tr);
1933
- topleft = interpolateX(maxV, tl, tr);
1934
- edges.push(isoBandEdgeRB[cval]);
1935
- } else if (cval === 69) {
1936
- /* 1011 */
1937
- rightbottom = 1 - interpolateX(minV, tr, br);
1938
- topleft = 1 - interpolateX(minV, tr, tl);
1939
- edges.push(isoBandEdgeRB[cval]);
1940
- } else if (cval === 149) {
1941
- /* 2111 */
1942
- leftbottom = interpolateX(maxV, bl, tl);
1943
- topright = 1 - interpolateX(maxV, tr, tl);
1944
- edges.push(isoBandEdgeLB[cval]);
1945
- } else if (cval === 21) {
1946
- /* 0111 */
1947
- leftbottom = 1 - interpolateX(minV, tl, bl);
1948
- topright = interpolateX(minV, tl, tr);
1949
- edges.push(isoBandEdgeLB[cval]);
1950
- } else if (cval === 86) {
1951
- /* 1112 */
1952
- bottomright = 1 - interpolateX(maxV, br, bl);
1953
- lefttop = 1 - interpolateX(maxV, tl, bl);
1954
- edges.push(isoBandEdgeBR[cval]);
1955
- } else if (cval === 84) {
1956
- /* 1110 */
1957
- bottomright = interpolateX(minV, bl, br);
1958
- lefttop = interpolateX(minV, bl, tl);
1959
- edges.push(isoBandEdgeBR[cval]);
1960
- } else if (cval === 89) {
1961
- /* 1121 */
1962
- righttop = 1 - interpolateX(maxV, tr, br);
1963
- bottomleft = interpolateX(maxV, bl, br);
1964
- edges.push(isoBandEdgeBL[cval]);
1965
- } else if (cval === 81) {
1966
- /* 1101 */
1967
- righttop = interpolateX(minV, br, tr);
1968
- bottomleft = 1 - interpolateX(minV, br, bl);
1969
- edges.push(isoBandEdgeBL[cval]);
1970
- } else if (cval === 96) {
1971
- /* 1200 */
1972
- righttop = interpolateX(maxV, br, tr);
1973
- rightbottom = interpolateX(minV, br, tr);
1974
- lefttop = interpolateX(minV, bl, tl);
1975
- topleft = interpolateX(maxV, tl, tr);
1976
- edges.push(isoBandEdgeRT[cval]);
1977
- edges.push(isoBandEdgeRB[cval]);
1978
- } else if (cval === 74) {
1979
- /* 1022 */
1980
- righttop = 1 - interpolateX(minV, tr, br);
1981
- rightbottom = 1 - interpolateX(maxV, tr, br);
1982
- lefttop = 1 - interpolateX(maxV, tl, bl);
1983
- topleft = 1 - interpolateX(minV, tr, tl);
1984
- edges.push(isoBandEdgeRT[cval]);
1985
- edges.push(isoBandEdgeRB[cval]);
1986
- } else if (cval === 24) {
1987
- /* 0120 */
1988
- righttop = 1 - interpolateX(maxV, tr, br);
1989
- bottomright = interpolateX(maxV, bl, br);
1990
- bottomleft = interpolateX(minV, bl, br);
1991
- topright = interpolateX(minV, tl, tr);
1992
- edges.push(isoBandEdgeRT[cval]);
1993
- edges.push(isoBandEdgeBL[cval]);
1994
- } else if (cval === 146) {
1995
- /* 2102 */
1996
- righttop = interpolateX(minV, br, tr);
1997
- bottomright = 1 - interpolateX(minV, br, bl);
1998
- bottomleft = 1 - interpolateX(maxV, br, bl);
1999
- topright = 1 - interpolateX(maxV, tr, tl);
2000
- edges.push(isoBandEdgeRT[cval]);
2001
- edges.push(isoBandEdgeBL[cval]);
2002
- } else if (cval === 6) {
2003
- /* 0012 */
2004
- rightbottom = 1 - interpolateX(minV, tr, br);
2005
- bottomright = 1 - interpolateX(maxV, br, bl);
2006
- leftbottom = 1 - interpolateX(maxV, tl, bl);
2007
- lefttop = 1 - interpolateX(minV, tl, bl);
2008
- edges.push(isoBandEdgeRB[cval]);
2009
- edges.push(isoBandEdgeBR[cval]);
2010
- } else if (cval === 164) {
2011
- /* 2210 */
2012
- rightbottom = interpolateX(maxV, br, tr);
2013
- bottomright = interpolateX(minV, bl, br);
2014
- leftbottom = interpolateX(minV, bl, tl);
2015
- lefttop = interpolateX(maxV, bl, tl);
2016
- edges.push(isoBandEdgeRB[cval]);
2017
- edges.push(isoBandEdgeBR[cval]);
2018
- } else if (cval === 129) {
2019
- /* 2001 */
2020
- bottomleft = 1 - interpolateX(minV, br, bl);
2021
- leftbottom = interpolateX(maxV, bl, tl);
2022
- topleft = 1 - interpolateX(maxV, tr, tl);
2023
- topright = 1 - interpolateX(minV, tr, tl);
2024
- edges.push(isoBandEdgeBL[cval]);
2025
- edges.push(isoBandEdgeLB[cval]);
2026
- } else if (cval === 41) {
2027
- /* 0221 */
2028
- bottomleft = interpolateX(maxV, bl, br);
2029
- leftbottom = 1 - interpolateX(minV, tl, bl);
2030
- topleft = interpolateX(minV, tl, tr);
2031
- topright = interpolateX(maxV, tl, tr);
2032
- edges.push(isoBandEdgeBL[cval]);
2033
- edges.push(isoBandEdgeLB[cval]);
2034
- } else if (cval === 66) {
2035
- /* 1002 */
2036
- bottomright = 1 - interpolateX(minV, br, bl);
2037
- bottomleft = 1 - interpolateX(maxV, br, bl);
2038
- lefttop = 1 - interpolateX(maxV, tl, bl);
2039
- topleft = 1 - interpolateX(minV, tr, tl);
2040
- edges.push(isoBandEdgeBR[cval]);
2041
- edges.push(isoBandEdgeBL[cval]);
2042
- } else if (cval === 104) {
2043
- /* 1220 */
2044
- bottomright = interpolateX(maxV, bl, br);
2045
- bottomleft = interpolateX(minV, bl, br);
2046
- lefttop = interpolateX(minV, bl, tl);
2047
- topleft = interpolateX(maxV, tl, tr);
2048
- edges.push(isoBandEdgeBL[cval]);
2049
- edges.push(isoBandEdgeTL[cval]);
2050
- } else if (cval === 144) {
2051
- /* 2100 */
2052
- righttop = interpolateX(minV, br, tr);
2053
- leftbottom = interpolateX(minV, bl, tl);
2054
- lefttop = interpolateX(maxV, bl, tl);
2055
- topright = 1 - interpolateX(maxV, tr, tl);
2056
- edges.push(isoBandEdgeRT[cval]);
2057
- edges.push(isoBandEdgeLT[cval]);
2058
- } else if (cval === 26) {
2059
- /* 0122 */
2060
- righttop = 1 - interpolateX(maxV, tr, br);
2061
- leftbottom = 1 - interpolateX(maxV, tl, bl);
2062
- lefttop = 1 - interpolateX(minV, tl, bl);
2063
- topright = interpolateX(minV, tl, tr);
2064
- edges.push(isoBandEdgeRT[cval]);
2065
- edges.push(isoBandEdgeLT[cval]);
2066
- } else if (cval === 36) {
2067
- /* 0210 */
2068
- rightbottom = interpolateX(maxV, br, tr);
2069
- bottomright = interpolateX(minV, bl, br);
2070
- topleft = interpolateX(minV, tl, tr);
2071
- topright = interpolateX(maxV, tl, tr);
2072
- edges.push(isoBandEdgeRB[cval]);
2073
- edges.push(isoBandEdgeBR[cval]);
2074
- } else if (cval === 134) {
2075
- /* 2012 */
2076
- rightbottom = 1 - interpolateX(minV, tr, br);
2077
- bottomright = 1 - interpolateX(maxV, br, bl);
2078
- topleft = 1 - interpolateX(maxV, tr, tl);
2079
- topright = 1 - interpolateX(minV, tr, tl);
2080
- edges.push(isoBandEdgeRB[cval]);
2081
- edges.push(isoBandEdgeBR[cval]);
2082
- } else if (cval === 9) {
2083
- /* 0021 */
2084
- righttop = 1 - interpolateX(minV, tr, br);
2085
- rightbottom = 1 - interpolateX(maxV, tr, br);
2086
- bottomleft = interpolateX(maxV, bl, br);
2087
- leftbottom = 1 - interpolateX(minV, tl, bl);
2088
- edges.push(isoBandEdgeRT[cval]);
2089
- edges.push(isoBandEdgeRB[cval]);
2090
- } else if (cval === 161) {
2091
- /* 2201 */
2092
- righttop = interpolateX(maxV, br, tr);
2093
- rightbottom = interpolateX(minV, br, tr);
2094
- bottomleft = 1 - interpolateX(minV, br, bl);
2095
- leftbottom = interpolateX(maxV, bl, tl);
2096
- edges.push(isoBandEdgeRT[cval]);
2097
- edges.push(isoBandEdgeRB[cval]);
2098
- } else if (cval === 37) {
2099
- /* 5th single hexagon cases */
2100
- /* 0211 */
2101
- rightbottom = interpolateX(maxV, br, tr);
2102
- leftbottom = 1 - interpolateX(minV, tl, bl);
2103
- topleft = interpolateX(minV, tl, tr);
2104
- topright = interpolateX(maxV, tl, tr);
2105
- edges.push(isoBandEdgeRB[cval]);
2106
- edges.push(isoBandEdgeLB[cval]);
2107
- } else if (cval === 133) {
2108
- /* 2011 */
2109
- rightbottom = 1 - interpolateX(minV, tr, br);
2110
- leftbottom = interpolateX(maxV, bl, tl);
2111
- topleft = 1 - interpolateX(maxV, tr, tl);
2112
- topright = 1 - interpolateX(minV, tr, tl);
2113
- edges.push(isoBandEdgeRB[cval]);
2114
- edges.push(isoBandEdgeLB[cval]);
2115
- } else if (cval === 148) {
2116
- /* 2110 */
2117
- bottomright = interpolateX(minV, bl, br);
2118
- leftbottom = interpolateX(minV, bl, tl);
2119
- lefttop = interpolateX(maxV, bl, tl);
2120
- topright = 1 - interpolateX(maxV, tr, tl);
2121
- edges.push(isoBandEdgeBR[cval]);
2122
- edges.push(isoBandEdgeLT[cval]);
2123
- } else if (cval === 22) {
2124
- /* 0112 */
2125
- bottomright = 1 - interpolateX(maxV, br, bl);
2126
- leftbottom = 1 - interpolateX(maxV, tl, bl);
2127
- lefttop = 1 - interpolateX(minV, tl, bl);
2128
- topright = interpolateX(minV, tl, tr);
2129
- edges.push(isoBandEdgeBR[cval]);
2130
- edges.push(isoBandEdgeLT[cval]);
2131
- } else if (cval === 82) {
2132
- /* 1102 */
2133
- righttop = interpolateX(minV, br, tr);
2134
- bottomright = 1 - interpolateX(minV, br, bl);
2135
- bottomleft = 1 - interpolateX(maxV, br, bl);
2136
- lefttop = 1 - interpolateX(maxV, tl, bl);
2137
- edges.push(isoBandEdgeRT[cval]);
2138
- edges.push(isoBandEdgeBL[cval]);
2139
- } else if (cval === 88) {
2140
- /* 1120 */
2141
- righttop = 1 - interpolateX(maxV, tr, br);
2142
- bottomright = interpolateX(maxV, bl, br);
2143
- bottomleft = interpolateX(minV, bl, br);
2144
- lefttop = interpolateX(minV, bl, tl);
2145
- edges.push(isoBandEdgeRT[cval]);
2146
- edges.push(isoBandEdgeBL[cval]);
2147
- } else if (cval === 73) {
2148
- /* 1021 */
2149
- righttop = 1 - interpolateX(minV, tr, br);
2150
- rightbottom = 1 - interpolateX(maxV, tr, br);
2151
- bottomleft = interpolateX(maxV, bl, br);
2152
- topleft = 1 - interpolateX(minV, tr, tl);
2153
- edges.push(isoBandEdgeRT[cval]);
2154
- edges.push(isoBandEdgeRB[cval]);
2155
- } else if (cval === 97) {
2156
- /* 1201 */
2157
- righttop = interpolateX(maxV, br, tr);
2158
- rightbottom = interpolateX(minV, br, tr);
2159
- bottomleft = 1 - interpolateX(minV, br, bl);
2160
- topleft = interpolateX(maxV, tl, tr);
2161
- edges.push(isoBandEdgeRT[cval]);
2162
- edges.push(isoBandEdgeRB[cval]);
2163
- } else if (cval === 145) {
2164
- /* 2101 */
2165
- righttop = interpolateX(minV, br, tr);
2166
- bottomleft = 1 - interpolateX(minV, br, bl);
2167
- leftbottom = interpolateX(maxV, bl, tl);
2168
- topright = 1 - interpolateX(maxV, tr, tl);
2169
- edges.push(isoBandEdgeRT[cval]);
2170
- edges.push(isoBandEdgeLB[cval]);
2171
- } else if (cval === 25) {
2172
- /* 0121 */
2173
- righttop = 1 - interpolateX(maxV, tr, br);
2174
- bottomleft = interpolateX(maxV, bl, br);
2175
- leftbottom = 1 - interpolateX(minV, tl, bl);
2176
- topright = interpolateX(minV, tl, tr);
2177
- edges.push(isoBandEdgeRT[cval]);
2178
- edges.push(isoBandEdgeLB[cval]);
2179
- } else if (cval === 70) {
2180
- /* 1012 */
2181
- rightbottom = 1 - interpolateX(minV, tr, br);
2182
- bottomright = 1 - interpolateX(maxV, br, bl);
2183
- lefttop = 1 - interpolateX(maxV, tl, bl);
2184
- topleft = 1 - interpolateX(minV, tr, tl);
2185
- edges.push(isoBandEdgeRB[cval]);
2186
- edges.push(isoBandEdgeBR[cval]);
2187
- } else if (cval === 100) {
2188
- /* 1210 */
2189
- rightbottom = interpolateX(maxV, br, tr);
2190
- bottomright = interpolateX(minV, bl, br);
2191
- lefttop = interpolateX(minV, bl, tl);
2192
- topleft = interpolateX(maxV, tl, tr);
2193
- edges.push(isoBandEdgeRB[cval]);
2194
- edges.push(isoBandEdgeBR[cval]);
2195
- } else if (cval === 34) {
2196
- /* 8-sided cases */
2197
- /* 0202 || 2020 with flipped == 0 */
2198
- if (flipped === 0) {
2199
- righttop = 1 - interpolateX(minV, tr, br);
2200
- rightbottom = 1 - interpolateX(maxV, tr, br);
2201
- bottomright = interpolateX(maxV, bl, br);
2202
- bottomleft = interpolateX(minV, bl, br);
2203
- leftbottom = interpolateX(minV, bl, tl);
2204
- lefttop = interpolateX(maxV, bl, tl);
2205
- topleft = 1 - interpolateX(maxV, tr, tl);
2206
- topright = 1 - interpolateX(minV, tr, tl);
2207
- } else {
2208
- righttop = interpolateX(maxV, br, tr);
2209
- rightbottom = interpolateX(minV, br, tr);
2210
- bottomright = 1 - interpolateX(minV, br, bl);
2211
- bottomleft = 1 - interpolateX(maxV, br, bl);
2212
- leftbottom = 1 - interpolateX(maxV, tl, bl);
2213
- lefttop = 1 - interpolateX(minV, tl, bl);
2214
- topleft = interpolateX(minV, tl, tr);
2215
- topright = interpolateX(maxV, tl, tr);
2216
- }
2217
- edges.push(isoBandEdgeRT[cval]);
2218
- edges.push(isoBandEdgeRB[cval]);
2219
- edges.push(isoBandEdgeLB[cval]);
2220
- edges.push(isoBandEdgeLT[cval]);
2221
- } else if (cval === 35) {
2222
- /* flipped == 1 state for 0202, and 2020 with flipped == 4*/
2223
- if (flipped === 4) {
2224
- righttop = 1 - interpolateX(minV, tr, br);
2225
- rightbottom = 1 - interpolateX(maxV, tr, br);
2226
- bottomright = interpolateX(maxV, bl, br);
2227
- bottomleft = interpolateX(minV, bl, br);
2228
- leftbottom = interpolateX(minV, bl, tl);
2229
- lefttop = interpolateX(maxV, bl, tl);
2230
- topleft = 1 - interpolateX(maxV, tr, tl);
2231
- topright = 1 - interpolateX(minV, tr, tl);
2232
- } else {
2233
- righttop = interpolateX(maxV, br, tr);
2234
- rightbottom = interpolateX(minV, br, tr);
2235
- bottomright = 1 - interpolateX(minV, br, bl);
2236
- bottomleft = 1 - interpolateX(maxV, br, bl);
2237
- leftbottom = 1 - interpolateX(maxV, tl, bl);
2238
- lefttop = 1 - interpolateX(minV, tl, bl);
2239
- topleft = interpolateX(minV, tl, tr);
2240
- topright = interpolateX(maxV, tl, tr);
2241
- }
2242
- edges.push(isoBandEdgeRT[cval]);
2243
- edges.push(isoBandEdgeRB[cval]);
2244
- edges.push(isoBandEdgeBL[cval]);
2245
- edges.push(isoBandEdgeLT[cval]);
2246
- } else if (cval === 136) {
2247
- /* 2020 || 0202 with flipped == 0 */
2248
- if (flipped === 0) {
2249
- righttop = interpolateX(maxV, br, tr);
2250
- rightbottom = interpolateX(minV, br, tr);
2251
- bottomright = 1 - interpolateX(minV, br, bl);
2252
- bottomleft = 1 - interpolateX(maxV, br, bl);
2253
- leftbottom = 1 - interpolateX(maxV, tl, bl);
2254
- lefttop = 1 - interpolateX(minV, tl, bl);
2255
- topleft = interpolateX(minV, tl, tr);
2256
- topright = interpolateX(maxV, tl, tr);
2257
- } else {
2258
- righttop = 1 - interpolateX(minV, tr, br);
2259
- rightbottom = 1 - interpolateX(maxV, tr, br);
2260
- bottomright = interpolateX(maxV, bl, br);
2261
- bottomleft = interpolateX(minV, bl, br);
2262
- leftbottom = interpolateX(minV, bl, tl);
2263
- lefttop = interpolateX(maxV, bl, tl);
2264
- topleft = 1 - interpolateX(maxV, tr, tl);
2265
- topright = 1 - interpolateX(minV, tr, tl);
2266
- }
2267
- edges.push(isoBandEdgeRT[cval]);
2268
- edges.push(isoBandEdgeRB[cval]);
2269
- edges.push(isoBandEdgeLB[cval]);
2270
- edges.push(isoBandEdgeLT[cval]);
2271
- } else if (cval === 153) {
2272
- /* 6-sided polygon cases */
2273
- /* 0101 with flipped == 0 || 2121 with flipped == 2 */
2274
- if (flipped === 0) {
2275
- righttop = interpolateX(minV, br, tr);
2276
- bottomleft = 1 - interpolateX(minV, br, bl);
2277
- leftbottom = 1 - interpolateX(minV, tl, bl);
2278
- topright = interpolateX(minV, tl, tr);
2279
- } else {
2280
- righttop = 1 - interpolateX(maxV, tr, br);
2281
- bottomleft = interpolateX(maxV, bl, br);
2282
- leftbottom = interpolateX(maxV, bl, tl);
2283
- topright = 1 - interpolateX(maxV, tr, tl);
2284
- }
2285
- edges.push(isoBandEdgeRT[cval]);
2286
- edges.push(isoBandEdgeBL[cval]);
2287
- } else if (cval === 102) {
2288
- /* 1010 with flipped == 0 || 1212 with flipped == 2 */
2289
- if (flipped === 0) {
2290
- rightbottom = 1 - interpolateX(minV, tr, br);
2291
- bottomright = interpolateX(minV, bl, br);
2292
- lefttop = interpolateX(minV, bl, tl);
2293
- topleft = 1 - interpolateX(minV, tr, tl);
2294
- } else {
2295
- rightbottom = interpolateX(maxV, br, tr);
2296
- bottomright = 1 - interpolateX(maxV, br, bl);
2297
- lefttop = 1 - interpolateX(maxV, tl, bl);
2298
- topleft = interpolateX(maxV, tl, tr);
2299
- }
2300
- edges.push(isoBandEdgeRB[cval]);
2301
- edges.push(isoBandEdgeLT[cval]);
2302
- } else if (cval === 155) {
2303
- /* 0101 with flipped == 4 || 2121 with flipped == 1 */
2304
- if (flipped === 4) {
2305
- righttop = interpolateX(minV, br, tr);
2306
- bottomleft = 1 - interpolateX(minV, br, bl);
2307
- leftbottom = 1 - interpolateX(minV, tl, bl);
2308
- topright = interpolateX(minV, tl, tr);
2309
- } else {
2310
- righttop = 1 - interpolateX(maxV, tr, br);
2311
- bottomleft = interpolateX(maxV, bl, br);
2312
- leftbottom = interpolateX(maxV, bl, tl);
2313
- topright = 1 - interpolateX(maxV, tr, tl);
2314
- }
2315
- edges.push(isoBandEdgeRT[cval]);
2316
- edges.push(isoBandEdgeLB[cval]);
2317
- } else if (cval === 103) {
2318
- /* 1010 with flipped == 4 || 1212 with flipped == 1 */
2319
- if (flipped === 4) {
2320
- rightbottom = 1 - interpolateX(minV, tr, br);
2321
- bottomright = interpolateX(minV, bl, br);
2322
- lefttop = interpolateX(minV, bl, tl);
2323
- topleft = 1 - interpolateX(minV, tr, tl);
2324
- } else {
2325
- rightbottom = interpolateX(maxV, br, tr);
2326
- bottomright = 1 - interpolateX(maxV, br, bl);
2327
- lefttop = 1 - interpolateX(maxV, tl, bl);
2328
- topleft = interpolateX(maxV, tl, tr);
2329
- }
2330
- edges.push(isoBandEdgeRB[cval]);
2331
- edges.push(isoBandEdgeBR[cval]);
2332
- } else if (cval === 152) {
2333
- /* 7-sided polygon cases */
2334
- /* 2120 with flipped == 2 || 0102 with flipped == 0 */
2335
- if (flipped === 0) {
2336
- righttop = interpolateX(minV, br, tr);
2337
- bottomright = 1 - interpolateX(minV, br, bl);
2338
- bottomleft = 1 - interpolateX(maxV, br, bl);
2339
- leftbottom = 1 - interpolateX(maxV, tl, bl);
2340
- lefttop = 1 - interpolateX(minV, tl, bl);
2341
- topright = interpolateX(minV, tl, tr);
2342
- } else {
2343
- righttop = 1 - interpolateX(maxV, tr, br);
2344
- bottomright = interpolateX(maxV, bl, br);
2345
- bottomleft = interpolateX(minV, bl, br);
2346
- leftbottom = interpolateX(minV, bl, tl);
2347
- lefttop = interpolateX(maxV, bl, tl);
2348
- topright = 1 - interpolateX(maxV, tr, tl);
2349
- }
2350
- edges.push(isoBandEdgeRT[cval]);
2351
- edges.push(isoBandEdgeBR[cval]);
2352
- edges.push(isoBandEdgeBL[cval]);
2353
- } else if (cval === 156) {
2354
- /* 2120 with flipped == 1 || 0102 with flipped == 4 */
2355
- if (flipped === 4) {
2356
- righttop = interpolateX(minV, br, tr);
2357
- bottomright = 1 - interpolateX(minV, br, bl);
2358
- bottomleft = 1 - interpolateX(maxV, br, bl);
2359
- leftbottom = 1 - interpolateX(maxV, tl, bl);
2360
- lefttop = 1 - interpolateX(minV, tl, bl);
2361
- topright = interpolateX(minV, tl, tr);
2362
- } else {
2363
- righttop = 1 - interpolateX(maxV, tr, br);
2364
- bottomright = interpolateX(maxV, bl, br);
2365
- bottomleft = interpolateX(minV, bl, br);
2366
- leftbottom = interpolateX(minV, bl, tl);
2367
- lefttop = interpolateX(maxV, bl, tl);
2368
- topright = 1 - interpolateX(maxV, tr, tl);
2369
- }
2370
- edges.push(isoBandEdgeRT[cval]);
2371
- edges.push(isoBandEdgeBL[cval]);
2372
- edges.push(isoBandEdgeLT[cval]);
2373
- } else if (cval === 137) {
2374
- /* 2021 with flipped == 2 || 0201 with flipped == 0 */
2375
- if (flipped === 0) {
2376
- righttop = interpolateX(maxV, br, tr);
2377
- rightbottom = interpolateX(minV, br, tr);
2378
- bottomleft = 1 - interpolateX(minV, br, bl);
2379
- leftbottom = 1 - interpolateX(minV, tl, bl);
2380
- topleft = interpolateX(minV, tl, tr);
2381
- topright = interpolateX(maxV, tl, tr);
2382
- } else {
2383
- righttop = 1 - interpolateX(minV, tr, br);
2384
- rightbottom = 1 - interpolateX(maxV, tr, br);
2385
- bottomleft = interpolateX(maxV, bl, br);
2386
- leftbottom = interpolateX(maxV, bl, tl);
2387
- topleft = 1 - interpolateX(maxV, tr, tl);
2388
- topright = 1 - interpolateX(minV, tr, tl);
2389
- }
2390
- edges.push(isoBandEdgeRT[cval]);
2391
- edges.push(isoBandEdgeRB[cval]);
2392
- edges.push(isoBandEdgeBL[cval]);
2393
- } else if (cval === 139) {
2394
- /* 2021 with flipped == 1 || 0201 with flipped == 4 */
2395
- if (flipped === 4) {
2396
- righttop = interpolateX(maxV, br, tr);
2397
- rightbottom = interpolateX(minV, br, tr);
2398
- bottomleft = 1 - interpolateX(minV, br, bl);
2399
- leftbottom = 1 - interpolateX(minV, tl, bl);
2400
- topleft = interpolateX(minV, tl, tr);
2401
- topright = interpolateX(maxV, tl, tr);
2402
- } else {
2403
- righttop = 1 - interpolateX(minV, tr, br);
2404
- rightbottom = 1 - interpolateX(maxV, tr, br);
2405
- bottomleft = interpolateX(maxV, bl, br);
2406
- leftbottom = interpolateX(maxV, bl, tl);
2407
- topleft = 1 - interpolateX(maxV, tr, tl);
2408
- topright = 1 - interpolateX(minV, tr, tl);
2409
- }
2410
- edges.push(isoBandEdgeRT[cval]);
2411
- edges.push(isoBandEdgeRB[cval]);
2412
- edges.push(isoBandEdgeLB[cval]);
2413
- } else if (cval === 98) {
2414
- /* 1202 with flipped == 2 || 1020 with flipped == 0 */
2415
- if (flipped === 0) {
2416
- righttop = 1 - interpolateX(minV, tr, br);
2417
- rightbottom = 1 - interpolateX(maxV, tr, br);
2418
- bottomright = interpolateX(maxV, bl, br);
2419
- bottomleft = interpolateX(minV, bl, br);
2420
- lefttop = interpolateX(minV, bl, tl);
2421
- topleft = 1 - interpolateX(minV, tr, tl);
2422
- } else {
2423
- righttop = interpolateX(maxV, br, tr);
2424
- rightbottom = interpolateX(minV, br, tr);
2425
- bottomright = 1 - interpolateX(minV, br, bl);
2426
- bottomleft = 1 - interpolateX(maxV, br, bl);
2427
- lefttop = 1 - interpolateX(maxV, tl, bl);
2428
- topleft = interpolateX(maxV, tl, tr);
2429
- }
2430
- edges.push(isoBandEdgeRT[cval]);
2431
- edges.push(isoBandEdgeRB[cval]);
2432
- edges.push(isoBandEdgeLT[cval]);
2433
- } else if (cval === 99) {
2434
- /* 1202 with flipped == 1 || 1020 with flipped == 4 */
2435
- if (flipped === 4) {
2436
- righttop = 1 - interpolateX(minV, tr, br);
2437
- rightbottom = 1 - interpolateX(maxV, tr, br);
2438
- bottomright = interpolateX(maxV, bl, br);
2439
- bottomleft = interpolateX(minV, bl, br);
2440
- lefttop = interpolateX(minV, bl, tl);
2441
- topleft = 1 - interpolateX(minV, tr, tl);
2442
- } else {
2443
- righttop = interpolateX(maxV, br, tr);
2444
- rightbottom = interpolateX(minV, br, tr);
2445
- bottomright = 1 - interpolateX(minV, br, bl);
2446
- bottomleft = 1 - interpolateX(maxV, br, bl);
2447
- lefttop = 1 - interpolateX(maxV, tl, bl);
2448
- topleft = interpolateX(maxV, tl, tr);
2449
- }
2450
- edges.push(isoBandEdgeRT[cval]);
2451
- edges.push(isoBandEdgeRB[cval]);
2452
- edges.push(isoBandEdgeBL[cval]);
2453
- } else if (cval === 38) {
2454
- /* 0212 with flipped == 2 || 2010 with flipped == 0 */
2455
- if (flipped === 0) {
2456
- rightbottom = 1 - interpolateX(minV, tr, br);
2457
- bottomright = interpolateX(minV, bl, br);
2458
- leftbottom = interpolateX(minV, bl, tl);
2459
- lefttop = interpolateX(maxV, bl, tl);
2460
- topleft = 1 - interpolateX(maxV, tr, tl);
2461
- topright = 1 - interpolateX(minV, tr, tl);
2462
- } else {
2463
- rightbottom = interpolateX(maxV, br, tr);
2464
- bottomright = 1 - interpolateX(maxV, br, bl);
2465
- leftbottom = 1 - interpolateX(maxV, tl, bl);
2466
- lefttop = 1 - interpolateX(minV, tl, bl);
2467
- topleft = interpolateX(minV, tl, tr);
2468
- topright = interpolateX(maxV, tl, tr);
2469
- }
2470
- edges.push(isoBandEdgeRB[cval]);
2471
- edges.push(isoBandEdgeLB[cval]);
2472
- edges.push(isoBandEdgeLT[cval]);
2473
- } else if (cval === 39) {
2474
- /* 0212 with flipped == 1 || 2010 with flipped == 4 */
2475
- if (flipped === 4) {
2476
- rightbottom = 1 - interpolateX(minV, tr, br);
2477
- bottomright = interpolateX(minV, bl, br);
2478
- leftbottom = interpolateX(minV, bl, tl);
2479
- lefttop = interpolateX(maxV, bl, tl);
2480
- topleft = 1 - interpolateX(maxV, tr, tl);
2481
- topright = 1 - interpolateX(minV, tr, tl);
2482
- } else {
2483
- rightbottom = interpolateX(maxV, br, tr);
2484
- bottomright = 1 - interpolateX(maxV, br, bl);
2485
- leftbottom = 1 - interpolateX(maxV, tl, bl);
2486
- lefttop = 1 - interpolateX(minV, tl, bl);
2487
- topleft = interpolateX(minV, tl, tr);
2488
- topright = interpolateX(maxV, tl, tr);
2489
- }
2490
- edges.push(isoBandEdgeRB[cval]);
2491
- edges.push(isoBandEdgeBR[cval]);
2492
- edges.push(isoBandEdgeLT[cval]);
2493
- } else if (cval === 85) {
2494
- righttop = 1;
2495
- rightbottom = 0;
2496
- bottomright = 1;
2497
- bottomleft = 0;
2498
- leftbottom = 0;
2499
- lefttop = 1;
2500
- topleft = 0;
2501
- topright = 1;
2502
- }
2503
-
2504
- if (
2505
- topleft < 0 ||
2506
- topleft > 1 ||
2507
- topright < 0 ||
2508
- topright > 1 ||
2509
- righttop < 0 ||
2510
- righttop > 1 ||
2511
- bottomright < 0 ||
2512
- bottomright > 1 ||
2513
- leftbottom < 0 ||
2514
- leftbottom > 1 ||
2515
- lefttop < 0 ||
2516
- lefttop > 1
2517
- ) {
2518
- console.log(
2519
- "MarchingSquaresJS-isoBands: " +
2520
- cval +
2521
- " " +
2522
- cval_real +
2523
- " " +
2524
- tl +
2525
- "," +
2526
- tr +
2527
- "," +
2528
- br +
2529
- "," +
2530
- bl +
2531
- " " +
2532
- flipped +
2533
- " " +
2534
- topleft +
2535
- " " +
2536
- topright +
2537
- " " +
2538
- righttop +
2539
- " " +
2540
- rightbottom +
2541
- " " +
2542
- bottomright +
2543
- " " +
2544
- bottomleft +
2545
- " " +
2546
- leftbottom +
2547
- " " +
2548
- lefttop
2549
- );
2550
- }
2551
-
2552
- BandGrid.cells[j][i] = {
2553
- cval: cval,
2554
- cval_real: cval_real,
2555
- flipped: flipped,
2556
- topleft: topleft,
2557
- topright: topright,
2558
- righttop: righttop,
2559
- rightbottom: rightbottom,
2560
- bottomright: bottomright,
2561
- bottomleft: bottomleft,
2562
- leftbottom: leftbottom,
2563
- lefttop: lefttop,
2564
- edges: edges,
2565
- };
2566
- }
2567
- }
2568
- }
2569
-
2570
- return BandGrid;
2571
- }
2572
-
2573
- function BandGrid2AreaPaths(grid) {
2574
- var areas = [];
2575
- var rows = grid.rows;
2576
- var cols = grid.cols;
2577
- var currentPolygon = [];
2578
-
2579
- for (var j = 0; j < rows; j++) {
2580
- for (var i = 0; i < cols; i++) {
2581
- if (
2582
- typeof grid.cells[j][i] !== "undefined" &&
2583
- grid.cells[j][i].edges.length > 0
2584
- ) {
2585
- /* trace back polygon path starting from this cell */
2586
-
2587
- var cell = grid.cells[j][i];
2588
-
2589
- /* get start coordinates */
2590
-
2591
- var prev = getStartXY(cell),
2592
- next = null,
2593
- p = i,
2594
- q = j;
2595
-
2596
- if (prev !== null) {
2597
- currentPolygon.push([prev.p[0] + p, prev.p[1] + q]);
2598
- //console.log(cell);
2599
- //console.log("coords: " + (prev.p[0] + p) + " " + (prev.p[1] + q));
2600
- }
2601
-
2602
- do {
2603
- //console.log(p + "," + q);
2604
- //console.log(grid.cells[q][p]);
2605
- //console.log(grid.cells[q][p].edges);
2606
- //console.log("from : " + prev.x + " " + prev.y + " " + prev.o);
2607
-
2608
- next = getExitXY(grid.cells[q][p], prev.x, prev.y, prev.o);
2609
- if (next !== null) {
2610
- //console.log("coords: " + (next.p[0] + p) + " " + (next.p[1] + q));
2611
- currentPolygon.push([next.p[0] + p, next.p[1] + q]);
2612
- p += next.x;
2613
- q += next.y;
2614
- prev = next;
2615
- } else {
2616
- //console.log("getExitXY() returned null!");
2617
- break;
2618
- }
2619
- //console.log("to : " + next.x + " " + next.y + " " + next.o);
2620
- /* special case, where we've reached the grid boundaries */
2621
- if (
2622
- q < 0 ||
2623
- q >= rows ||
2624
- p < 0 ||
2625
- p >= cols ||
2626
- typeof grid.cells[q][p] === "undefined"
2627
- ) {
2628
- /* to create a closed path, we need to trace our way
2629
- arround the missing data, until we find an entry
2630
- point again
2631
- */
2632
-
2633
- /* set back coordinates of current cell */
2634
- p -= next.x;
2635
- q -= next.y;
2636
-
2637
- //console.log("reached boundary at " + p + " " + q);
2638
-
2639
- var missing = traceOutOfGridPath(
2640
- grid,
2641
- p,
2642
- q,
2643
- next.x,
2644
- next.y,
2645
- next.o
2646
- );
2647
- if (missing !== null) {
2648
- missing.path.forEach(function (pp) {
2649
- //console.log("coords: " + (pp[0]) + " " + (pp[1]));
2650
- currentPolygon.push(pp);
2651
- });
2652
- p = missing.i;
2653
- q = missing.j;
2654
- prev = missing;
2655
- } else {
2656
- break;
2657
- }
2658
- //console.log(grid.cells[q][p]);
2659
- }
2660
- } while (
2661
- typeof grid.cells[q][p] !== "undefined" &&
2662
- grid.cells[q][p].edges.length > 0
2663
- );
2664
-
2665
- areas.push(currentPolygon);
2666
- //console.log("next polygon");
2667
- //console.log(currentPolygon);
2668
- currentPolygon = [];
2669
- if (grid.cells[j][i].edges.length > 0) i--;
2670
- }
2671
- }
2672
- }
2673
- return areas;
2674
- }
2675
-
2676
- function traceOutOfGridPath(grid, i, j, d_x, d_y, d_o) {
2677
- var cell = grid.cells[j][i];
2678
- var cval = cell.cval_real;
2679
- var p = i + d_x,
2680
- q = j + d_y;
2681
- var path = [];
2682
- var closed = false;
2683
-
2684
- while (!closed) {
2685
- //console.log("processing cell " + p + "," + q + " " + d_x + " " + d_y + " " + d_o);
2686
- if (
2687
- typeof grid.cells[q] === "undefined" ||
2688
- typeof grid.cells[q][p] === "undefined"
2689
- ) {
2690
- //console.log("which is undefined");
2691
- /* we can't move on, so we have to change direction to proceed further */
2692
-
2693
- /* go back to previous cell */
2694
- q -= d_y;
2695
- p -= d_x;
2696
- cell = grid.cells[q][p];
2697
- cval = cell.cval_real;
2698
-
2699
- /* check where we've left defined cells of the grid... */
2700
- if (d_y === -1) {
2701
- /* we came from top */
2702
- if (d_o === 0) {
2703
- /* exit left */
2704
- if (cval & Node3) {
2705
- /* lower left node is within range, so we move left */
2706
- path.push([p, q]);
2707
- d_x = -1;
2708
- d_y = 0;
2709
- d_o = 0;
2710
- } else if (cval & Node2) {
2711
- /* lower right node is within range, so we move right */
2712
- path.push([p + 1, q]);
2713
- d_x = 1;
2714
- d_y = 0;
2715
- d_o = 0;
2716
- } else {
2717
- /* close the path */
2718
- path.push([p + cell.bottomright, q]);
2719
- d_x = 0;
2720
- d_y = 1;
2721
- d_o = 1;
2722
- closed = true;
2723
- break;
2724
- }
2725
- } else if (cval & Node3) {
2726
- path.push([p, q]);
2727
- d_x = -1;
2728
- d_y = 0;
2729
- d_o = 0;
2730
- } else if (cval & Node2) {
2731
- path.push([p + cell.bottomright, q]);
2732
- d_x = 0;
2733
- d_y = 1;
2734
- d_o = 1;
2735
- closed = true;
2736
- break;
2737
- } else {
2738
- path.push([p + cell.bottomleft, q]);
2739
- d_x = 0;
2740
- d_y = 1;
2741
- d_o = 0;
2742
- closed = true;
2743
- break;
2744
- }
2745
- } else if (d_y === 1) {
2746
- /* we came from bottom */
2747
- //console.log("we came from bottom and hit a non-existing cell " + (p + d_x) + "," + (q + d_y) + "!");
2748
- if (d_o === 0) {
2749
- /* exit left */
2750
- if (cval & Node1) {
2751
- /* top right node is within range, so we move right */
2752
- path.push([p + 1, q + 1]);
2753
- d_x = 1;
2754
- d_y = 0;
2755
- d_o = 1;
2756
- } else if (!(cval & Node0)) {
2757
- /* found entry within same cell */
2758
- path.push([p + cell.topright, q + 1]);
2759
- d_x = 0;
2760
- d_y = -1;
2761
- d_o = 1;
2762
- closed = true;
2763
- //console.log("found entry from bottom at " + p + "," + q);
2764
- break;
2765
- } else {
2766
- path.push([p + cell.topleft, q + 1]);
2767
- d_x = 0;
2768
- d_y = -1;
2769
- d_o = 0;
2770
- closed = true;
2771
- break;
2772
- }
2773
- } else if (cval & Node1) {
2774
- path.push([p + 1, q + 1]);
2775
- d_x = 1;
2776
- d_y = 0;
2777
- d_o = 1;
2778
- } else {
2779
- /* move right */
2780
- path.push([p + 1, q + 1]);
2781
- d_x = 1;
2782
- d_y = 0;
2783
- d_o = 1;
2784
- //console.log("wtf");
2785
- //break;
2786
- }
2787
- } else if (d_x === -1) {
2788
- /* we came from right */
2789
- //console.log("we came from right and hit a non-existing cell at " + (p + d_x) + "," + (q + d_y) + "!");
2790
- if (d_o === 0) {
2791
- //console.log("continue at bottom");
2792
- if (cval & Node0) {
2793
- path.push([p, q + 1]);
2794
- d_x = 0;
2795
- d_y = 1;
2796
- d_o = 0;
2797
- //console.log("moving upwards to " + (p + d_x) + "," + (q + d_y) + "!");
2798
- } else if (!(cval & Node3)) {
2799
- /* there has to be an entry into the regular grid again! */
2800
- //console.log("exiting top");
2801
- path.push([p, q + cell.lefttop]);
2802
- d_x = 1;
2803
- d_y = 0;
2804
- d_o = 1;
2805
- closed = true;
2806
- break;
2807
- } else {
2808
- //console.log("exiting bottom");
2809
- path.push([p, q + cell.leftbottom]);
2810
- d_x = 1;
2811
- d_y = 0;
2812
- d_o = 0;
2813
- closed = true;
2814
- break;
2815
- }
2816
- } else {
2817
- //console.log("continue at top");
2818
- if (cval & Node0) {
2819
- path.push([p, q + 1]);
2820
- d_x = 0;
2821
- d_y = 1;
2822
- d_o = 0;
2823
- //console.log("moving upwards to " + (p + d_x) + "," + (q + d_y) + "!");
2824
- } else {
2825
- /* */
2826
- console.log("MarchingSquaresJS-isoBands: wtf");
2827
- break;
2828
- }
2829
- }
2830
- } else if (d_x === 1) {
2831
- /* we came from left */
2832
- //console.log("we came from left and hit a non-existing cell " + (p + d_x) + "," + (q + d_y) + "!");
2833
- if (d_o === 0) {
2834
- /* exit bottom */
2835
- if (cval & Node2) {
2836
- path.push([p + 1, q]);
2837
- d_x = 0;
2838
- d_y = -1;
2839
- d_o = 1;
2840
- } else {
2841
- path.push([p + 1, q + cell.rightbottom]);
2842
- d_x = -1;
2843
- d_y = 0;
2844
- d_o = 0;
2845
- closed = true;
2846
- break;
2847
- }
2848
- } else {
2849
- /* exit top */
2850
- if (cval & Node2) {
2851
- path.push([p + 1, q]);
2852
- d_x = 0;
2853
- d_y = -1;
2854
- d_o = 1;
2855
- } else if (!(cval & Node1)) {
2856
- path.push([p + 1, q + cell.rightbottom]);
2857
- d_x = -1;
2858
- d_y = 0;
2859
- d_o = 0;
2860
- closed = true;
2861
- break;
2862
- } else {
2863
- path.push([p + 1, q + cell.righttop]);
2864
- d_x = -1;
2865
- d_y = 0;
2866
- d_o = 1;
2867
- break;
2868
- }
2869
- }
2870
- } else {
2871
- /* we came from the same cell */
2872
- console.log("MarchingSquaresJS-isoBands: we came from nowhere!");
2873
- break;
2874
- }
2875
- } else {
2876
- /* try to find an entry into the regular grid again! */
2877
- cell = grid.cells[q][p];
2878
- cval = cell.cval_real;
2879
- //console.log("which is defined");
2880
-
2881
- if (d_x === -1) {
2882
- if (d_o === 0) {
2883
- /* try to go downwards */
2884
- if (
2885
- typeof grid.cells[q - 1] !== "undefined" &&
2886
- typeof grid.cells[q - 1][p] !== "undefined"
2887
- ) {
2888
- d_x = 0;
2889
- d_y = -1;
2890
- d_o = 1;
2891
- } else if (cval & Node3) {
2892
- /* proceed searching in x-direction */
2893
- //console.log("proceeding in x-direction!");
2894
- path.push([p, q]);
2895
- } else {
2896
- /* we must have found an entry into the regular grid */
2897
- path.push([p + cell.bottomright, q]);
2898
- d_x = 0;
2899
- d_y = 1;
2900
- d_o = 1;
2901
- closed = true;
2902
- //console.log("found entry from bottom at " + p + "," + q);
2903
- break;
2904
- }
2905
- } else if (cval & Node0) {
2906
- /* proceed searchin in x-direction */
2907
- console.log("MarchingSquaresJS-isoBands: proceeding in x-direction!");
2908
- } else {
2909
- /* we must have found an entry into the regular grid */
2910
- console.log(
2911
- "MarchingSquaresJS-isoBands: found entry from top at " + p + "," + q
2912
- );
2913
- break;
2914
- }
2915
- } else if (d_x === 1) {
2916
- if (d_o === 0) {
2917
- console.log("MarchingSquaresJS-isoBands: wtf");
2918
- break;
2919
- } else {
2920
- /* try to go upwards */
2921
- if (
2922
- typeof grid.cells[q + 1] !== "undefined" &&
2923
- typeof grid.cells[q + 1][p] !== "undefined"
2924
- ) {
2925
- d_x = 0;
2926
- d_y = 1;
2927
- d_o = 0;
2928
- } else if (cval & Node1) {
2929
- path.push([p + 1, q + 1]);
2930
- d_x = 1;
2931
- d_y = 0;
2932
- d_o = 1;
2933
- } else {
2934
- /* found an entry point into regular grid! */
2935
- path.push([p + cell.topleft, q + 1]);
2936
- d_x = 0;
2937
- d_y = -1;
2938
- d_o = 0;
2939
- closed = true;
2940
- //console.log("found entry from bottom at " + p + "," + q);
2941
- break;
2942
- }
2943
- }
2944
- } else if (d_y === -1) {
2945
- if (d_o === 1) {
2946
- /* try to go right */
2947
- if (typeof grid.cells[q][p + 1] !== "undefined") {
2948
- d_x = 1;
2949
- d_y = 0;
2950
- d_o = 1;
2951
- } else if (cval & Node2) {
2952
- path.push([p + 1, q]);
2953
- d_x = 0;
2954
- d_y = -1;
2955
- d_o = 1;
2956
- } else {
2957
- /* found entry into regular grid! */
2958
- path.push([p + 1, q + cell.righttop]);
2959
- d_x = -1;
2960
- d_y = 0;
2961
- d_o = 1;
2962
- closed = true;
2963
- //console.log("found entry from top at " + p + "," + q);
2964
- break;
2965
- }
2966
- } else {
2967
- console.log("MarchingSquaresJS-isoBands: wtf");
2968
- break;
2969
- }
2970
- } else if (d_y === 1) {
2971
- if (d_o === 0) {
2972
- //console.log("we came from bottom left and proceed to the left");
2973
- /* try to go left */
2974
- if (typeof grid.cells[q][p - 1] !== "undefined") {
2975
- d_x = -1;
2976
- d_y = 0;
2977
- d_o = 0;
2978
- } else if (cval & Node0) {
2979
- path.push([p, q + 1]);
2980
- d_x = 0;
2981
- d_y = 1;
2982
- d_o = 0;
2983
- } else {
2984
- /* found an entry point into regular grid! */
2985
- path.push([p, q + cell.leftbottom]);
2986
- d_x = 1;
2987
- d_y = 0;
2988
- d_o = 0;
2989
- closed = true;
2990
- //console.log("found entry from bottom at " + p + "," + q);
2991
- break;
2992
- }
2993
- } else {
2994
- //console.log("we came from bottom right and proceed to the right");
2995
- console.log("MarchingSquaresJS-isoBands: wtf");
2996
- break;
2997
- }
2998
- } else {
2999
- console.log("MarchingSquaresJS-isoBands: where did we came from???");
3000
- break;
3001
- }
3002
- }
3003
-
3004
- p += d_x;
3005
- q += d_y;
3006
- //console.log("going on to " + p + "," + q + " via " + d_x + " " + d_y + " " + d_o);
3007
-
3008
- if (p === i && q === j) {
3009
- /* bail out, once we've closed a circle path */
3010
- break;
3011
- }
3012
- }
3013
-
3014
- //console.log("exit with " + p + "," + q + " " + d_x + " " + d_y + " " + d_o);
3015
- return { path: path, i: p, j: q, x: d_x, y: d_y, o: d_o };
3016
- }
3017
-
3018
- function deleteEdge(cell, edgeIdx) {
3019
- delete cell.edges[edgeIdx];
3020
- for (var k = edgeIdx + 1; k < cell.edges.length; k++) {
3021
- cell.edges[k - 1] = cell.edges[k];
3022
- }
3023
- cell.edges.pop();
3024
- }
3025
-
3026
- function getStartXY(cell) {
3027
- if (cell.edges.length > 0) {
3028
- var e = cell.edges[cell.edges.length - 1];
3029
- //console.log("starting with edge " + e);
3030
- var cval = cell.cval_real;
3031
- switch (e) {
3032
- case 0:
3033
- if (cval & Node1) {
3034
- /* node 1 within range */
3035
- return { p: [1, cell.righttop], x: -1, y: 0, o: 1 };
3036
- } else {
3037
- /* node 1 below or above threshold */
3038
- return { p: [cell.topleft, 1], x: 0, y: -1, o: 0 };
3039
- }
3040
- case 1:
3041
- if (cval & Node2) {
3042
- return { p: [cell.topleft, 1], x: 0, y: -1, o: 0 };
3043
- } else {
3044
- return { p: [1, cell.rightbottom], x: -1, y: 0, o: 0 };
3045
- }
3046
- case 2:
3047
- if (cval & Node2) {
3048
- return { p: [cell.bottomright, 0], x: 0, y: 1, o: 1 };
3049
- } else {
3050
- return { p: [cell.topleft, 1], x: 0, y: -1, o: 0 };
3051
- }
3052
- case 3:
3053
- if (cval & Node3) {
3054
- return { p: [cell.topleft, 1], x: 0, y: -1, o: 0 };
3055
- } else {
3056
- return { p: [cell.bottomleft, 0], x: 0, y: 1, o: 0 };
3057
- }
3058
- case 4:
3059
- if (cval & Node1) {
3060
- return { p: [1, cell.righttop], x: -1, y: 0, o: 1 };
3061
- } else {
3062
- return { p: [cell.topright, 1], x: 0, y: -1, o: 1 };
3063
- }
3064
- case 5:
3065
- if (cval & Node2) {
3066
- return { p: [cell.topright, 1], x: 0, y: -1, o: 1 };
3067
- } else {
3068
- return { p: [1, cell.rightbottom], x: -1, y: 0, o: 0 };
3069
- }
3070
- case 6:
3071
- if (cval & Node2) {
3072
- return { p: [cell.bottomright, 0], x: 0, y: 1, o: 1 };
3073
- } else {
3074
- return { p: [cell.topright, 1], x: 0, y: -1, o: 1 };
3075
- }
3076
- case 7:
3077
- if (cval & Node3) {
3078
- return { p: [cell.topright, 1], x: 0, y: -1, o: 1 };
3079
- } else {
3080
- return { p: [cell.bottomleft, 0], x: 0, y: 1, o: 0 };
3081
- }
3082
- case 8:
3083
- if (cval & Node2) {
3084
- return { p: [cell.bottomright, 0], x: 0, y: 1, o: 1 };
3085
- } else {
3086
- return { p: [1, cell.righttop], x: -1, y: 0, o: 1 };
3087
- }
3088
- case 9:
3089
- if (cval & Node3) {
3090
- return { p: [1, cell.righttop], x: -1, y: 0, o: 1 };
3091
- } else {
3092
- return { p: [cell.bottomleft, 0], x: 0, y: 1, o: 0 };
3093
- }
3094
- case 10:
3095
- if (cval & Node3) {
3096
- return { p: [0, cell.leftbottom], x: 1, y: 0, o: 0 };
3097
- } else {
3098
- return { p: [1, cell.righttop], x: -1, y: 0, o: 1 };
3099
- }
3100
- case 11:
3101
- if (cval & Node0) {
3102
- return { p: [1, cell.righttop], x: -1, y: 0, o: 1 };
3103
- } else {
3104
- return { p: [0, cell.lefttop], x: 1, y: 0, o: 1 };
3105
- }
3106
- case 12:
3107
- if (cval & Node2) {
3108
- return { p: [cell.bottomright, 0], x: 0, y: 1, o: 1 };
3109
- } else {
3110
- return { p: [1, cell.rightbottom], x: -1, y: 0, o: 0 };
3111
- }
3112
- case 13:
3113
- if (cval & Node3) {
3114
- return { p: [1, cell.rightbottom], x: -1, y: 0, o: 0 };
3115
- } else {
3116
- return { p: [cell.bottomleft, 0], x: 0, y: 1, o: 0 };
3117
- }
3118
- case 14:
3119
- if (cval & Node3) {
3120
- return { p: [0, cell.leftbottom], x: 1, y: 0, o: 0 };
3121
- } else {
3122
- return { p: [1, cell.rightbottom], x: -1, y: 0, o: 0 };
3123
- }
3124
- case 15:
3125
- if (cval & Node0) {
3126
- return { p: [1, cell.rightbottom], x: -1, y: 0, o: 0 };
3127
- } else {
3128
- return { p: [0, cell.lefttop], x: 1, y: 0, o: 1 };
3129
- }
3130
- case 16:
3131
- if (cval & Node2) {
3132
- return { p: [cell.bottomright, 0], x: 0, y: 1, o: 1 };
3133
- } else {
3134
- return { p: [0, cell.leftbottom], x: 1, y: 0, o: 0 };
3135
- }
3136
- case 17:
3137
- if (cval & Node0) {
3138
- return { p: [cell.bottomright, 0], x: 0, y: 1, o: 1 };
3139
- } else {
3140
- return { p: [0, cell.lefttop], x: 1, y: 0, o: 1 };
3141
- }
3142
- case 18:
3143
- if (cval & Node3) {
3144
- return { p: [0, cell.leftbottom], x: 1, y: 0, o: 0 };
3145
- } else {
3146
- return { p: [cell.bottomleft, 0], x: 0, y: 1, o: 0 };
3147
- }
3148
- case 19:
3149
- if (cval & Node0) {
3150
- return { p: [cell.bottomleft, 0], x: 0, y: 1, o: 0 };
3151
- } else {
3152
- return { p: [0, cell.lefttop], x: 1, y: 0, o: 1 };
3153
- }
3154
- case 20:
3155
- if (cval & Node0) {
3156
- return { p: [cell.topleft, 1], x: 0, y: -1, o: 0 };
3157
- } else {
3158
- return { p: [0, cell.leftbottom], x: 1, y: 0, o: 0 };
3159
- }
3160
- case 21:
3161
- if (cval & Node1) {
3162
- return { p: [0, cell.leftbottom], x: 1, y: 0, o: 0 };
3163
- } else {
3164
- return { p: [cell.topright, 1], x: 0, y: -1, o: 1 };
3165
- }
3166
- case 22:
3167
- if (cval & Node0) {
3168
- return { p: [cell.topleft, 1], x: 0, y: -1, o: 0 };
3169
- } else {
3170
- return { p: [0, cell.lefttop], x: 1, y: 0, o: 1 };
3171
- }
3172
- case 23:
3173
- if (cval & Node1) {
3174
- return { p: [0, cell.lefttop], x: 1, y: 0, o: 1 };
3175
- } else {
3176
- return { p: [cell.topright, 1], x: 0, y: -1, o: 1 };
3177
- }
3178
- default:
3179
- console.log("MarchingSquaresJS-isoBands: edge index out of range!");
3180
- console.log(cell);
3181
- break;
3182
- }
3183
- }
3184
-
3185
- return null;
3186
- }
3187
-
3188
- function getExitXY(cell, x, y, o) {
3189
- var e,
3190
- id_x,
3191
- d_x,
3192
- d_y,
3193
- cval = cell.cval;
3194
- var d_o;
3195
-
3196
- switch (x) {
3197
- case -1:
3198
- switch (o) {
3199
- case 0:
3200
- e = isoBandEdgeRB[cval];
3201
- d_x = isoBandNextXRB[cval];
3202
- d_y = isoBandNextYRB[cval];
3203
- d_o = isoBandNextORB[cval];
3204
- break;
3205
- default:
3206
- e = isoBandEdgeRT[cval];
3207
- d_x = isoBandNextXRT[cval];
3208
- d_y = isoBandNextYRT[cval];
3209
- d_o = isoBandNextORT[cval];
3210
- break;
3211
- }
3212
- break;
3213
- case 1:
3214
- switch (o) {
3215
- case 0:
3216
- e = isoBandEdgeLB[cval];
3217
- d_x = isoBandNextXLB[cval];
3218
- d_y = isoBandNextYLB[cval];
3219
- d_o = isoBandNextOLB[cval];
3220
- break;
3221
- default:
3222
- e = isoBandEdgeLT[cval];
3223
- d_x = isoBandNextXLT[cval];
3224
- d_y = isoBandNextYLT[cval];
3225
- d_o = isoBandNextOLT[cval];
3226
- break;
3227
- }
3228
- break;
3229
- default:
3230
- switch (y) {
3231
- case -1:
3232
- switch (o) {
3233
- case 0:
3234
- e = isoBandEdgeTL[cval];
3235
- d_x = isoBandNextXTL[cval];
3236
- d_y = isoBandNextYTL[cval];
3237
- d_o = isoBandNextOTL[cval];
3238
- break;
3239
- default:
3240
- e = isoBandEdgeTR[cval];
3241
- d_x = isoBandNextXTR[cval];
3242
- d_y = isoBandNextYTR[cval];
3243
- d_o = isoBandNextOTR[cval];
3244
- break;
3245
- }
3246
- break;
3247
- case 1:
3248
- switch (o) {
3249
- case 0:
3250
- e = isoBandEdgeBL[cval];
3251
- d_x = isoBandNextXBL[cval];
3252
- d_y = isoBandNextYBL[cval];
3253
- d_o = isoBandNextOBL[cval];
3254
- break;
3255
- default:
3256
- e = isoBandEdgeBR[cval];
3257
- d_x = isoBandNextXBR[cval];
3258
- d_y = isoBandNextYBR[cval];
3259
- d_o = isoBandNextOBR[cval];
3260
- break;
3261
- }
3262
- break;
3263
- default:
3264
- break;
3265
- }
3266
- break;
3267
- }
3268
-
3269
- id_x = cell.edges.indexOf(e);
3270
- if (typeof cell.edges[id_x] !== "undefined") {
3271
- deleteEdge(cell, id_x);
3272
- } else {
3273
- //console.log("wrong edges...");
3274
- //console.log(x + " " + y + " " + o);
3275
- //console.log(cell);
3276
- return null;
3277
- }
3278
-
3279
- cval = cell.cval_real;
3280
-
3281
- switch (e) {
3282
- case 0:
3283
- if (cval & Node1) {
3284
- /* node 1 within range */
3285
- x = cell.topleft;
3286
- y = 1;
3287
- } else {
3288
- /* node 1 below or above threshold */
3289
- x = 1;
3290
- y = cell.righttop;
3291
- }
3292
- break;
3293
- case 1:
3294
- if (cval & Node2) {
3295
- x = 1;
3296
- y = cell.rightbottom;
3297
- } else {
3298
- x = cell.topleft;
3299
- y = 1;
3300
- }
3301
- break;
3302
- case 2:
3303
- if (cval & Node2) {
3304
- x = cell.topleft;
3305
- y = 1;
3306
- } else {
3307
- x = cell.bottomright;
3308
- y = 0;
3309
- }
3310
- break;
3311
- case 3:
3312
- if (cval & Node3) {
3313
- x = cell.bottomleft;
3314
- y = 0;
3315
- } else {
3316
- x = cell.topleft;
3317
- y = 1;
3318
- }
3319
- break;
3320
- case 4:
3321
- if (cval & Node1) {
3322
- x = cell.topright;
3323
- y = 1;
3324
- } else {
3325
- x = 1;
3326
- y = cell.righttop;
3327
- }
3328
- break;
3329
- case 5:
3330
- if (cval & Node2) {
3331
- x = 1;
3332
- y = cell.rightbottom;
3333
- } else {
3334
- x = cell.topright;
3335
- y = 1;
3336
- }
3337
- break;
3338
- case 6:
3339
- if (cval & Node2) {
3340
- x = cell.topright;
3341
- y = 1;
3342
- } else {
3343
- x = cell.bottomright;
3344
- y = 0;
3345
- }
3346
- break;
3347
- case 7:
3348
- if (cval & Node3) {
3349
- x = cell.bottomleft;
3350
- y = 0;
3351
- } else {
3352
- x = cell.topright;
3353
- y = 1;
3354
- }
3355
- break;
3356
- case 8:
3357
- if (cval & Node2) {
3358
- x = 1;
3359
- y = cell.righttop;
3360
- } else {
3361
- x = cell.bottomright;
3362
- y = 0;
3363
- }
3364
- break;
3365
- case 9:
3366
- if (cval & Node3) {
3367
- x = cell.bottomleft;
3368
- y = 0;
3369
- } else {
3370
- x = 1;
3371
- y = cell.righttop;
3372
- }
3373
- break;
3374
- case 10:
3375
- if (cval & Node3) {
3376
- x = 1;
3377
- y = cell.righttop;
3378
- } else {
3379
- x = 0;
3380
- y = cell.leftbottom;
3381
- }
3382
- break;
3383
- case 11:
3384
- if (cval & Node0) {
3385
- x = 0;
3386
- y = cell.lefttop;
3387
- } else {
3388
- x = 1;
3389
- y = cell.righttop;
3390
- }
3391
- break;
3392
- case 12:
3393
- if (cval & Node2) {
3394
- x = 1;
3395
- y = cell.rightbottom;
3396
- } else {
3397
- x = cell.bottomright;
3398
- y = 0;
3399
- }
3400
- break;
3401
- case 13:
3402
- if (cval & Node3) {
3403
- x = cell.bottomleft;
3404
- y = 0;
3405
- } else {
3406
- x = 1;
3407
- y = cell.rightbottom;
3408
- }
3409
- break;
3410
- case 14:
3411
- if (cval & Node3) {
3412
- x = 1;
3413
- y = cell.rightbottom;
3414
- } else {
3415
- x = 0;
3416
- y = cell.leftbottom;
3417
- }
3418
- break;
3419
- case 15:
3420
- if (cval & Node0) {
3421
- x = 0;
3422
- y = cell.lefttop;
3423
- } else {
3424
- x = 1;
3425
- y = cell.rightbottom;
3426
- }
3427
- break;
3428
- case 16:
3429
- if (cval & Node2) {
3430
- x = 0;
3431
- y = cell.leftbottom;
3432
- } else {
3433
- x = cell.bottomright;
3434
- y = 0;
3435
- }
3436
- break;
3437
- case 17:
3438
- if (cval & Node0) {
3439
- x = 0;
3440
- y = cell.lefttop;
3441
- } else {
3442
- x = cell.bottomright;
3443
- y = 0;
3444
- }
3445
- break;
3446
- case 18:
3447
- if (cval & Node3) {
3448
- x = cell.bottomleft;
3449
- y = 0;
3450
- } else {
3451
- x = 0;
3452
- y = cell.leftbottom;
3453
- }
3454
- break;
3455
- case 19:
3456
- if (cval & Node0) {
3457
- x = 0;
3458
- y = cell.lefttop;
3459
- } else {
3460
- x = cell.bottomleft;
3461
- y = 0;
3462
- }
3463
- break;
3464
- case 20:
3465
- if (cval & Node0) {
3466
- x = 0;
3467
- y = cell.leftbottom;
3468
- } else {
3469
- x = cell.topleft;
3470
- y = 1;
3471
- }
3472
- break;
3473
- case 21:
3474
- if (cval & Node1) {
3475
- x = cell.topright;
3476
- y = 1;
3477
- } else {
3478
- x = 0;
3479
- y = cell.leftbottom;
3480
- }
3481
- break;
3482
- case 22:
3483
- if (cval & Node0) {
3484
- x = 0;
3485
- y = cell.lefttop;
3486
- } else {
3487
- x = cell.topleft;
3488
- y = 1;
3489
- }
3490
- break;
3491
- case 23:
3492
- if (cval & Node1) {
3493
- x = cell.topright;
3494
- y = 1;
3495
- } else {
3496
- x = 0;
3497
- y = cell.lefttop;
3498
- }
3499
- break;
3500
- default:
3501
- console.log("MarchingSquaresJS-isoBands: edge index out of range!");
3502
- console.log(cell);
3503
- return null;
3504
- }
3505
-
3506
- if (
3507
- typeof x === "undefined" ||
3508
- typeof y === "undefined" ||
3509
- typeof d_x === "undefined" ||
3510
- typeof d_y === "undefined" ||
3511
- typeof d_o === "undefined"
3512
- ) {
3513
- console.log("MarchingSquaresJS-isoBands: undefined value!");
3514
- console.log(cell);
3515
- console.log(x + " " + y + " " + d_x + " " + d_y + " " + d_o);
3516
- }
3517
- return { p: [x, y], x: d_x, y: d_y, o: d_o };
3518
- }
3519
-
3520
- function BandGrid2Areas(grid) {
3521
- var areas = [];
3522
- var area_idx = 0;
3523
-
3524
- grid.cells.forEach(function (g, j) {
3525
- g.forEach(function (gg, i) {
3526
- if (typeof gg !== "undefined") {
3527
- var a = polygon_table[gg.cval](gg);
3528
- if (typeof a === "object" && isArray(a)) {
3529
- if (typeof a[0] === "object" && isArray(a[0])) {
3530
- if (typeof a[0][0] === "object" && isArray(a[0][0])) {
3531
- a.forEach(function (aa) {
3532
- aa.forEach(function (aaa) {
3533
- aaa[0] += i;
3534
- aaa[1] += j;
3535
- });
3536
- areas[area_idx++] = aa;
3537
- });
3538
- } else {
3539
- a.forEach(function (aa) {
3540
- aa[0] += i;
3541
- aa[1] += j;
3542
- });
3543
- areas[area_idx++] = a;
3544
- }
3545
- } else {
3546
- console.log(
3547
- "MarchingSquaresJS-isoBands: bandcell polygon with malformed coordinates"
3548
- );
3549
- }
3550
- } else {
3551
- console.log(
3552
- "MarchingSquaresJS-isoBands: bandcell polygon with null coordinates"
3553
- );
3554
- }
3555
- }
3556
- });
3557
- });
3558
-
3559
- return areas;
3560
- }
3561
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const bbox_1 = tslib_1.__importDefault(require("@turf/bbox"));
5
+ const area_1 = tslib_1.__importDefault(require("@turf/area"));
6
+ const boolean_point_in_polygon_1 = tslib_1.__importDefault(require("@turf/boolean-point-in-polygon"));
7
+ const explode_1 = tslib_1.__importDefault(require("@turf/explode"));
8
+ const invariant_1 = require("@turf/invariant");
9
+ const helpers_1 = require("@turf/helpers");
10
+ const grid_to_matrix_1 = tslib_1.__importDefault(require("./lib/grid-to-matrix"));
11
+ const marchingsquares_isobands_1 = tslib_1.__importDefault(require("./lib/marchingsquares-isobands"));
3562
12
  /**
3563
13
  * Takes a square or rectangular grid {@link FeatureCollection} of {@link Point} features with z-values and an array of
3564
14
  * value breaks and generates filled contour isobands.
@@ -3573,45 +23,39 @@ function BandGrid2Areas(grid) {
3573
23
  * @returns {FeatureCollection<MultiPolygon>} a FeatureCollection of {@link MultiPolygon} features representing isobands
3574
24
  */
3575
25
  function isobands(pointGrid, breaks, options) {
3576
- // Optional parameters
3577
- options = options || {};
3578
- if (!helpers.isObject(options)) throw new Error("options is invalid");
3579
- var zProperty = options.zProperty || "elevation";
3580
- var commonProperties = options.commonProperties || {};
3581
- var breaksProperties = options.breaksProperties || [];
3582
-
3583
- // Validation
3584
- invariant.collectionOf(pointGrid, "Point", "Input must contain Points");
3585
- if (!breaks) throw new Error("breaks is required");
3586
- if (!Array.isArray(breaks)) throw new Error("breaks is not an Array");
3587
- if (!helpers.isObject(commonProperties))
3588
- throw new Error("commonProperties is not an Object");
3589
- if (!Array.isArray(breaksProperties))
3590
- throw new Error("breaksProperties is not an Array");
3591
-
3592
- // Isoband methods
3593
- var matrix = gridToMatrix(pointGrid, { zProperty: zProperty, flip: true });
3594
- var contours = createContourLines(matrix, breaks, zProperty);
3595
- contours = rescaleContours(contours, matrix, pointGrid);
3596
-
3597
- var multipolygons = contours.map(function (contour, index) {
3598
- if (breaksProperties[index] && !helpers.isObject(breaksProperties[index])) {
3599
- throw new Error("Each mappedProperty is required to be an Object");
3600
- }
3601
- // collect all properties
3602
- var contourProperties = objectAssign(
3603
- {},
3604
- commonProperties,
3605
- breaksProperties[index]
3606
- );
3607
- contourProperties[zProperty] = contour[zProperty];
3608
- var multiP = helpers.multiPolygon(contour.groupedRings, contourProperties);
3609
- return multiP;
3610
- });
3611
-
3612
- return helpers.featureCollection(multipolygons);
26
+ // Optional parameters
27
+ options = options || {};
28
+ if (!helpers_1.isObject(options))
29
+ throw new Error("options is invalid");
30
+ const zProperty = options.zProperty || "elevation";
31
+ const commonProperties = options.commonProperties || {};
32
+ const breaksProperties = options.breaksProperties || [];
33
+ // Validation
34
+ invariant_1.collectionOf(pointGrid, "Point", "Input must contain Points");
35
+ if (!breaks)
36
+ throw new Error("breaks is required");
37
+ if (!Array.isArray(breaks))
38
+ throw new Error("breaks is not an Array");
39
+ if (!helpers_1.isObject(commonProperties))
40
+ throw new Error("commonProperties is not an Object");
41
+ if (!Array.isArray(breaksProperties))
42
+ throw new Error("breaksProperties is not an Array");
43
+ // Isoband methods
44
+ const matrix = grid_to_matrix_1.default(pointGrid, { zProperty: zProperty, flip: true });
45
+ let contours = createContourLines(matrix, breaks, zProperty);
46
+ contours = rescaleContours(contours, matrix, pointGrid);
47
+ const multipolygons = contours.map((contour, index) => {
48
+ if (breaksProperties[index] && !helpers_1.isObject(breaksProperties[index])) {
49
+ throw new Error("Each mappedProperty is required to be an Object");
50
+ }
51
+ // collect all properties
52
+ const contourProperties = Object.assign(Object.assign({}, commonProperties), breaksProperties[index]);
53
+ contourProperties[zProperty] = contour[zProperty];
54
+ const multiP = helpers_1.multiPolygon(contour.groupedRings, contourProperties);
55
+ return multiP;
56
+ });
57
+ return helpers_1.featureCollection(multipolygons);
3613
58
  }
3614
-
3615
59
  /**
3616
60
  * Creates the contours lines (featuresCollection of polygon features) from the 2D data grid
3617
61
  *
@@ -3626,26 +70,24 @@ function isobands(pointGrid, breaks, options) {
3626
70
  * @returns {Array<any>} contours
3627
71
  */
3628
72
  function createContourLines(matrix, breaks, property) {
3629
- var contours = [];
3630
- for (var i = 1; i < breaks.length; i++) {
3631
- var lowerBand = +breaks[i - 1]; // make sure the breaks value is a number
3632
- var upperBand = +breaks[i];
3633
-
3634
- var isobandsCoords = isoBands(matrix, lowerBand, upperBand - lowerBand);
3635
- // as per GeoJson rules for creating a Polygon, make sure the first element
3636
- // in the array of LinearRings represents the exterior ring (i.e. biggest area),
3637
- // and any subsequent elements represent interior rings (i.e. smaller area);
3638
- // this avoids rendering issues of the MultiPolygons on the map
3639
- var nestedRings = orderByArea(isobandsCoords);
3640
- var groupedRings = groupNestedRings(nestedRings);
3641
- var obj = {};
3642
- obj["groupedRings"] = groupedRings;
3643
- obj[property] = lowerBand + "-" + upperBand;
3644
- contours.push(obj);
3645
- }
3646
- return contours;
73
+ const contours = [];
74
+ for (let i = 1; i < breaks.length; i++) {
75
+ const lowerBand = +breaks[i - 1]; // make sure the breaks value is a number
76
+ const upperBand = +breaks[i];
77
+ const isobandsCoords = marchingsquares_isobands_1.default(matrix, lowerBand, upperBand - lowerBand);
78
+ // as per GeoJson rules for creating a Polygon, make sure the first element
79
+ // in the array of LinearRings represents the exterior ring (i.e. biggest area),
80
+ // and any subsequent elements represent interior rings (i.e. smaller area);
81
+ // this avoids rendering issues of the MultiPolygons on the map
82
+ const nestedRings = orderByArea(isobandsCoords);
83
+ const groupedRings = groupNestedRings(nestedRings);
84
+ contours.push({
85
+ groupedRings: groupedRings,
86
+ [property]: lowerBand + "-" + upperBand,
87
+ });
88
+ }
89
+ return contours;
3647
90
  }
3648
-
3649
91
  /**
3650
92
  * Transform isobands of 2D grid to polygons for the map
3651
93
  *
@@ -3656,39 +98,34 @@ function createContourLines(matrix, breaks, property) {
3656
98
  * @returns {Array<any>} contours
3657
99
  */
3658
100
  function rescaleContours(contours, matrix, points) {
3659
- // get dimensions (on the map) of the original grid
3660
- var gridBbox = bbox(points); // [ minX, minY, maxX, maxY ]
3661
- var originalWidth = gridBbox[2] - gridBbox[0];
3662
- var originalHeigth = gridBbox[3] - gridBbox[1];
3663
-
3664
- // get origin, which is the first point of the last row on the rectangular data on the map
3665
- var x0 = gridBbox[0];
3666
- var y0 = gridBbox[1];
3667
- // get number of cells per side
3668
- var matrixWidth = matrix[0].length - 1;
3669
- var matrixHeight = matrix.length - 1;
3670
- // calculate the scaling factor between matrix and rectangular grid on the map
3671
- var scaleX = originalWidth / matrixWidth;
3672
- var scaleY = originalHeigth / matrixHeight;
3673
-
3674
- var resize = function (point) {
3675
- point[0] = point[0] * scaleX + x0;
3676
- point[1] = point[1] * scaleY + y0;
3677
- };
3678
-
3679
- // resize and shift each point/line of the isobands
3680
- contours.forEach(function (contour) {
3681
- contour.groupedRings.forEach(function (lineRingSet) {
3682
- lineRingSet.forEach(function (lineRing) {
3683
- lineRing.forEach(resize);
3684
- });
101
+ // get dimensions (on the map) of the original grid
102
+ const gridBbox = bbox_1.default(points); // [ minX, minY, maxX, maxY ]
103
+ const originalWidth = gridBbox[2] - gridBbox[0];
104
+ const originalHeigth = gridBbox[3] - gridBbox[1];
105
+ // get origin, which is the first point of the last row on the rectangular data on the map
106
+ const x0 = gridBbox[0];
107
+ const y0 = gridBbox[1];
108
+ // get number of cells per side
109
+ const matrixWidth = matrix[0].length - 1;
110
+ const matrixHeight = matrix.length - 1;
111
+ // calculate the scaling factor between matrix and rectangular grid on the map
112
+ const scaleX = originalWidth / matrixWidth;
113
+ const scaleY = originalHeigth / matrixHeight;
114
+ const resize = (point) => {
115
+ point[0] = point[0] * scaleX + x0;
116
+ point[1] = point[1] * scaleY + y0;
117
+ };
118
+ // resize and shift each point/line of the isobands
119
+ contours.forEach(function (contour) {
120
+ contour.groupedRings.forEach(function (lineRingSet) {
121
+ lineRingSet.forEach(function (lineRing) {
122
+ lineRing.forEach(resize);
123
+ });
124
+ });
3685
125
  });
3686
- });
3687
- return contours;
126
+ return contours;
3688
127
  }
3689
-
3690
128
  /* utility functions */
3691
-
3692
129
  /**
3693
130
  * Returns an array of coordinates (of LinearRings) in descending order by area
3694
131
  *
@@ -3697,34 +134,33 @@ function rescaleContours(contours, matrix, points) {
3697
134
  * @returns {Array} array of the input LineString ordered by area
3698
135
  */
3699
136
  function orderByArea(ringsCoords) {
3700
- var ringsWithArea = [];
3701
- var areas = [];
3702
- ringsCoords.forEach(function (coords) {
3703
- // var poly = polygon([points]);
3704
- var ringArea = area(helpers.polygon([coords]));
3705
- // create an array of areas value
3706
- areas.push(ringArea);
3707
- // associate each lineRing with its area
3708
- ringsWithArea.push({ ring: coords, area: ringArea });
3709
- });
3710
- areas.sort(function (a, b) {
3711
- // bigger --> smaller
3712
- return b - a;
3713
- });
3714
- // create a new array of linearRings coordinates ordered by their area
3715
- var orderedByArea = [];
3716
- areas.forEach(function (area$$1) {
3717
- for (var lr = 0; lr < ringsWithArea.length; lr++) {
3718
- if (ringsWithArea[lr].area === area$$1) {
3719
- orderedByArea.push(ringsWithArea[lr].ring);
3720
- ringsWithArea.splice(lr, 1);
3721
- break;
3722
- }
3723
- }
3724
- });
3725
- return orderedByArea;
137
+ const ringsWithArea = [];
138
+ const areas = [];
139
+ ringsCoords.forEach(function (coords) {
140
+ // const poly = polygon([points]);
141
+ const ringArea = area_1.default(helpers_1.polygon([coords]));
142
+ // create an array of areas value
143
+ areas.push(ringArea);
144
+ // associate each lineRing with its area
145
+ ringsWithArea.push({ ring: coords, area: ringArea });
146
+ });
147
+ areas.sort(function (a, b) {
148
+ // bigger --> smaller
149
+ return b - a;
150
+ });
151
+ // create a new array of linearRings coordinates ordered by their area
152
+ const orderedByArea = [];
153
+ areas.forEach(function (area) {
154
+ for (let lr = 0; lr < ringsWithArea.length; lr++) {
155
+ if (ringsWithArea[lr].area === area) {
156
+ orderedByArea.push(ringsWithArea[lr].ring);
157
+ ringsWithArea.splice(lr, 1);
158
+ break;
159
+ }
160
+ }
161
+ });
162
+ return orderedByArea;
3726
163
  }
3727
-
3728
164
  /**
3729
165
  * Returns an array of arrays of coordinates, each representing
3730
166
  * a set of (coordinates of) nested LinearRings,
@@ -3735,37 +171,36 @@ function orderByArea(ringsCoords) {
3735
171
  * @returns {Array<Array>} Array of coordinates of nested LinearRings
3736
172
  */
3737
173
  function groupNestedRings(orderedLinearRings) {
3738
- // create a list of the (coordinates of) LinearRings
3739
- var lrList = orderedLinearRings.map(function (lr) {
3740
- return { lrCoordinates: lr, grouped: false };
3741
- });
3742
- var groupedLinearRingsCoords = [];
3743
- while (!allGrouped(lrList)) {
3744
- for (var i = 0; i < lrList.length; i++) {
3745
- if (!lrList[i].grouped) {
3746
- // create new group starting with the larger not already grouped ring
3747
- var group = [];
3748
- group.push(lrList[i].lrCoordinates);
3749
- lrList[i].grouped = true;
3750
- var outerMostPoly = helpers.polygon([lrList[i].lrCoordinates]);
3751
- // group all the rings contained by the outermost ring
3752
- for (var j = i + 1; j < lrList.length; j++) {
3753
- if (!lrList[j].grouped) {
3754
- var lrPoly = helpers.polygon([lrList[j].lrCoordinates]);
3755
- if (isInside(lrPoly, outerMostPoly)) {
3756
- group.push(lrList[j].lrCoordinates);
3757
- lrList[j].grouped = true;
174
+ // create a list of the (coordinates of) LinearRings
175
+ const lrList = orderedLinearRings.map((lr) => {
176
+ return { lrCoordinates: lr, grouped: false };
177
+ });
178
+ const groupedLinearRingsCoords = [];
179
+ while (!allGrouped(lrList)) {
180
+ for (let i = 0; i < lrList.length; i++) {
181
+ if (!lrList[i].grouped) {
182
+ // create new group starting with the larger not already grouped ring
183
+ const group = [];
184
+ group.push(lrList[i].lrCoordinates);
185
+ lrList[i].grouped = true;
186
+ const outerMostPoly = helpers_1.polygon([lrList[i].lrCoordinates]);
187
+ // group all the rings contained by the outermost ring
188
+ for (let j = i + 1; j < lrList.length; j++) {
189
+ if (!lrList[j].grouped) {
190
+ const lrPoly = helpers_1.polygon([lrList[j].lrCoordinates]);
191
+ if (isInside(lrPoly, outerMostPoly)) {
192
+ group.push(lrList[j].lrCoordinates);
193
+ lrList[j].grouped = true;
194
+ }
195
+ }
196
+ }
197
+ // insert the new group
198
+ groupedLinearRingsCoords.push(group);
3758
199
  }
3759
- }
3760
200
  }
3761
- // insert the new group
3762
- groupedLinearRingsCoords.push(group);
3763
- }
3764
201
  }
3765
- }
3766
- return groupedLinearRingsCoords;
202
+ return groupedLinearRingsCoords;
3767
203
  }
3768
-
3769
204
  /**
3770
205
  * @private
3771
206
  * @param {Polygon} testPolygon polygon of interest
@@ -3773,27 +208,25 @@ function groupNestedRings(orderedLinearRings) {
3773
208
  * @returns {boolean} true if test-Polygon is inside target-Polygon
3774
209
  */
3775
210
  function isInside(testPolygon, targetPolygon) {
3776
- var points = explode(testPolygon);
3777
- for (var i = 0; i < points.features.length; i++) {
3778
- if (!booleanPointInPolygon(points.features[i], targetPolygon)) {
3779
- return false;
211
+ const points = explode_1.default(testPolygon);
212
+ for (let i = 0; i < points.features.length; i++) {
213
+ if (!boolean_point_in_polygon_1.default(points.features[i], targetPolygon)) {
214
+ return false;
215
+ }
3780
216
  }
3781
- }
3782
- return true;
217
+ return true;
3783
218
  }
3784
-
3785
219
  /**
3786
220
  * @private
3787
221
  * @param {Array<Object>} list list of objects which might contain the 'group' attribute
3788
222
  * @returns {boolean} true if all the objects in the list are marked as grouped
3789
223
  */
3790
224
  function allGrouped(list) {
3791
- for (var i = 0; i < list.length; i++) {
3792
- if (list[i].grouped === false) {
3793
- return false;
225
+ for (let i = 0; i < list.length; i++) {
226
+ if (list[i].grouped === false) {
227
+ return false;
228
+ }
3794
229
  }
3795
- }
3796
- return true;
230
+ return true;
3797
231
  }
3798
-
3799
- module.exports = isobands;
232
+ exports.default = isobands;