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

uber / deck.gl / 13945

20 Sep 2019 - 0:32 coverage decreased (-2.9%) to 79.802%
13945

Pull #3655

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Update layer.md
Pull Request #3655: Update pydeck layer docs

3399 of 4611 branches covered (73.72%)

Branch coverage included in aggregate %.

7024 of 8450 relevant lines covered (83.12%)

5682.28 hits per line

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

19.74
/modules/core/src/lib/attribute-transition-utils.js
1
import BaseAttribute from '../lib/base-attribute';
10×
2
import {padArray} from '../utils/array-utils';
3

4
const DEFAULT_TRANSITION_SETTINGS = {
1×
5
  interpolation: {
6
    duration: 0,
7
    easing: t => t
13×
8
  },
9
  spring: {
10
    stiffness: 0.05,
11
    damping: 0.5
12
  }
13
};
14

15
export function normalizeTransitionSettings(userSettings, layerSettings) {
16
  if (!userSettings) {
16×
17
    return null;
1×
18
  }
19
  if (Number.isFinite(userSettings)) {
15×
20
    userSettings = {duration: userSettings};
8×
21
  }
22
  userSettings.type = userSettings.type || 'interpolation';
15×
23
  return Object.assign(
15×
24
    {},
25
    DEFAULT_TRANSITION_SETTINGS[userSettings.type],
26
    layerSettings,
27
    userSettings
28
  );
29
}
30

31
// NOTE: NOT COPYING OVER OFFSET OR STRIDE HERE BECAUSE:
32
// (1) WE DON'T SUPPORT INTERLEAVED BUFFERS FOR TRANSITIONS
33
// (2) BUFFERS WITH OFFSETS ALWAYS CONTAIN VALUES OF THE SAME SIZE
34
// (3) THE OPERATIONS IN THE SHADER ARE PER-COMPONENT (addition and scaling)
35
export function getSourceBufferAttribute(gl, attribute) {
UNCOV
36
  const {size, value, normalized, constant} = attribute;
!
37
  // The Attribute we pass to Transform as a sourceBuffer must have {divisor: 0}
38
  // so we create a copy of the attribute (with divisor=0) to use when running
39
  // transform feedback
UNCOV
40
  if (constant) {
Branches [[3, 0], [3, 1]] missed. !
41
    // don't pass normalized here because the `value` from a normalized attribute is
42
    // already normalized
UNCOV
43
    return new BaseAttribute(gl, {constant, value, size});
!
44
  }
UNCOV
45
  const buffer = attribute.getBuffer();
!
UNCOV
46
  return new BaseAttribute(gl, {divisor: 0, constant, buffer, size, normalized});
!
47
}
48

49
export function getAttributeTypeFromSize(size) {
UNCOV
50
  switch (size) {
Branches [[4, 0], [4, 1], [4, 2], [4, 3], [4, 4]] missed. !
51
    case 1:
UNCOV
52
      return 'float';
!
53
    case 2:
UNCOV
54
      return 'vec2';
!
55
    case 3:
UNCOV
56
      return 'vec3';
!
57
    case 4:
UNCOV
58
      return 'vec4';
!
59
    default:
UNCOV
60
      throw new Error(`No defined attribute type for size "${size}"`);
!
61
  }
62
}
63

64
export function cycleBuffers(buffers) {
65
  buffers.push(buffers.shift());
!
66
}
67

68
export function getAttributeBufferLength(attribute, numInstances) {
69
  const {doublePrecision, userData, value, size} = attribute;
!
70
  const multiplier = doublePrecision ? 2 : 1;
Branches [[5, 0], [5, 1]] missed. !
71
  return (userData.noAlloc ? value.length : numInstances * size) * multiplier;
Branches [[6, 0], [6, 1]] missed. !
72
}
73

74
// This helper is used when transitioning attributes from a set of values in one buffer layout
75
// to a set of values in a different buffer layout. (Buffer layouts are used when attribute values
76
// within a buffer should be grouped for drawElements, like the Polygon layer.) For example, a
77
// buffer layout of [3, 4] might have data [A1, A2, A3, B1, B2, B3, B4]. If it needs to transition
78
// to a buffer layout of [4, 2], it should produce a buffer, using the transition setting's `enter`
79
// function, that looks like this: [A1, A2, A3, A4 (user `enter` fn), B1, B2, 0]. Note: the final
80
// 0 in this buffer is because we never shrink buffers, only grow them, for performance reasons.
81
export function padBuffer({
82
  buffer,
83
  numInstances,
84
  attribute,
85
  fromLength,
86
  fromBufferLayout,
87
  getData = x => x
Branches [[7, 0]] missed. !
88
}) {
89
  // TODO: move the precisionMultiplier logic to the attribute when retrieving
90
  // its `size` and `elementOffset`?
91
  const precisionMultiplier = attribute.doublePrecision ? 2 : 1;
Branches [[8, 0], [8, 1]] missed. !
92
  const size = attribute.size * precisionMultiplier;
!
93
  const offset = attribute.elementOffset * precisionMultiplier;
!
94
  const toBufferLayout = attribute.bufferLayout;
!
95
  const hasBufferLayout = fromBufferLayout && toBufferLayout;
Branches [[9, 0], [9, 1]] missed. !
96
  const toLength = getAttributeBufferLength(attribute, numInstances);
!
97

98
  // check if buffer needs to be padded
99
  if (!hasBufferLayout && fromLength >= toLength) {
Branches [[10, 0], [10, 1], [11, 0], [11, 1]] missed. !
100
    return;
!
101
  }
102

103
  const toData = attribute.constant ? attribute.getValue() : attribute.getBuffer().getData({});
Branches [[12, 0], [12, 1]] missed. !
104
  if (attribute.normalized) {
Branches [[13, 0], [13, 1]] missed. !
105
    const getter = getData;
!
106
    getData = (value, chunk) => attribute._normalizeConstant(getter(value, chunk));
!
107
  }
108

109
  const getMissingData = attribute.constant
Branches [[14, 0], [14, 1]] missed. !
110
    ? (i, chunk) => getData(toData, chunk)
!
111
    : (i, chunk) => getData(toData.subarray(i, i + size), chunk);
!
112

113
  const source = buffer.getData({length: fromLength});
!
114
  const data = new Float32Array(toLength);
!
115
  padArray({
!
116
    source,
117
    target: data,
118
    sourceLayout: fromBufferLayout,
119
    targetLayout: toBufferLayout,
120
    offset,
121
    size,
122
    getData: getMissingData
123
  });
124

125
  buffer.setData({data});
!
126
}
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