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

uber / deck.gl / 13074

28 Aug 2019 - 0:36 coverage decreased (-2.5%) to 80.994%
13074

Pull #3496

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
use timeline
Pull Request #3496: Transition system refactor (1/2): use timeline

3394 of 4574 branches covered (74.2%)

Branch coverage included in aggregate %.

54 of 58 new or added lines in 9 files covered. (93.1%)

818 existing lines in 101 files now uncovered.

6953 of 8201 relevant lines covered (84.78%)

4628.87 hits per line

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

95.4
/modules/core/src/utils/tesselator.js
1
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
4×
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 {createIterable} from './iterable-utils';
21
import defaultTypedArrayManager from './typed-array-manager';
22

23
export default class Tesselator {
24
  constructor(opts = {}) {
Branches [[0, 0]] missed.
25
    const {attributes = {}} = opts;
Branches [[1, 0]] missed. 32×
26

27
    this.typedArrayManager = defaultTypedArrayManager;
32×
28
    this.indexLayout = null;
32×
29
    this.bufferLayout = null;
32×
30
    this.vertexCount = 0;
32×
31
    this.instanceCount = 0;
32×
32
    this.attributes = {};
32×
33
    this._attributeDefs = attributes;
32×
34

35
    this.updateGeometry(opts);
32×
36

37
    Object.seal(this);
32×
38
  }
39

40
  /* Public methods */
41
  updateGeometry({data, getGeometry, positionFormat, dataChanged}) {
42
    this.data = data;
85×
43
    this.getGeometry = getGeometry;
85×
44
    this.positionSize = positionFormat === 'XY' ? 2 : 3;
85×
45
    if (Array.isArray(dataChanged)) {
85×
46
      // is partial update
47
      for (const dataRange of dataChanged) {
5×
48
        this._rebuildGeometry(dataRange);
5×
49
      }
50
    } else {
51
      this._rebuildGeometry();
80×
52
    }
53
  }
54

55
  updatePartialGeometry({startRow, endRow}) {
56
    this._rebuildGeometry({startRow, endRow});
4×
57
  }
58

59
  /* Subclass interface */
60

61
  // Update the positions of a single geometry
62
  updateGeometryAttributes(geometry, startIndex, size) {
UNCOV
63
    throw new Error('Not implemented');
!
64
  }
65

66
  // Returns the number of vertices in a geometry
67
  getGeometrySize(geometry) {
UNCOV
68
    throw new Error('Not implemented');
!
69
  }
70

71
  /* Private utility methods */
72

73
  /**
74
   * Visit all objects
75
   * `data` is expected to be an iterable consistent with the base Layer expectation
76
   */
77
  _forEachGeometry(visitor, startRow, endRow) {
78
    const {data, getGeometry} = this;
140×
79
    const {iterable, objectInfo} = createIterable(data, startRow, endRow);
140×
80
    for (const object of iterable) {
140×
81
      objectInfo.index++;
7,734×
82
      const geometry = getGeometry(object, objectInfo);
7,734×
83
      visitor(geometry, objectInfo.index);
7,734×
84
    }
85
  }
86

87
  /* eslint-disable complexity,max-statements */
88
  _rebuildGeometry(dataRange) {
89
    if (!this.data || !this.getGeometry) {
89×
90
      return;
19×
91
    }
92

93
    let {indexLayout, bufferLayout} = this;
70×
94

95
    if (!dataRange) {
70×
96
      // Full update - regenerate buffer layout from scratch
97
      indexLayout = [];
61×
98
      bufferLayout = [];
61×
99
    }
100

101
    const {startRow = 0, endRow = Infinity} = dataRange || {};
70×
102
    this._forEachGeometry(
70×
103
      (geometry, dataIndex) => {
104
        bufferLayout[dataIndex] = this.getGeometrySize(geometry);
3,867×
105
      },
106
      startRow,
107
      endRow
108
    );
109

110
    // count instances
111
    let instanceCount = 0;
70×
112
    for (const count of bufferLayout) {
70×
113
      instanceCount += count;
3,961×
114
    }
115

116
    // allocate attributes
117
    const {attributes, _attributeDefs, typedArrayManager, fp64} = this;
70×
118
    for (const name in _attributeDefs) {
70×
119
      const def = _attributeDefs[name];
278×
120
      // If dataRange is supplied, this is a partial update.
121
      // In case we need to reallocate the typed array, it will need the old values copied
122
      // before performing partial update.
123
      def.copy = Boolean(dataRange);
278×
124

125
      // do not create fp64-only attributes unless in fp64 mode
126
      if (!def.fp64Only || fp64) {
278×
127
        attributes[name] = typedArrayManager.allocate(attributes[name], instanceCount, def);
210×
128
      }
129
    }
130

131
    this.indexLayout = indexLayout;
70×
132
    this.bufferLayout = bufferLayout;
70×
133
    this.instanceCount = instanceCount;
70×
134

135
    const context = {
70×
136
      vertexStart: 0,
137
      indexStart: 0
138
    };
139
    for (let i = 0; i < startRow; i++) {
70×
140
      context.vertexStart += bufferLayout[i];
4×
141
      context.indexStart += indexLayout[i] || 0;
4×
142
    }
143

144
    this._forEachGeometry(
70×
145
      (geometry, dataIndex) => {
146
        const geometrySize = bufferLayout[dataIndex];
3,867×
147
        context.geometryIndex = dataIndex;
3,867×
148
        context.geometrySize = geometrySize;
3,867×
149
        this.updateGeometryAttributes(geometry, context);
3,867×
150
        context.vertexStart += geometrySize;
3,867×
151
        context.indexStart += indexLayout[dataIndex] || 0;
3,867×
152
      },
153
      startRow,
154
      endRow
155
    );
156

157
    // count vertices
158
    let vertexCount = context.indexStart;
70×
159
    for (let i = endRow; i < indexLayout.length; i++) {
70×
160
      vertexCount += indexLayout[i];
25×
161
    }
162
    this.vertexCount = vertexCount;
70×
163
  }
164
}
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