Skip to content

Commit

Permalink
"collision group" -> "cross source collisions" conversion:
Browse files Browse the repository at this point in the history
 - Rename tests
 - Remove dead code from CollisionGroups, update parameter names
 - Simplify return pathways for _query
  • Loading branch information
ChrisLoer committed Jun 8, 2018
1 parent 003d3ce commit 38138a3
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 59 deletions.
8 changes: 4 additions & 4 deletions src/symbol/collision_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,17 @@ class CollisionIndex {
return result;
}

insertCollisionBox(collisionBox: Array<number>, ignorePlacement: boolean, bucketInstanceId: number, featureIndex: number, collisionGroup: number) {
insertCollisionBox(collisionBox: Array<number>, ignorePlacement: boolean, bucketInstanceId: number, featureIndex: number, collisionGroupID: number) {
const grid = ignorePlacement ? this.ignoredGrid : this.grid;

const key = { bucketInstanceId: bucketInstanceId, featureIndex: featureIndex, collisionGroup: collisionGroup };
const key = { bucketInstanceId: bucketInstanceId, featureIndex: featureIndex, collisionGroupID: collisionGroupID };
grid.insert(key, collisionBox[0], collisionBox[1], collisionBox[2], collisionBox[3]);
}

insertCollisionCircles(collisionCircles: Array<number>, ignorePlacement: boolean, bucketInstanceId: number, featureIndex: number, collisionGroup: number) {
insertCollisionCircles(collisionCircles: Array<number>, ignorePlacement: boolean, bucketInstanceId: number, featureIndex: number, collisionGroupID: number) {
const grid = ignorePlacement ? this.ignoredGrid : this.grid;

const key = { bucketInstanceId: bucketInstanceId, featureIndex: featureIndex, collisionGroup: collisionGroup };
const key = { bucketInstanceId: bucketInstanceId, featureIndex: featureIndex, collisionGroupID: collisionGroupID };
for (let k = 0; k < collisionCircles.length; k += 4) {
grid.insertCircle(key, collisionCircles[k], collisionCircles[k + 1], collisionCircles[k + 2]);
}
Expand Down
6 changes: 2 additions & 4 deletions src/symbol/grid_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,15 @@ class GridIndex {
y2: y + radius
});
}
if (predicate) {
return result.filter(predicate);
}
return predicate ? result.filter(predicate) : result;
} else {
const queryArgs = {
hitTest,
seenUids: { box: {}, circle: {} }
};
this._forEachCell(x1, y1, x2, y2, this._queryCell, result, queryArgs, predicate);
return hitTest ? result.length > 0 : result;
}
return hitTest ? result.length > 0 : result;
}

_queryCircle(x: number, y: number, radius: number, hitTest: boolean, predicate?: any) {
Expand Down
56 changes: 23 additions & 33 deletions src/symbol/placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,40 +83,34 @@ export class RetainedQueryData {
}

class CollisionGroups {
collisionGroups: { [layerId: ?string]: { ID: number, predicate?: any }};
collisionGroups: { [groupName: string]: { ID: number, predicate?: any }};
maxGroupID: number;
crossSourceCollisions: boolean;

constructor() {
constructor(crossSourceCollisions: boolean) {
this.crossSourceCollisions = crossSourceCollisions;
this.maxGroupID = 0;
this.collisionGroups = {
undefined: {
ID: 0,
predicate: null
}
};
this.collisionGroups = {};
}

get(groupName?: string) {
if (groupName && this.maxGroupID === 0) {
// Keep the predicate null until the first collision
// group gets added to avoid overhead in the case
// everything's in the default group.
this.collisionGroups[undefined].predicate =
(key) => {
return key.collisionGroup === 0;
get(sourceID: string) {
// The predicate/groupID mechanism allows for arbitrary grouping,
// but the current interface defines one source == one group when
// crossSourceCollisions == true.
if (!this.crossSourceCollisions) {
if (!this.collisionGroups[sourceID]) {
const nextGroupID = ++this.maxGroupID;
this.collisionGroups[sourceID] = {
ID: nextGroupID,
predicate: (key) => {
return key.collisionGroupID === nextGroupID;
}
};
}
return this.collisionGroups[sourceID];
} else {
return { ID: 0, predicate: null };
}

if (!this.collisionGroups[groupName]) {
const nextGroupID = ++this.maxGroupID;
this.collisionGroups[groupName] = {
ID: nextGroupID,
predicate: (key) => {
return key.collisionGroup === nextGroupID;
}
};
}
return this.collisionGroups[groupName];
}
}

Expand All @@ -132,7 +126,6 @@ export class Placement {
fadeDuration: number;
retainedQueryData: {[number]: RetainedQueryData};
collisionGroups: CollisionGroups;
crossSourceCollisions: boolean;

constructor(transform: Transform, fadeDuration: number, crossSourceCollisions: boolean) {
this.transform = transform.clone();
Expand All @@ -142,8 +135,7 @@ export class Placement {
this.stale = false;
this.fadeDuration = fadeDuration;
this.retainedQueryData = {};
this.collisionGroups = new CollisionGroups();
this.crossSourceCollisions = crossSourceCollisions;
this.collisionGroups = new CollisionGroups(crossSourceCollisions);
}

placeLayerTile(styleLayer: StyleLayer, tile: Tile, showCollisionBoxes: boolean, seenCrossTileIDs: { [string | number]: boolean }) {
Expand Down Expand Up @@ -197,9 +189,7 @@ export class Placement {
const iconWithoutText = !bucket.hasTextData() || layout.get('text-optional');
const textWithoutIcon = !bucket.hasIconData() || layout.get('icon-optional');

const collisionGroup = this.crossSourceCollisions ?
this.collisionGroups.get() :
this.collisionGroups.get(bucket.sourceID);
const collisionGroup = this.collisionGroups.get(bucket.sourceID);

for (const symbolInstance of bucket.symbolInstances) {
if (!seenCrossTileIDs[symbolInstance.crossTileID]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"sprite": "local://sprites/sprite",
"layers": [
{
"id": "defaultGroup1",
"id": "source1Group1",
"type": "symbol",
"source": "source1",
"layout": {
Expand All @@ -81,7 +81,7 @@
}
},
{
"id": "defaultGroup2",
"id": "source1Group2",
"type": "symbol",
"source": "source1",
"layout": {
Expand All @@ -90,7 +90,7 @@
}
},
{
"id": "firstGroup1",
"id": "source2Group1",
"type": "symbol",
"source": "source2",
"layout": {
Expand All @@ -103,7 +103,7 @@
}
},
{
"id": "firstGroup2",
"id": "source2Group2",
"type": "symbol",
"source": "source2",
"layout": {
Expand All @@ -116,7 +116,7 @@
}
},
{
"id": "secondGroup1",
"id": "source3Group1",
"type": "symbol",
"source": "source3",
"layout": {
Expand All @@ -129,7 +129,7 @@
}
},
{
"id": "secondGroup2",
"id": "source3Group2",
"type": "symbol",
"source": "source3",
"layout": {
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"layers": [
{
"id": "defaultGroup1",
"id": "source1Group1",
"type": "symbol",
"source": "source1",
"layout": {
"text-field": "Default Group {name}",
"text-field": "Source1 Group {name}",
"text-max-width": 30,
"text-font": [
"Open Sans Semibold",
Expand All @@ -133,11 +133,11 @@
}
},
{
"id": "defaultGroup2",
"id": "source1Group2",
"type": "symbol",
"source": "source1",
"layout": {
"text-field": "2nd Layer Default Group {name}",
"text-field": "2nd Layer Source1 Group {name}",
"text-max-width": 30,
"text-font": [
"Open Sans Semibold",
Expand All @@ -146,11 +146,11 @@
}
},
{
"id": "firstGroup1",
"id": "source2Group1",
"type": "symbol",
"source": "source2",
"layout": {
"text-field": "First Group {name}",
"text-field": "Source2 Group {name}",
"text-max-width": 30,
"text-font": [
"Open Sans Semibold",
Expand All @@ -163,11 +163,11 @@
}
},
{
"id": "firstGroup2",
"id": "source2Group2",
"type": "symbol",
"source": "source2",
"layout": {
"text-field": "2nd Layer First Group {name}",
"text-field": "2nd Layer Source2 Group {name}",
"text-max-width": 30,
"text-font": [
"Open Sans Semibold",
Expand All @@ -180,11 +180,11 @@
}
},
{
"id": "secondGroup1",
"id": "source3Group1",
"type": "symbol",
"source": "source3",
"layout": {
"text-field": "Second Group {name}",
"text-field": "Source3 Group {name}",
"text-max-width": 30,
"text-font": [
"Open Sans Semibold",
Expand All @@ -197,11 +197,11 @@
}
},
{
"id": "secondGroup2",
"id": "ssource3Group2",
"type": "symbol",
"source": "source3",
"layout": {
"text-field": "2nd Layer Second Group {name}",
"text-field": "2nd Layer Source3 Group {name}",
"text-max-width": 30,
"text-font": [
"Open Sans Semibold",
Expand Down

0 comments on commit 38138a3

Please sign in to comment.