UNPKG

@deck.gl/core

Version:

deck.gl core library

78 lines 2.56 kB
// deck.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors /* * Helper function for padArray */ function padArrayChunk(options) { const { source, target, start = 0, size, getData } = options; const end = options.end || target.length; const sourceLength = source.length; const targetLength = end - start; if (sourceLength > targetLength) { target.set(source.subarray(0, targetLength), start); return; } target.set(source, start); if (!getData) { return; } // source is not large enough to fill target space, call `getData` to get filler data let i = sourceLength; while (i < targetLength) { const datum = getData(i, source); for (let j = 0; j < size; j++) { target[start + i] = datum[j] || 0; i++; } } } /* * The padArray function stretches a source array to the size of a target array. The arrays can have internal structures (like the attributes of PathLayer and SolidPolygonLayer), defined by the optional sourceStartIndices and targetStartIndices parameters. If the target array is larger, the getData callback is used to fill in the blanks. */ export function padArray({ source, target, size, getData, sourceStartIndices, targetStartIndices }) { if (!sourceStartIndices || !targetStartIndices) { // Flat arrays padArrayChunk({ source, target, size, getData }); return target; } // Arrays have internal structure let sourceIndex = 0; let targetIndex = 0; const getChunkData = getData && ((i, chunk) => getData(i + targetIndex, chunk)); const n = Math.min(sourceStartIndices.length, targetStartIndices.length); for (let i = 1; i < n; i++) { const nextSourceIndex = sourceStartIndices[i] * size; const nextTargetIndex = targetStartIndices[i] * size; padArrayChunk({ source: source.subarray(sourceIndex, nextSourceIndex), target, start: targetIndex, end: nextTargetIndex, size, getData: getChunkData }); sourceIndex = nextSourceIndex; targetIndex = nextTargetIndex; } if (targetIndex < target.length) { padArrayChunk({ // @ts-ignore source: [], target, start: targetIndex, size, getData: getChunkData }); } return target; } //# sourceMappingURL=array-utils.js.map