Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Typescript: minor fixes #241

Merged
merged 2 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/data/bucket/circle_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> implement

populate(features: Array<IndexedFeature>, options: PopulateParameters, canonical: CanonicalTileID) {
const styleLayer = this.layers[0];
const bucketFeatures = [];
const bucketFeatures: BucketFeature[] = [];
let circleSortKey = null;
let sortFeaturesByKey = false;

// Heatmap layers are handled in this bucket and have no evaluated properties, so we check our access
if (styleLayer.type === 'circle') {
circleSortKey = (styleLayer as any as CircleStyleLayer).layout.get('circle-sort-key');
circleSortKey = (styleLayer as CircleStyleLayer).layout.get('circle-sort-key');
sortFeaturesByKey = !circleSortKey.isConstant();
}

Expand All @@ -94,7 +94,6 @@ class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> implement
if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom), evaluationFeature, canonical)) continue;

const sortKey = sortFeaturesByKey ?
// $FlowFixMe
circleSortKey.evaluate(evaluationFeature, {}, canonical) :
undefined;

Expand All @@ -116,7 +115,7 @@ class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> implement
if (sortFeaturesByKey) {
bucketFeatures.sort((a, b) => {
// a.sortKey is always a number when in use
return (a.sortKey as any as number) - (b.sortKey as any as number);
return (a.sortKey) - (b.sortKey);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize I can remove the parens.. will cleanup some other stuff and add to this PR

Copy link
Contributor Author

@chippieTV chippieTV Aug 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you ok with

if (sortFeaturesByKey) bucketFeatures.sort((a, b) => a.sortKey - b.sortKey);

or you prefer to keep it

if (sortFeaturesByKey) {
    bucketFeatures.sort((a, b) => {
        return a.sortKey - b.sortKey;
    });
}

not sure the line between types only and cleaning up syntax.. maybe it's less consistent

});
}

Expand Down
5 changes: 2 additions & 3 deletions src/data/bucket/fill_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class FillBucket implements Bucket {
this.hasPattern = hasPattern('fill', this.layers, options);
const fillSortKey = this.layers[0].layout.get('fill-sort-key');
const sortFeaturesByKey = !fillSortKey.isConstant();
const bucketFeatures = [];
const bucketFeatures: BucketFeature[] = [];

for (const {feature, id, index, sourceLayerIndex} of features) {
const needGeometry = this.layers[0]._featureFilter.needGeometry;
Expand Down Expand Up @@ -105,8 +105,7 @@ class FillBucket implements Bucket {

if (sortFeaturesByKey) {
bucketFeatures.sort((a, b) => {
// a.sortKey is always a number when in use
return (a.sortKey as any as number) - (b.sortKey as any as number);
return (a.sortKey) - (b.sortKey);
});
}

Expand Down
11 changes: 5 additions & 6 deletions src/data/bucket/line_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type LineClips = {

type GradientTexture = {
texture: Texture,
gradient: RGBAImage | undefined | null,
gradient?: RGBAImage,
version: number
};

Expand All @@ -88,7 +88,7 @@ class LineBucket implements Bucket {
totalDistance: number;
maxLineLength: number;
scaledDistance: number;
lineClips: LineClips | undefined | null;
lineClips?: LineClips;

e1: number;
e2: number;
Expand Down Expand Up @@ -147,7 +147,7 @@ class LineBucket implements Bucket {
this.hasPattern = hasPattern('line', this.layers, options);
const lineSortKey = this.layers[0].layout.get('line-sort-key');
const sortFeaturesByKey = !lineSortKey.isConstant();
const bucketFeatures = [];
const bucketFeatures: BucketFeature[] = [];

for (const {feature, id, index, sourceLayerIndex} of features) {
const needGeometry = this.layers[0]._featureFilter.needGeometry;
Expand Down Expand Up @@ -175,8 +175,7 @@ class LineBucket implements Bucket {

if (sortFeaturesByKey) {
bucketFeatures.sort((a, b) => {
// a.sortKey is always a number when in use
return (a.sortKey as any as number) - (b.sortKey as any as number);
return (a.sortKey) - (b.sortKey);
});
}

Expand Down Expand Up @@ -240,7 +239,7 @@ class LineBucket implements Bucket {
this.segments.destroy();
}

lineFeatureClips(feature: BucketFeature): LineClips | undefined | null {
lineFeatureClips(feature: BucketFeature): LineClips | undefined {
if (!!feature.properties && Object.prototype.hasOwnProperty.call(feature.properties, 'mapbox_clip_start') && Object.prototype.hasOwnProperty.call(feature.properties, 'mapbox_clip_end')) {
const start = +feature.properties['mapbox_clip_start'];
const end = +feature.properties['mapbox_clip_end'];
Expand Down
12 changes: 6 additions & 6 deletions src/data/bucket/symbol_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ class SymbolBucket implements Bucket {
if (this.sortFeaturesByKey) {
this.features.sort((a, b) => {
// a.sortKey is always a number when sortFeaturesByKey is true
return (a.sortKey as any as number) - (b.sortKey as any as number);
return (a.sortKey as number) - (b.sortKey as number);
});
}
}
Expand Down Expand Up @@ -720,7 +720,7 @@ class SymbolBucket implements Bucket {

addDebugCollisionBoxes(startIndex: number, endIndex: number, symbolInstance: SymbolInstance, isText: boolean) {
for (let b = startIndex; b < endIndex; b++) {
const box: CollisionBox = (this.collisionBoxArray.get(b) as any);
const box: CollisionBox = this.collisionBoxArray.get(b);
const x1 = box.x1;
const y1 = box.y1;
const x2 = box.x2;
Expand Down Expand Up @@ -765,27 +765,27 @@ class SymbolBucket implements Bucket {

const collisionArrays = {} as CollisionArrays;
for (let k = textStartIndex; k < textEndIndex; k++) {
const box: CollisionBox = (collisionBoxArray.get(k) as any);
const box: CollisionBox = collisionBoxArray.get(k);
collisionArrays.textBox = {x1: box.x1, y1: box.y1, x2: box.x2, y2: box.y2, anchorPointX: box.anchorPointX, anchorPointY: box.anchorPointY};
collisionArrays.textFeatureIndex = box.featureIndex;
break; // Only one box allowed per instance
}
for (let k = verticalTextStartIndex; k < verticalTextEndIndex; k++) {
const box: CollisionBox = (collisionBoxArray.get(k) as any);
const box: CollisionBox = collisionBoxArray.get(k);
collisionArrays.verticalTextBox = {x1: box.x1, y1: box.y1, x2: box.x2, y2: box.y2, anchorPointX: box.anchorPointX, anchorPointY: box.anchorPointY};
collisionArrays.verticalTextFeatureIndex = box.featureIndex;
break; // Only one box allowed per instance
}
for (let k = iconStartIndex; k < iconEndIndex; k++) {
// An icon can only have one box now, so this indexing is a bit vestigial...
const box: CollisionBox = (collisionBoxArray.get(k) as any);
const box: CollisionBox = collisionBoxArray.get(k);
collisionArrays.iconBox = {x1: box.x1, y1: box.y1, x2: box.x2, y2: box.y2, anchorPointX: box.anchorPointX, anchorPointY: box.anchorPointY};
collisionArrays.iconFeatureIndex = box.featureIndex;
break; // Only one box allowed per instance
}
for (let k = verticalIconStartIndex; k < verticalIconEndIndex; k++) {
// An icon can only have one box now, so this indexing is a bit vestigial...
const box: CollisionBox = (collisionBoxArray.get(k) as any);
const box: CollisionBox = collisionBoxArray.get(k);
collisionArrays.verticalIconBox = {x1: box.x1, y1: box.y1, x2: box.x2, y2: box.y2, anchorPointX: box.anchorPointX, anchorPointY: box.anchorPointY};
collisionArrays.verticalIconFeatureIndex = box.featureIndex;
break; // Only one box allowed per instance
Expand Down
2 changes: 1 addition & 1 deletion src/data/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type VertexArrayObject from '../render/vertex_array_object';
import type {StructArray} from '../util/struct_array';

export type Segment = {
sortKey: number | void,
sortKey?: number,
vertexOffset: number,
primitiveOffset: number,
vertexLength: number,
Expand Down