Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

uber / deck.gl / 14011

20 Sep 2019 - 23:54 coverage increased (+2.7%) to 82.999%
14011

Pull #3672

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
bump loaders.gl version
Pull Request #3672: Fix bugs in pre-bundled version

3393 of 4577 branches covered (74.13%)

Branch coverage included in aggregate %.

7157 of 8134 relevant lines covered (87.99%)

4305.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.44
/modules/layers/src/column-layer/column-layer.js
1
// Copyright (c) 2015 - 2017 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

21
import {Layer} from '@deck.gl/core';
22
import GL from '@luma.gl/constants';
23
import {Model, PhongMaterial} from '@luma.gl/core';
24
import ColumnGeometry from './column-geometry';
25
const defaultMaterial = new PhongMaterial();
1×
26

27
import vs from './column-layer-vertex.glsl';
28
import fs from './column-layer-fragment.glsl';
29

30
const DEFAULT_COLOR = [0, 0, 0, 255];
14×
31

32
const defaultProps = {
1×
33
  diskResolution: {type: 'number', min: 4, value: 20},
34
  vertices: null,
35
  radius: {type: 'number', min: 0, value: 1000},
36
  angle: {type: 'number', value: 0},
37
  offset: {type: 'array', value: [0, 0]},
38
  coverage: {type: 'number', min: 0, max: 1, value: 1},
39
  elevationScale: {type: 'number', min: 0, value: 1},
40

41
  lineWidthUnits: 'meters',
42
  lineWidthScale: 1,
43
  lineWidthMinPixels: 0,
44
  lineWidthMaxPixels: Number.MAX_SAFE_INTEGER,
45

46
  extruded: true,
47
  wireframe: false,
48
  filled: true,
49
  stroked: false,
50

51
  getPosition: {type: 'accessor', value: x => x.position},
1×
52
  getFillColor: {type: 'accessor', value: DEFAULT_COLOR},
53
  getLineColor: {type: 'accessor', value: DEFAULT_COLOR},
54
  getLineWidth: {type: 'accessor', value: 1},
55
  getElevation: {type: 'accessor', value: 1000},
56
  material: defaultMaterial,
57
  getColor: {deprecatedFor: ['getFillColor', 'getLineColor']}
58
};
59

60
export default class ColumnLayer extends Layer {
61
  getShaders() {
62
    return super.getShaders({vs, fs, modules: ['project32', 'gouraud-lighting', 'picking']});
1×
63
  }
64

65
  /**
66
   * DeckGL calls initializeState when GL context is available
67
   * Essentially a deferred constructor
68
   */
69
  initializeState() {
70
    const attributeManager = this.getAttributeManager();
1×
71
    /* eslint-disable max-len */
72
    attributeManager.addInstanced({
1×
73
      instancePositions: {
74
        size: 3,
75
        type: this.use64bitPositions() ? GL.DOUBLE : GL.FLOAT,
Branches [[0, 1]] missed.
76
        transition: true,
77
        accessor: 'getPosition'
78
      },
79
      instanceElevations: {
80
        size: 1,
81
        transition: true,
82
        accessor: 'getElevation'
83
      },
84
      instanceFillColors: {
85
        size: this.props.colorFormat.length,
86
        type: GL.UNSIGNED_BYTE,
87
        normalized: true,
88
        transition: true,
89
        accessor: 'getFillColor',
90
        defaultValue: DEFAULT_COLOR
91
      },
92
      instanceLineColors: {
93
        size: this.props.colorFormat.length,
94
        type: GL.UNSIGNED_BYTE,
95
        normalized: true,
96
        transition: true,
97
        accessor: 'getLineColor',
98
        defaultValue: DEFAULT_COLOR
99
      },
100
      instanceStrokeWidths: {
101
        size: 1,
102
        accessor: 'getLineWidth',
103
        transition: true
104
      }
105
    });
106
    /* eslint-enable max-len */
107
  }
108

109
  updateState({props, oldProps, changeFlags}) {
110
    super.updateState({props, oldProps, changeFlags});
1×
111

112
    const regenerateModels = changeFlags.extensionsChanged;
1×
113

114
    if (regenerateModels) {
1×
115
      const {gl} = this.context;
3×
116
      if (this.state.model) {
Branches [[2, 0]] missed. 1×
117
        this.state.model.delete();
2×
118
      }
119
      this.setState({model: this._getModel(gl)});
1×
120
      this.getAttributeManager().invalidateAll();
2×
121
    }
122

123
    if (
1×
124
      regenerateModels ||
125
      props.diskResolution !== oldProps.diskResolution ||
126
      props.vertices !== oldProps.vertices
127
    ) {
128
      this._updateGeometry(props);
1×
129
    }
130
  }
131

132
  getGeometry(diskResolution, vertices) {
133
    const geometry = new ColumnGeometry({
1×
134
      radius: 1,
135
      height: 2,
136
      vertices,
137
      nradial: diskResolution
138
    });
139

140
    let meanVertexDistance = 0;
2,857×
141
    if (vertices) {
16×
142
      for (let i = 0; i < diskResolution; i++) {
16×
143
        const p = vertices[i];
183×
144
        const d = Math.sqrt(p[0] * p[0] + p[1] * p[1]);
183×
145
        meanVertexDistance += d / diskResolution;
183×
146
      }
147
    } else {
148
      meanVertexDistance = 1;
16×
149
    }
150
    this.setState({
16×
151
      edgeDistance: Math.cos(Math.PI / diskResolution) * meanVertexDistance
152
    });
153

UNCOV
154
    return geometry;
!
155
  }
156

157
  _getModel(gl) {
158
    return new Model(
16×
159
      gl,
160
      Object.assign({}, this.getShaders(), {
161
        id: this.props.id,
162
        isInstanced: true
163
      })
164
    );
165
  }
166

167
  _updateGeometry({diskResolution, vertices}) {
168
    const geometry = this.getGeometry(diskResolution, vertices);
16×
169

170
    this.setState({
183×
171
      fillVertexCount: geometry.attributes.POSITION.value.length / 3,
172
      wireframeVertexCount: geometry.indices.value.length
173
    });
174

175
    this.state.model.setProps({geometry});
19×
176
  }
177

178
  draw({uniforms}) {
179
    const {viewport} = this.context;
12×
180
    const {
181
      lineWidthUnits,
182
      lineWidthScale,
183
      lineWidthMinPixels,
184
      lineWidthMaxPixels,
185

186
      elevationScale,
187
      extruded,
188
      filled,
189
      stroked,
190
      wireframe,
191
      offset,
192
      coverage,
193
      radius,
194
      angle
195
    } = this.props;
12×
196
    const {model, fillVertexCount, wireframeVertexCount, edgeDistance} = this.state;
12×
197

198
    const widthMultiplier =
199
      lineWidthUnits === 'pixels' ? viewport.distanceScales.metersPerPixel[2] : 1;
Branches [[6, 0]] missed. 2×
200

201
    model.setUniforms(
2×
202
      Object.assign({}, uniforms, {
203
        radius,
204
        angle: (angle / 180) * Math.PI,
205
        offset,
206
        extruded,
207
        coverage,
208
        elevationScale,
209
        edgeDistance,
210
        widthScale: lineWidthScale * widthMultiplier,
211
        widthMinPixels: lineWidthMinPixels,
212
        widthMaxPixels: lineWidthMaxPixels
213
      })
214
    );
215

216
    // When drawing 3d: draw wireframe first so it doesn't get occluded by depth test
217
    if (extruded && wireframe) {
12×
218
      model.setProps({isIndexed: true});
12×
219
      model
12×
220
        .setVertexCount(wireframeVertexCount)
221
        .setDrawMode(GL.LINES)
222
        .setUniforms({isStroke: true})
223
        .draw();
224
    }
225
    if (filled) {
10×
226
      model.setProps({isIndexed: false});
12×
227
      model
12×
228
        .setVertexCount(fillVertexCount)
229
        .setDrawMode(GL.TRIANGLE_STRIP)
230
        .setUniforms({isStroke: false})
231
        .draw();
232
    }
233
    // When drawing 2d: draw fill before stroke so that the outline is always on top
234
    if (!extruded && stroked) {
16×
235
      model.setProps({isIndexed: false});
19×
236
      // The width of the stroke is achieved by flattening the side of the cylinder.
237
      // Skip the last 1/3 of the vertices which is the top.
238
      model
19×
239
        .setVertexCount((fillVertexCount * 2) / 3)
240
        .setDrawMode(GL.TRIANGLE_STRIP)
241
        .setUniforms({isStroke: true})
242
        .draw();
243
    }
244
  }
245
}
246

247
ColumnLayer.layerName = 'ColumnLayer';
19×
248
ColumnLayer.defaultProps = defaultProps;
120×
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC