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