Skip to content

Commit

Permalink
Revert conservative glyph placement
Browse files Browse the repository at this point in the history
  • Loading branch information
mpulkki-mapbox committed Mar 3, 2020
1 parent de75c11 commit 4305e63
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
6 changes: 1 addition & 5 deletions src/symbol/collision_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ class CollisionIndex {
const lineOffsetX = symbol.lineOffsetX * labelPlaneFontScale;
const lineOffsetY = symbol.lineOffsetY * labelPlaneFontScale;

// Use conservative placement to cover both flipped and non-flipped cases as the final usage is not known yet
const conservativePlacement = true;

const firstAndLastGlyph = projection.placeFirstAndLastGlyph(
labelPlaneFontScale,
glyphOffsetArray,
Expand All @@ -126,8 +123,7 @@ class CollisionIndex {
symbol,
lineVertexArray,
labelPlaneMatrix,
projectionCache,
conservativePlacement);
projectionCache);

let collisionDetected = false;
let inGrid = false;
Expand Down
14 changes: 4 additions & 10 deletions src/symbol/projection.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,13 @@ function updateLineLabels(bucket: SymbolBucket,
}
}

function placeFirstAndLastGlyph(fontScale: number, glyphOffsetArray: GlyphOffsetArray, lineOffsetX: number, lineOffsetY: number, flip: boolean, anchorPoint: Point, tileAnchorPoint: Point, symbol: any, lineVertexArray: SymbolLineVertexArray, labelPlaneMatrix: mat4, projectionCache: any, conservativePlacement: boolean) {
function placeFirstAndLastGlyph(fontScale: number, glyphOffsetArray: GlyphOffsetArray, lineOffsetX: number, lineOffsetY: number, flip: boolean, anchorPoint: Point, tileAnchorPoint: Point, symbol: any, lineVertexArray: SymbolLineVertexArray, labelPlaneMatrix: mat4, projectionCache: any) {
const glyphEndIndex = symbol.glyphStartIndex + symbol.numGlyphs;
const lineStartIndex = symbol.lineStartIndex;
const lineEndIndex = symbol.lineStartIndex + symbol.lineLength;

let firstGlyphOffset = glyphOffsetArray.getoffsetX(symbol.glyphStartIndex);
let lastGlyphOffset = glyphOffsetArray.getoffsetX(glyphEndIndex - 1);

if (conservativePlacement) {
const maxOffset = Math.max(Math.abs(firstGlyphOffset), Math.abs(lastGlyphOffset));
firstGlyphOffset = -maxOffset;
lastGlyphOffset = maxOffset;
}
const firstGlyphOffset = glyphOffsetArray.getoffsetX(symbol.glyphStartIndex);
const lastGlyphOffset = glyphOffsetArray.getoffsetX(glyphEndIndex - 1);

const firstPlacedGlyph = placeGlyphAlongLine(fontScale * firstGlyphOffset, lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, symbol.segment,
lineStartIndex, lineEndIndex, lineVertexArray, labelPlaneMatrix, projectionCache);
Expand Down Expand Up @@ -268,7 +262,7 @@ function placeGlyphsAlongLine(symbol, fontSize, flip, keepUpright, posMatrix, la

// Place the first and the last glyph in the label first, so we can figure out
// the overall orientation of the label and determine whether it needs to be flipped in keepUpright mode
const firstAndLastGlyph = placeFirstAndLastGlyph(fontScale, glyphOffsetArray, lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, symbol, lineVertexArray, labelPlaneMatrix, projectionCache, false);
const firstAndLastGlyph = placeFirstAndLastGlyph(fontScale, glyphOffsetArray, lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, symbol, lineVertexArray, labelPlaneMatrix, projectionCache);
if (!firstAndLastGlyph) {
return {notEnoughRoom: true};
}
Expand Down

0 comments on commit 4305e63

Please sign in to comment.