-
-
Notifications
You must be signed in to change notification settings - Fork 767
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Symbols: fix translation, variable-anchors and collision boxes (#4071)
* Import mercator symbol render tests from globe branch * Import src changes to symbols from globe branch * Add forgotten file change from globe branch * Use a reduced version of projection, adapt changes for main branch * Update build size * Fix failing unit test * Minor refactor * Rename ProjectionArgs to SymbolProjectionContext * Refactor posMatrix in draw_collision_debug * Add "_" to projectTruncatedLineSegment function name * Refactor collision box passing into a function * Remove unused code from placement.ts * collision_index: use else-if * collision_index: avoid creating copies of points * collision_index: refactor AABB projection using map() calls * collision_index: remove unused code branch * Fix merge * Change changelog formulation * Symbols: fix pitchWithMap texts sometimes having a wrongly shifted collision box * Symbols: fix pitchWithMap symbol collision boxes sometimes becoming oversized when zooming in * Symbols: update render tests * Revert oversized collisionbox fix * Symbols: more render tests with collisions enabled * Remove unused arguments from drawCollisionDebug * Refactor bounding box projection * Use explicit type for projection result in symbol projection * Add render test for distant pitch-aligned text collision bugfix * Add render test variants without bounding box corners * Fix missing docs * Add symbol box collisions benchmark * Only measure collision box handling, not grid performance * Minor refactor * Fix benchmark name being inconsistent with file name
- Loading branch information
Showing
98 changed files
with
7,356 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import type {Tile} from '../../source/tile'; | ||
import {pixelsToTileUnits} from '../../source/pixels_to_tile_units'; | ||
import type {PointProjection} from '../../symbol/projection'; | ||
|
||
/** | ||
* A greatly reduced version of the `Projection` interface from the globe branch, | ||
* used to port symbol bugfixes over to the main branch. Will be replaced with | ||
* the proper interface once globe is merged. | ||
*/ | ||
export type Projection = { | ||
useSpecialProjectionForSymbols: boolean; | ||
isOccluded(_x, _y, _t): boolean; | ||
projectTileCoordinates(_x, _y, _t, _ele): PointProjection; | ||
getPitchedTextCorrection(_transform, _anchor, _tile): number; | ||
translatePosition(transform: { angle: number; zoom: number }, tile: Tile, translate: [number, number], translateAnchor: 'map' | 'viewport'): [number, number]; | ||
getCircleRadiusCorrection(tr: any): number; | ||
}; | ||
|
||
export function createProjection(): Projection { | ||
return { | ||
isOccluded(_x: any, _y: any, _t: any) { | ||
return false; | ||
}, | ||
getPitchedTextCorrection(_transform: any, _anchor: any, _tile: any) { | ||
return 1.0; | ||
}, | ||
get useSpecialProjectionForSymbols() { return false; }, | ||
projectTileCoordinates(_x, _y, _t, _ele) { | ||
// This function should only be used when useSpecialProjectionForSymbols is set to true. | ||
throw new Error('Not implemented.'); | ||
}, | ||
translatePosition(transform, tile, translate, translateAnchor) { | ||
return translatePosition(transform, tile, translate, translateAnchor); | ||
}, | ||
getCircleRadiusCorrection(_: any) { | ||
return 1.0; | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Returns a translation in tile units that correctly incorporates the view angle and the *-translate and *-translate-anchor properties. | ||
* @param inViewportPixelUnitsUnits - True when the units accepted by the matrix are in viewport pixels instead of tile units. | ||
* | ||
* Temporarily imported from globe branch. | ||
*/ | ||
function translatePosition( | ||
transform: { angle: number; zoom: number }, | ||
tile: Tile, | ||
translate: [number, number], | ||
translateAnchor: 'map' | 'viewport', | ||
inViewportPixelUnitsUnits: boolean = false | ||
): [number, number] { | ||
if (!translate[0] && !translate[1]) return [0, 0]; | ||
|
||
const angle = inViewportPixelUnitsUnits ? | ||
(translateAnchor === 'map' ? transform.angle : 0) : | ||
(translateAnchor === 'viewport' ? -transform.angle : 0); | ||
|
||
if (angle) { | ||
const sinA = Math.sin(angle); | ||
const cosA = Math.cos(angle); | ||
translate = [ | ||
translate[0] * cosA - translate[1] * sinA, | ||
translate[0] * sinA + translate[1] * cosA | ||
]; | ||
} | ||
|
||
return [ | ||
inViewportPixelUnitsUnits ? translate[0] : pixelsToTileUnits(tile, translate[0], transform.zoom), | ||
inViewportPixelUnitsUnits ? translate[1] : pixelsToTileUnits(tile, translate[1], transform.zoom)]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.