Skip to content

Commit

Permalink
type improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Jun 10, 2024
1 parent 2f790c7 commit 7984f42
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {WebGLBinSorter} from './webgl-bin-sorter';
import {WebGLAggregationTransform} from './webgl-aggregation-transform';
import {_deepEqual as deepEqual, log, BinaryAttribute} from '@deck.gl/core';

import type {Aggregator, AggregationProps} from '../aggregator';
import type {Aggregator, AggregationProps, AggregatedBin} from '../aggregator';
import type {Device, Buffer, BufferLayout, TypedArray} from '@luma.gl/core';
import type {ShaderModule} from '@luma.gl/shadertools';

/** Settings used to construct a new GPUAggregator */
export type GPUAggregatorSettings = {
/** Options used to construct a new GPUAggregator */
export type GPUAggregatorOptions = {
/** Size of bin IDs */
dimensions: 1 | 2;
/** How many properties to perform aggregation on */
Expand All @@ -32,7 +32,7 @@ export type GPUAggregatorSettings = {
defines?: Record<string, string | number | boolean>;
};

/** Options used to run GPU aggregation, can be changed at any time */
/** Props used to run GPU aggregation, can be changed at any time */
export type GPUAggregationProps = AggregationProps & {
/** Limits of binId defined for each dimension. Ids outside of the [start, end) are ignored.
*/
Expand Down Expand Up @@ -71,7 +71,7 @@ export class GPUAggregator implements Aggregator {
/** Step 2. (optional) calculate the min/max across all bins */
protected aggregationTransform: WebGLAggregationTransform;

constructor(device: Device, settings: GPUAggregatorSettings) {
constructor(device: Device, settings: GPUAggregatorOptions) {
this.device = device;
this.dimensions = settings.dimensions;
this.numChannels = settings.numChannels;
Expand Down Expand Up @@ -103,22 +103,15 @@ export class GPUAggregator implements Aggregator {
}

/** Returns the information for a given bin. */
getBin(index: number): {
/** The original id */
id: number | [number, number];
/** Aggregated values by channel */
value: number[];
/** Count of data points in this bin */
count: number;
} | null {
getBin(index: number): AggregatedBin | null {
if (index < 0 || index >= this.numBins) {
return null;
}
const {binIdRange} = this.props;
let id: number | [number, number];
let id: number[];

if (this.dimensions === 1) {
id = index + binIdRange[0][0];
id = [index + binIdRange[0][0]];
} else {
const [[x0, x1], [y0]] = binIdRange;
const width = x1 - x0;
Expand Down
2 changes: 1 addition & 1 deletion modules/aggregation-layers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ export type {ScreenGridLayerProps} from './screen-grid-layer/screen-grid-layer';

export type {
GPUAggregationProps,
GPUAggregatorSettings
GPUAggregatorOptions
} from './aggregation-layer-v9/gpu-aggregator/gpu-aggregator';
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,15 @@ test('GPUAggregator#1D', t => {
t.deepEqual(aggregator.getResultDomain(2), [1, 5], 'getResultDomain() - max education');

// Empty bin
t.deepEqual(aggregator.getBin(0), {id: 2, count: 0, value: [NaN, NaN, NaN]}, 'getBin() - empty');
t.deepEqual(
aggregator.getBin(0),
{id: [2], count: 0, value: [NaN, NaN, NaN]},
'getBin() - empty'
);
// {age: 40, household: 4, income: 140, education: 4},
// {age: 42, household: 2, income: 110, education: 5},
// {age: 44, household: 4, income: 500, education: 4},
t.deepEqual(aggregator.getBin(6), {id: 8, count: 3, value: [3, 250, 5]}, 'getBin()');
t.deepEqual(aggregator.getBin(6), {id: [8], count: 3, value: [3, 250, 5]}, 'getBin()');

attributes.age.delete();
attributes.income.delete();
Expand Down

0 comments on commit 7984f42

Please sign in to comment.