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

uber / deck.gl / 13127

29 Aug 2019 - 17:33 coverage increased (+2.5%) to 83.552%
13127

Pull #3507

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
update the component-wrapping-rfc.md
Pull Request #3507: update the component-wrapping-rfc.md

3393 of 4570 branches covered (74.25%)

Branch coverage included in aggregate %.

7066 of 7948 relevant lines covered (88.9%)

3403.06 hits per line

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

95.35
/modules/core/src/utils/tesselator.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
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. 1×
26

27
    this.typedArrayManager = defaultTypedArrayManager;
4×
28
    this.indexLayout = null;
1×
29
    this.bufferLayout = null;
1×
30
    this.vertexCount = 0;
1×
31
    this.instanceCount = 0;
1×
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;
32×
43
    this.getGeometry = getGeometry;
32×
44
    this.positionSize = positionFormat === 'XY' ? 2 : 3;
32×
45
    if (Array.isArray(dataChanged)) {
32×
46
      // is partial update
47
      for (const dataRange of dataChanged) {
32×
48
        this._rebuildGeometry(dataRange);
32×
49
      }
50
    } else {
51
      this._rebuildGeometry();
85×
52
    }
53
  }
54

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

59
  /* Subclass interface */
60

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

66
  // Returns the number of vertices in a geometry
67
  getGeometrySize(geometry) {
68
    throw new Error('Not implemented');
85×
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;
5×
79
    const {iterable, objectInfo} = createIterable(data, startRow, endRow);
5×
80
    for (const object of iterable) {
80×
81
      objectInfo.index++;
4×
UNCOV
82
      const geometry = getGeometry(object, objectInfo);
!
UNCOV
83
      visitor(geometry, objectInfo.index);
!
84
    }
85
  }
86

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

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

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

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

110
    // count instances
111
    let instanceCount = 0;
70×
112
    for (const count of bufferLayout) {
61×
113
      instanceCount += count;
61×
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];
3,867×
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);
70×
124

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

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

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

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

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