@deck.gl/aggregation-layers 8.8.0-beta.2 → 8.8.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/dist.dev.js +271 -261
  2. package/dist/es5/contour-layer/contour-layer.js.map +1 -1
  3. package/dist/es5/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
  4. package/dist/es5/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
  5. package/dist/es5/grid-layer/grid-layer.js.map +1 -1
  6. package/dist/es5/heatmap-layer/heatmap-layer.js +17 -12
  7. package/dist/es5/heatmap-layer/heatmap-layer.js.map +1 -1
  8. package/dist/es5/hexagon-layer/hexagon-layer.js.map +1 -1
  9. package/dist/es5/screen-grid-layer/screen-grid-layer.js.map +1 -1
  10. package/dist/esm/contour-layer/contour-layer.js.map +1 -1
  11. package/dist/esm/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
  12. package/dist/esm/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
  13. package/dist/esm/grid-layer/grid-layer.js.map +1 -1
  14. package/dist/esm/heatmap-layer/heatmap-layer.js +16 -12
  15. package/dist/esm/heatmap-layer/heatmap-layer.js.map +1 -1
  16. package/dist/esm/hexagon-layer/hexagon-layer.js.map +1 -1
  17. package/dist/esm/screen-grid-layer/screen-grid-layer.js.map +1 -1
  18. package/dist.min.js +1 -1
  19. package/package.json +2 -2
  20. package/src/contour-layer/contour-layer.ts +2 -0
  21. package/src/cpu-grid-layer/cpu-grid-layer.ts +1 -0
  22. package/src/gpu-grid-layer/gpu-grid-layer.ts +1 -3
  23. package/src/grid-layer/grid-layer.ts +1 -0
  24. package/src/heatmap-layer/heatmap-layer.ts +24 -12
  25. package/src/hexagon-layer/hexagon-layer.ts +1 -0
  26. package/src/screen-grid-layer/screen-grid-layer.ts +1 -0
  27. package/typed/contour-layer/contour-layer.d.ts +1 -0
  28. package/typed/contour-layer/contour-layer.d.ts.map +1 -1
  29. package/typed/cpu-grid-layer/cpu-grid-layer.d.ts +1 -0
  30. package/typed/cpu-grid-layer/cpu-grid-layer.d.ts.map +1 -1
  31. package/typed/gpu-grid-layer/gpu-grid-layer.d.ts +1 -3
  32. package/typed/gpu-grid-layer/gpu-grid-layer.d.ts.map +1 -1
  33. package/typed/grid-layer/grid-layer.d.ts +1 -0
  34. package/typed/grid-layer/grid-layer.d.ts.map +1 -1
  35. package/typed/heatmap-layer/heatmap-layer.d.ts +1 -0
  36. package/typed/heatmap-layer/heatmap-layer.d.ts.map +1 -1
  37. package/typed/hexagon-layer/hexagon-layer.d.ts +1 -0
  38. package/typed/hexagon-layer/hexagon-layer.d.ts.map +1 -1
  39. package/typed/screen-grid-layer/screen-grid-layer.d.ts +1 -0
  40. package/typed/screen-grid-layer/screen-grid-layer.d.ts.map +1 -1
  41. package/typed/utils/bin-sorter.d.ts +1 -1
  42. package/typed/aggregation-layer.js +0 -151
  43. package/typed/contour-layer/contour-layer.js +0 -234
  44. package/typed/contour-layer/contour-utils.js +0 -64
  45. package/typed/contour-layer/marching-squares-codes.js +0 -337
  46. package/typed/contour-layer/marching-squares.js +0 -147
  47. package/typed/cpu-grid-layer/cpu-grid-layer.js +0 -129
  48. package/typed/cpu-grid-layer/grid-aggregator.js +0 -141
  49. package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js +0 -34
  50. package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +0 -141
  51. package/typed/gpu-grid-layer/gpu-grid-cell-layer.js +0 -143
  52. package/typed/gpu-grid-layer/gpu-grid-layer.js +0 -289
  53. package/typed/grid-aggregation-layer.js +0 -172
  54. package/typed/grid-layer/grid-layer.js +0 -60
  55. package/typed/heatmap-layer/heatmap-layer-utils.js +0 -78
  56. package/typed/heatmap-layer/heatmap-layer.js +0 -478
  57. package/typed/heatmap-layer/max-fs.glsl.js +0 -7
  58. package/typed/heatmap-layer/max-vs.glsl.js +0 -12
  59. package/typed/heatmap-layer/triangle-layer-fragment.glsl.js +0 -58
  60. package/typed/heatmap-layer/triangle-layer-vertex.glsl.js +0 -51
  61. package/typed/heatmap-layer/triangle-layer.js +0 -67
  62. package/typed/heatmap-layer/weights-fs.glsl.js +0 -19
  63. package/typed/heatmap-layer/weights-vs.glsl.js +0 -23
  64. package/typed/hexagon-layer/hexagon-aggregator.js +0 -112
  65. package/typed/hexagon-layer/hexagon-layer.js +0 -171
  66. package/typed/index.js +0 -33
  67. package/typed/screen-grid-layer/screen-grid-cell-layer.js +0 -159
  68. package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.js +0 -37
  69. package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.js +0 -83
  70. package/typed/screen-grid-layer/screen-grid-layer.js +0 -216
  71. package/typed/types.js +0 -1
  72. package/typed/utils/aggregation-operation-utils.js +0 -94
  73. package/typed/utils/bin-sorter.js +0 -167
  74. package/typed/utils/color-utils.js +0 -53
  75. package/typed/utils/cpu-aggregator.js +0 -417
  76. package/typed/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.js +0 -39
  77. package/typed/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.js +0 -53
  78. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.js +0 -31
  79. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.js +0 -77
  80. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.js +0 -41
  81. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.js +0 -1
  82. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator.js +0 -562
  83. package/typed/utils/gpu-grid-aggregation/transform-mean-vs.glsl.js +0 -36
  84. package/typed/utils/grid-aggregation-utils.js +0 -114
  85. package/typed/utils/prop-utils.js +0 -28
  86. package/typed/utils/resource-utils.js +0 -40
  87. package/typed/utils/scale-utils.js +0 -184
@@ -1,234 +0,0 @@
1
- // Copyright (c) 2015 - 2018 Uber Technologies, Inc.
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy
4
- // of this software and associated documentation files (the "Software"), to deal
5
- // in the Software without restriction, including without limitation the rights
6
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- // copies of the Software, and to permit persons to whom the Software is
8
- // furnished to do so, subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in
11
- // all copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- // THE SOFTWARE.
20
- import GL from '@luma.gl/constants';
21
- import { LineLayer, SolidPolygonLayer } from '@deck.gl/layers';
22
- import { generateContours } from './contour-utils';
23
- import { log } from '@deck.gl/core';
24
- import GPUGridAggregator from '../utils/gpu-grid-aggregation/gpu-grid-aggregator';
25
- import { AGGREGATION_OPERATION, getValueFunc } from '../utils/aggregation-operation-utils';
26
- import { getBoundingBox, getGridParams } from '../utils/grid-aggregation-utils';
27
- import GridAggregationLayer from '../grid-aggregation-layer';
28
- const DEFAULT_COLOR = [255, 255, 255, 255];
29
- const DEFAULT_STROKE_WIDTH = 1;
30
- const DEFAULT_THRESHOLD = 1;
31
- const defaultProps = {
32
- // grid aggregation
33
- cellSize: { type: 'number', min: 1, max: 1000, value: 1000 },
34
- getPosition: { type: 'accessor', value: x => x.position },
35
- getWeight: { type: 'accessor', value: 1 },
36
- gpuAggregation: true,
37
- aggregation: 'SUM',
38
- // contour lines
39
- contours: [{ threshold: DEFAULT_THRESHOLD }],
40
- zOffset: 0.005
41
- };
42
- const POSITION_ATTRIBUTE_NAME = 'positions';
43
- const DIMENSIONS = {
44
- data: {
45
- props: ['cellSize']
46
- },
47
- weights: {
48
- props: ['aggregation'],
49
- accessors: ['getWeight']
50
- }
51
- };
52
- export default class ContourLayer extends GridAggregationLayer {
53
- initializeState() {
54
- super.initializeAggregationLayer({
55
- dimensions: DIMENSIONS
56
- });
57
- this.setState({
58
- contourData: {},
59
- projectPoints: false,
60
- weights: {
61
- count: {
62
- size: 1,
63
- operation: AGGREGATION_OPERATION.SUM
64
- }
65
- }
66
- });
67
- const attributeManager = this.getAttributeManager();
68
- attributeManager.add({
69
- [POSITION_ATTRIBUTE_NAME]: {
70
- size: 3,
71
- accessor: 'getPosition',
72
- type: GL.DOUBLE,
73
- fp64: this.use64bitPositions()
74
- },
75
- // this attribute is used in gpu aggregation path only
76
- count: { size: 3, accessor: 'getWeight' }
77
- });
78
- }
79
- updateState(opts) {
80
- super.updateState(opts);
81
- let contoursChanged = false;
82
- const { oldProps, props } = opts;
83
- const { aggregationDirty } = this.state;
84
- if (oldProps.contours !== props.contours || oldProps.zOffset !== props.zOffset) {
85
- contoursChanged = true;
86
- this._updateThresholdData(opts.props);
87
- }
88
- if (this.getNumInstances() > 0 && (aggregationDirty || contoursChanged)) {
89
- this._generateContours();
90
- }
91
- }
92
- renderLayers() {
93
- const { contourSegments, contourPolygons } = this.state.contourData;
94
- const LinesSubLayerClass = this.getSubLayerClass('lines', LineLayer);
95
- const BandsSubLayerClass = this.getSubLayerClass('bands', SolidPolygonLayer);
96
- // Contour lines layer
97
- const lineLayer = contourSegments &&
98
- contourSegments.length > 0 &&
99
- new LinesSubLayerClass(this.getSubLayerProps({
100
- id: 'lines'
101
- }), {
102
- data: this.state.contourData.contourSegments,
103
- getSourcePosition: d => d.start,
104
- getTargetPosition: d => d.end,
105
- getColor: d => d.contour.color || DEFAULT_COLOR,
106
- getWidth: d => d.contour.strokeWidth || DEFAULT_STROKE_WIDTH
107
- });
108
- // Contour bands layer
109
- const bandsLayer = contourPolygons &&
110
- contourPolygons.length > 0 &&
111
- new BandsSubLayerClass(this.getSubLayerProps({
112
- id: 'bands'
113
- }), {
114
- data: this.state.contourData.contourPolygons,
115
- getPolygon: d => d.vertices,
116
- getFillColor: d => d.contour.color || DEFAULT_COLOR
117
- });
118
- return [lineLayer, bandsLayer];
119
- }
120
- // Aggregation Overrides
121
- /* eslint-disable max-statements, complexity */
122
- updateAggregationState(opts) {
123
- const { props, oldProps } = opts;
124
- const { cellSize, coordinateSystem } = props;
125
- const { viewport } = this.context;
126
- const cellSizeChanged = oldProps.cellSize !== cellSize;
127
- let gpuAggregation = props.gpuAggregation;
128
- if (this.state.gpuAggregation !== props.gpuAggregation) {
129
- if (gpuAggregation && !GPUGridAggregator.isSupported(this.context.gl)) {
130
- log.warn('GPU Grid Aggregation not supported, falling back to CPU')();
131
- gpuAggregation = false;
132
- }
133
- }
134
- const gpuAggregationChanged = gpuAggregation !== this.state.gpuAggregation;
135
- this.setState({
136
- gpuAggregation
137
- });
138
- const { dimensions } = this.state;
139
- const positionsChanged = this.isAttributeChanged(POSITION_ATTRIBUTE_NAME);
140
- const { data, weights } = dimensions;
141
- let { boundingBox } = this.state;
142
- if (positionsChanged) {
143
- boundingBox = getBoundingBox(this.getAttributes(), this.getNumInstances());
144
- this.setState({ boundingBox });
145
- }
146
- if (positionsChanged || cellSizeChanged) {
147
- const { gridOffset, translation, width, height, numCol, numRow } = getGridParams(boundingBox, cellSize, viewport, coordinateSystem);
148
- this.allocateResources(numRow, numCol);
149
- this.setState({
150
- gridOffset,
151
- boundingBox,
152
- translation,
153
- posOffset: translation.slice(),
154
- gridOrigin: [-1 * translation[0], -1 * translation[1]],
155
- width,
156
- height,
157
- numCol,
158
- numRow
159
- });
160
- }
161
- const aggregationDataDirty = positionsChanged ||
162
- gpuAggregationChanged ||
163
- this.isAggregationDirty(opts, {
164
- dimension: data,
165
- compareAll: gpuAggregation // check for all (including extentions props) when using gpu aggregation
166
- });
167
- const aggregationWeightsDirty = this.isAggregationDirty(opts, {
168
- dimension: weights
169
- });
170
- if (aggregationWeightsDirty) {
171
- this._updateAccessors(opts);
172
- }
173
- if (aggregationDataDirty || aggregationWeightsDirty) {
174
- this._resetResults();
175
- }
176
- this.setState({
177
- aggregationDataDirty,
178
- aggregationWeightsDirty
179
- });
180
- }
181
- /* eslint-enable max-statements, complexity */
182
- // Private (Aggregation)
183
- _updateAccessors(opts) {
184
- const { getWeight, aggregation, data } = opts.props;
185
- const { count } = this.state.weights;
186
- if (count) {
187
- count.getWeight = getWeight;
188
- count.operation = AGGREGATION_OPERATION[aggregation];
189
- }
190
- this.setState({ getValue: getValueFunc(aggregation, getWeight, { data }) });
191
- }
192
- _resetResults() {
193
- const { count } = this.state.weights;
194
- if (count) {
195
- count.aggregationData = null;
196
- }
197
- }
198
- // Private (Contours)
199
- _generateContours() {
200
- const { numCol, numRow, gridOrigin, gridOffset, thresholdData } = this.state;
201
- const { count } = this.state.weights;
202
- let { aggregationData } = count;
203
- if (!aggregationData) {
204
- aggregationData = count.aggregationBuffer.getData();
205
- count.aggregationData = aggregationData;
206
- }
207
- const { cellWeights } = GPUGridAggregator.getCellData({ countsData: aggregationData });
208
- const contourData = generateContours({
209
- thresholdData,
210
- cellWeights,
211
- gridSize: [numCol, numRow],
212
- gridOrigin,
213
- cellSize: [gridOffset.xOffset, gridOffset.yOffset]
214
- });
215
- // contourData contains both iso-lines and iso-bands if requested.
216
- this.setState({ contourData });
217
- }
218
- _updateThresholdData(props) {
219
- const { contours, zOffset } = props;
220
- const count = contours.length;
221
- const thresholdData = new Array(count);
222
- for (let i = 0; i < count; i++) {
223
- const contour = contours[i];
224
- thresholdData[i] = {
225
- contour,
226
- zIndex: contour.zIndex || i,
227
- zOffset
228
- };
229
- }
230
- this.setState({ thresholdData });
231
- }
232
- }
233
- ContourLayer.layerName = 'ContourLayer';
234
- ContourLayer.defaultProps = defaultProps;
@@ -1,64 +0,0 @@
1
- import { getCode, getVertices, CONTOUR_TYPE } from './marching-squares';
2
- // Given all the cell weights, generates contours for each threshold.
3
- /* eslint-disable max-depth */
4
- export function generateContours({ thresholdData, cellWeights, gridSize, gridOrigin, cellSize }) {
5
- const contourSegments = [];
6
- const contourPolygons = [];
7
- const width = gridSize[0];
8
- const height = gridSize[1];
9
- let segmentIndex = 0;
10
- let polygonIndex = 0;
11
- for (const data of thresholdData) {
12
- const { contour } = data;
13
- const { threshold } = contour;
14
- for (let x = -1; x < width; x++) {
15
- for (let y = -1; y < height; y++) {
16
- // Get the MarchingSquares code based on neighbor cell weights.
17
- const { code, meanCode } = getCode({
18
- cellWeights,
19
- threshold,
20
- x,
21
- y,
22
- width,
23
- height
24
- });
25
- const opts = {
26
- type: CONTOUR_TYPE.ISO_BANDS,
27
- gridOrigin,
28
- cellSize,
29
- x,
30
- y,
31
- width,
32
- height,
33
- code,
34
- meanCode,
35
- thresholdData: data
36
- };
37
- if (Array.isArray(threshold)) {
38
- opts.type = CONTOUR_TYPE.ISO_BANDS;
39
- const polygons = getVertices(opts);
40
- for (const polygon of polygons) {
41
- contourPolygons[polygonIndex++] = {
42
- vertices: polygon,
43
- contour
44
- };
45
- }
46
- }
47
- else {
48
- // Get the intersection vertices based on MarchingSquares code.
49
- opts.type = CONTOUR_TYPE.ISO_LINES;
50
- const vertices = getVertices(opts);
51
- for (let i = 0; i < vertices.length; i += 2) {
52
- contourSegments[segmentIndex++] = {
53
- start: vertices[i],
54
- end: vertices[i + 1],
55
- contour
56
- };
57
- }
58
- }
59
- }
60
- }
61
- }
62
- return { contourSegments, contourPolygons };
63
- }
64
- /* eslint-enable max-depth */
@@ -1,337 +0,0 @@
1
- // Code to Offsets Map needed to implement Marching Squares algorithm
2
- // Ref: https://en.wikipedia.org/wiki/Marching_squares
3
- // Table to map code to the intersection offsets
4
- // All offsets are relative to the center of marching cell (which is top right corner of grid-cell, and center of marching-square)
5
- const HALF = 0.5;
6
- const ONE6TH = 1 / 6;
7
- const OFFSET = {
8
- N: [0, HALF],
9
- E: [HALF, 0],
10
- S: [0, -HALF],
11
- W: [-HALF, 0],
12
- // CORNERS
13
- NE: [HALF, HALF],
14
- NW: [-HALF, HALF],
15
- SE: [HALF, -HALF],
16
- SW: [-HALF, -HALF]
17
- };
18
- // NOTE: vertices are ordered in CCW direction, starting from NW corner
19
- // Triangles
20
- const SW_TRIANGLE = [OFFSET.W, OFFSET.SW, OFFSET.S];
21
- const SE_TRIANGLE = [OFFSET.S, OFFSET.SE, OFFSET.E];
22
- const NE_TRIANGLE = [OFFSET.E, OFFSET.NE, OFFSET.N];
23
- const NW_TRIANGLE = [OFFSET.NW, OFFSET.W, OFFSET.N];
24
- // Trapezoids
25
- const SW_TRAPEZOID = [
26
- [-HALF, ONE6TH],
27
- [-HALF, -ONE6TH],
28
- [-ONE6TH, -HALF],
29
- [ONE6TH, -HALF]
30
- ];
31
- const SE_TRAPEZOID = [
32
- [-ONE6TH, -HALF],
33
- [ONE6TH, -HALF],
34
- [HALF, -ONE6TH],
35
- [HALF, ONE6TH]
36
- ];
37
- const NE_TRAPEZOID = [
38
- [HALF, -ONE6TH],
39
- [HALF, ONE6TH],
40
- [ONE6TH, HALF],
41
- [-ONE6TH, HALF]
42
- ];
43
- const NW_TRAPEZOID = [
44
- [-HALF, ONE6TH],
45
- [-HALF, -ONE6TH],
46
- [ONE6TH, HALF],
47
- [-ONE6TH, HALF]
48
- ];
49
- // Rectangles
50
- const S_RECTANGLE = [OFFSET.W, OFFSET.SW, OFFSET.SE, OFFSET.E];
51
- const E_RECTANGLE = [OFFSET.S, OFFSET.SE, OFFSET.NE, OFFSET.N];
52
- const N_RECTANGLE = [OFFSET.NW, OFFSET.W, OFFSET.E, OFFSET.NE];
53
- const W_RECTANGLE = [OFFSET.NW, OFFSET.SW, OFFSET.S, OFFSET.N];
54
- const EW_RECTANGEL = [
55
- [-HALF, ONE6TH],
56
- [-HALF, -ONE6TH],
57
- [HALF, -ONE6TH],
58
- [HALF, ONE6TH]
59
- ];
60
- const SN_RECTANGEL = [
61
- [-ONE6TH, -HALF],
62
- [ONE6TH, -HALF],
63
- [ONE6TH, HALF],
64
- [-ONE6TH, HALF]
65
- ];
66
- // Square
67
- const SQUARE = [OFFSET.NW, OFFSET.SW, OFFSET.SE, OFFSET.NE];
68
- // Pentagons
69
- const SW_PENTAGON = [OFFSET.NW, OFFSET.SW, OFFSET.SE, OFFSET.E, OFFSET.N];
70
- const SE_PENTAGON = [OFFSET.W, OFFSET.SW, OFFSET.SE, OFFSET.NE, OFFSET.N];
71
- const NE_PENTAGON = [OFFSET.NW, OFFSET.W, OFFSET.S, OFFSET.SE, OFFSET.NE];
72
- const NW_PENTAGON = [OFFSET.NW, OFFSET.SW, OFFSET.S, OFFSET.E, OFFSET.NE];
73
- const NW_N_PENTAGON = [OFFSET.NW, OFFSET.W, [HALF, -ONE6TH], [HALF, ONE6TH], OFFSET.N];
74
- const NE_E_PENTAGON = [[-ONE6TH, -HALF], [ONE6TH, -HALF], OFFSET.E, OFFSET.NE, OFFSET.N];
75
- const SE_S_PENTAGON = [[-HALF, ONE6TH], [-HALF, -ONE6TH], OFFSET.S, OFFSET.SE, OFFSET.E];
76
- const SW_W_PENTAGON = [OFFSET.W, OFFSET.SW, OFFSET.S, [ONE6TH, HALF], [-ONE6TH, HALF]];
77
- const NW_W_PENTAGON = [OFFSET.NW, OFFSET.W, [-ONE6TH, -HALF], [ONE6TH, -HALF], OFFSET.N];
78
- const NE_N_PENTAGON = [[-HALF, ONE6TH], [-HALF, -ONE6TH], OFFSET.E, OFFSET.NE, OFFSET.N];
79
- const SE_E_PENTAGON = [OFFSET.S, OFFSET.SE, OFFSET.E, [ONE6TH, HALF], [-ONE6TH, HALF]];
80
- const SW_S_PENTAGON = [OFFSET.W, OFFSET.SW, OFFSET.S, [HALF, -ONE6TH], [HALF, ONE6TH]];
81
- // Hexagon
82
- const S_HEXAGON = [OFFSET.W, OFFSET.SW, OFFSET.SE, OFFSET.E, [ONE6TH, HALF], [-ONE6TH, HALF]];
83
- const E_HEXAGON = [[-HALF, ONE6TH], [-HALF, -ONE6TH], OFFSET.S, OFFSET.SE, OFFSET.NE, OFFSET.N];
84
- const N_HEXAGON = [OFFSET.NW, OFFSET.W, [-ONE6TH, -HALF], [ONE6TH, -HALF], OFFSET.E, OFFSET.NE];
85
- const W_HEXAGON = [OFFSET.NW, OFFSET.SW, OFFSET.S, [HALF, -ONE6TH], [HALF, ONE6TH], OFFSET.N];
86
- const SW_NE_HEXAGON = [OFFSET.W, OFFSET.SW, OFFSET.S, OFFSET.E, OFFSET.NE, OFFSET.N];
87
- const NW_SE_HEXAGON = [OFFSET.NW, OFFSET.W, OFFSET.S, OFFSET.SE, OFFSET.E, OFFSET.N];
88
- // Heptagon (7-sided)
89
- const NE_HEPTAGON = [
90
- [-HALF, ONE6TH],
91
- [-HALF, -ONE6TH],
92
- [-ONE6TH, -HALF],
93
- [ONE6TH, -HALF],
94
- OFFSET.E,
95
- OFFSET.NE,
96
- OFFSET.N
97
- ];
98
- const SW_HEPTAGON = [
99
- OFFSET.W,
100
- OFFSET.SW,
101
- OFFSET.S,
102
- [HALF, -ONE6TH],
103
- [HALF, ONE6TH],
104
- [ONE6TH, HALF],
105
- [-ONE6TH, HALF]
106
- ];
107
- const NW_HEPTAGON = [
108
- OFFSET.NW,
109
- OFFSET.W,
110
- [-ONE6TH, -HALF],
111
- [ONE6TH, -HALF],
112
- [HALF, -ONE6TH],
113
- [HALF, ONE6TH],
114
- OFFSET.N
115
- ];
116
- const SE_HEPTAGON = [
117
- [-HALF, ONE6TH],
118
- [-HALF, -ONE6TH],
119
- OFFSET.S,
120
- OFFSET.SE,
121
- OFFSET.E,
122
- [ONE6TH, HALF],
123
- [-ONE6TH, HALF]
124
- ];
125
- // Octagon
126
- const OCTAGON = [
127
- [-HALF, ONE6TH],
128
- [-HALF, -ONE6TH],
129
- [-ONE6TH, -HALF],
130
- [ONE6TH, -HALF],
131
- [HALF, -ONE6TH],
132
- [HALF, ONE6TH],
133
- [ONE6TH, HALF],
134
- [-ONE6TH, HALF]
135
- ];
136
- // Note: above wiki page invertes white/black dots for generating the code, we don't
137
- export const ISOLINES_CODE_OFFSET_MAP = {
138
- // key is equal to the code of 4 vertices (invert the code specified in wiki)
139
- // value can be an array or an Object
140
- // Array : [line] or [line, line], where each line is [start-point, end-point], and each point is [x, y]
141
- // Object : to handle saddle cases, whos output depends on mean value of all 4 corners
142
- // key: code of mean value (0 or 1)
143
- // value: Array , as above defines one or two line segments
144
- 0: [],
145
- 1: [[OFFSET.W, OFFSET.S]],
146
- 2: [[OFFSET.S, OFFSET.E]],
147
- 3: [[OFFSET.W, OFFSET.E]],
148
- 4: [[OFFSET.N, OFFSET.E]],
149
- 5: {
150
- 0: [
151
- [OFFSET.W, OFFSET.S],
152
- [OFFSET.N, OFFSET.E]
153
- ],
154
- 1: [
155
- [OFFSET.W, OFFSET.N],
156
- [OFFSET.S, OFFSET.E]
157
- ]
158
- },
159
- 6: [[OFFSET.N, OFFSET.S]],
160
- 7: [[OFFSET.W, OFFSET.N]],
161
- 8: [[OFFSET.W, OFFSET.N]],
162
- 9: [[OFFSET.N, OFFSET.S]],
163
- 10: {
164
- 0: [
165
- [OFFSET.W, OFFSET.N],
166
- [OFFSET.S, OFFSET.E]
167
- ],
168
- 1: [
169
- [OFFSET.W, OFFSET.S],
170
- [OFFSET.N, OFFSET.E]
171
- ]
172
- },
173
- 11: [[OFFSET.N, OFFSET.E]],
174
- 12: [[OFFSET.W, OFFSET.E]],
175
- 13: [[OFFSET.S, OFFSET.E]],
176
- 14: [[OFFSET.W, OFFSET.S]],
177
- 15: []
178
- };
179
- function ternaryToIndex(ternary) {
180
- return parseInt(ternary, 4);
181
- }
182
- export const ISOBANDS_CODE_OFFSET_MAP = {
183
- // Below list of cases, follow the same order as in above mentioned wiki page.
184
- // Each case has its code on first commented line // T,TR,R,C
185
- // where T: Top, TR: Top-right, R: Right and C: current, each will be either 0, 1 or 2
186
- // final code is binary representation of above code , where takes 2 digits
187
- // for example: code 2-2-2-1 => 10-10-10-01 => 10101001 => 169
188
- // no contours
189
- [ternaryToIndex('0000')]: [],
190
- [ternaryToIndex('2222')]: [],
191
- // single triangle
192
- [ternaryToIndex('2221')]: [SW_TRIANGLE],
193
- [ternaryToIndex('2212')]: [SE_TRIANGLE],
194
- [ternaryToIndex('2122')]: [NE_TRIANGLE],
195
- [ternaryToIndex('1222')]: [NW_TRIANGLE],
196
- [ternaryToIndex('0001')]: [SW_TRIANGLE],
197
- [ternaryToIndex('0010')]: [SE_TRIANGLE],
198
- [ternaryToIndex('0100')]: [NE_TRIANGLE],
199
- [ternaryToIndex('1000')]: [NW_TRIANGLE],
200
- // single trapezoid
201
- [ternaryToIndex('2220')]: [SW_TRAPEZOID],
202
- [ternaryToIndex('2202')]: [SE_TRAPEZOID],
203
- [ternaryToIndex('2022')]: [NE_TRAPEZOID],
204
- [ternaryToIndex('0222')]: [NW_TRAPEZOID],
205
- [ternaryToIndex('0002')]: [SW_TRAPEZOID],
206
- [ternaryToIndex('0020')]: [SE_TRAPEZOID],
207
- [ternaryToIndex('0200')]: [NE_TRAPEZOID],
208
- [ternaryToIndex('2000')]: [NW_TRAPEZOID],
209
- // single rectangle
210
- [ternaryToIndex('0011')]: [S_RECTANGLE],
211
- [ternaryToIndex('0110')]: [E_RECTANGLE],
212
- [ternaryToIndex('1100')]: [N_RECTANGLE],
213
- [ternaryToIndex('1001')]: [W_RECTANGLE],
214
- [ternaryToIndex('2211')]: [S_RECTANGLE],
215
- [ternaryToIndex('2112')]: [E_RECTANGLE],
216
- [ternaryToIndex('1122')]: [N_RECTANGLE],
217
- [ternaryToIndex('1221')]: [W_RECTANGLE],
218
- [ternaryToIndex('2200')]: [EW_RECTANGEL],
219
- [ternaryToIndex('2002')]: [SN_RECTANGEL],
220
- [ternaryToIndex('0022')]: [EW_RECTANGEL],
221
- [ternaryToIndex('0220')]: [SN_RECTANGEL],
222
- // single square
223
- // 1111
224
- [ternaryToIndex('1111')]: [SQUARE],
225
- // single pentagon
226
- [ternaryToIndex('1211')]: [SW_PENTAGON],
227
- [ternaryToIndex('2111')]: [SE_PENTAGON],
228
- [ternaryToIndex('1112')]: [NE_PENTAGON],
229
- [ternaryToIndex('1121')]: [NW_PENTAGON],
230
- [ternaryToIndex('1011')]: [SW_PENTAGON],
231
- [ternaryToIndex('0111')]: [SE_PENTAGON],
232
- [ternaryToIndex('1110')]: [NE_PENTAGON],
233
- [ternaryToIndex('1101')]: [NW_PENTAGON],
234
- [ternaryToIndex('1200')]: [NW_N_PENTAGON],
235
- [ternaryToIndex('0120')]: [NE_E_PENTAGON],
236
- [ternaryToIndex('0012')]: [SE_S_PENTAGON],
237
- [ternaryToIndex('2001')]: [SW_W_PENTAGON],
238
- [ternaryToIndex('1022')]: [NW_N_PENTAGON],
239
- [ternaryToIndex('2102')]: [NE_E_PENTAGON],
240
- [ternaryToIndex('2210')]: [SE_S_PENTAGON],
241
- [ternaryToIndex('0221')]: [SW_W_PENTAGON],
242
- [ternaryToIndex('1002')]: [NW_W_PENTAGON],
243
- [ternaryToIndex('2100')]: [NE_N_PENTAGON],
244
- [ternaryToIndex('0210')]: [SE_E_PENTAGON],
245
- [ternaryToIndex('0021')]: [SW_S_PENTAGON],
246
- [ternaryToIndex('1220')]: [NW_W_PENTAGON],
247
- [ternaryToIndex('0122')]: [NE_N_PENTAGON],
248
- [ternaryToIndex('2012')]: [SE_E_PENTAGON],
249
- [ternaryToIndex('2201')]: [SW_S_PENTAGON],
250
- // single hexagon
251
- [ternaryToIndex('0211')]: [S_HEXAGON],
252
- [ternaryToIndex('2110')]: [E_HEXAGON],
253
- [ternaryToIndex('1102')]: [N_HEXAGON],
254
- [ternaryToIndex('1021')]: [W_HEXAGON],
255
- [ternaryToIndex('2011')]: [S_HEXAGON],
256
- [ternaryToIndex('0112')]: [E_HEXAGON],
257
- [ternaryToIndex('1120')]: [N_HEXAGON],
258
- [ternaryToIndex('1201')]: [W_HEXAGON],
259
- [ternaryToIndex('2101')]: [SW_NE_HEXAGON],
260
- [ternaryToIndex('0121')]: [SW_NE_HEXAGON],
261
- [ternaryToIndex('1012')]: [NW_SE_HEXAGON],
262
- [ternaryToIndex('1210')]: [NW_SE_HEXAGON],
263
- // 6-sided polygons based on mean weight
264
- // NOTE: merges mean value codes for extreme changes (as per above Wiki doc)
265
- [ternaryToIndex('0101')]: {
266
- 0: [SW_TRIANGLE, NE_TRIANGLE],
267
- 1: [SW_NE_HEXAGON],
268
- 2: [SW_NE_HEXAGON]
269
- },
270
- [ternaryToIndex('1010')]: {
271
- 0: [NW_TRIANGLE, SE_TRIANGLE],
272
- 1: [NW_SE_HEXAGON],
273
- 2: [NW_SE_HEXAGON]
274
- },
275
- [ternaryToIndex('2121')]: {
276
- 0: [SW_NE_HEXAGON],
277
- 1: [SW_NE_HEXAGON],
278
- 2: [SW_TRIANGLE, NE_TRIANGLE]
279
- },
280
- [ternaryToIndex('1212')]: {
281
- 0: [NW_SE_HEXAGON],
282
- 1: [NW_SE_HEXAGON],
283
- 2: [NW_TRIANGLE, SE_TRIANGLE]
284
- },
285
- // 7-sided polygons based on mean weight
286
- [ternaryToIndex('2120')]: {
287
- 0: [NE_HEPTAGON],
288
- 1: [NE_HEPTAGON],
289
- 2: [SW_TRAPEZOID, NE_TRIANGLE]
290
- },
291
- [ternaryToIndex('2021')]: {
292
- 0: [SW_HEPTAGON],
293
- 1: [SW_HEPTAGON],
294
- 2: [SW_TRIANGLE, NE_TRAPEZOID]
295
- },
296
- [ternaryToIndex('1202')]: {
297
- 0: [NW_HEPTAGON],
298
- 1: [NW_HEPTAGON],
299
- 2: [NW_TRIANGLE, SE_TRAPEZOID]
300
- },
301
- [ternaryToIndex('0212')]: {
302
- 0: [SE_HEPTAGON],
303
- 1: [SE_HEPTAGON],
304
- 2: [SE_TRIANGLE, NW_TRAPEZOID]
305
- },
306
- [ternaryToIndex('0102')]: {
307
- 0: [SW_TRAPEZOID, NE_TRIANGLE],
308
- 1: [NE_HEPTAGON],
309
- 2: [NE_HEPTAGON]
310
- },
311
- [ternaryToIndex('0201')]: {
312
- 0: [SW_TRIANGLE, NE_TRAPEZOID],
313
- 1: [SW_HEPTAGON],
314
- 2: [SW_HEPTAGON]
315
- },
316
- [ternaryToIndex('1020')]: {
317
- 0: [NW_TRIANGLE, SE_TRAPEZOID],
318
- 1: [NW_HEPTAGON],
319
- 2: [NW_HEPTAGON]
320
- },
321
- [ternaryToIndex('2010')]: {
322
- 0: [SE_TRIANGLE, NW_TRAPEZOID],
323
- 1: [SE_HEPTAGON],
324
- 2: [SE_HEPTAGON]
325
- },
326
- // 8-sided polygons based on mean weight
327
- [ternaryToIndex('2020')]: {
328
- 0: [NW_TRAPEZOID, SE_TRAPEZOID],
329
- 1: [OCTAGON],
330
- 2: [SW_TRAPEZOID, NE_TRAPEZOID]
331
- },
332
- [ternaryToIndex('0202')]: {
333
- 0: [NE_TRAPEZOID, SW_TRAPEZOID],
334
- 1: [OCTAGON],
335
- 2: [NW_TRAPEZOID, SE_TRAPEZOID]
336
- }
337
- };