Skip to content

Commit

Permalink
Calculate line collision boxes over a wider range to account for label
Browse files Browse the repository at this point in the history
 expansion in the distance.
  • Loading branch information
ChrisLoer committed Apr 26, 2017
1 parent de738b8 commit cacbad9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/symbol/collision_feature.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict';

// We calculate line collision boxes out to 150% of what would normally be our
// max size, to allow collision detection to work on labels that expand as
// they move into the distance
const pitchExpansionFactor = 1.5;

/**
* A CollisionFeature represents the area of the tile covered by a single label.
* It is used with CollisionTile to check if the label overlaps with any
Expand Down Expand Up @@ -32,7 +37,7 @@ class CollisionFeature {
if (alignLine) {

let height = y2 - y1;
const length = x2 - x1;
const length = (x2 - x1) * pitchExpansionFactor;

if (height > 0) {
// set minimum box height to avoid very many small labels
Expand Down Expand Up @@ -120,7 +125,7 @@ class CollisionFeature {
const boxAnchorPoint = p1.sub(p0)._unit()._mult(segmentBoxDistance)._add(p0)._round();

const distanceToInnerEdge = Math.max(Math.abs(boxDistanceToAnchor - firstBoxOffset) - step / 2, 0);
const maxScale = labelLength / 2 / distanceToInnerEdge;
const maxScale = labelLength / 2 / distanceToInnerEdge / pitchExpansionFactor;

collisionBoxArray.emplaceBack(boxAnchorPoint.x, boxAnchorPoint.y,
-boxSize / 2, -boxSize / 2, boxSize / 2, boxSize / 2, maxScale,
Expand Down

0 comments on commit cacbad9

Please sign in to comment.