Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mpulkki-mapbox committed Mar 24, 2020
1 parent 81372b5 commit f4f59e7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/render/program/collision_program.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type CollisionUniformsType = {|

export type CollisionCircleUniformsType = {|
'u_matrix': UniformMatrix4f,
'u_invMatrix': UniformMatrix4f,
'u_inv_matrix': UniformMatrix4f,
'u_quads': Uniform4fv,
'u_camera_to_center_distance': Uniform1f,
'u_viewport_size': Uniform2f
Expand All @@ -39,7 +39,7 @@ const collisionUniforms = (context: Context, locations: UniformLocations): Colli

const collisionCircleUniforms = (context: Context, locations: UniformLocations): CollisionCircleUniformsType => ({
'u_matrix': new UniformMatrix4f(context, locations.u_matrix),
'u_invMatrix': new UniformMatrix4f(context, locations.u_invMatrix),
'u_inv_matrix': new UniformMatrix4f(context, locations.u_inv_matrix),
'u_quads': new Uniform4fv(context, locations.u_quads),
'u_camera_to_center_distance': new Uniform1f(context, locations.u_camera_to_center_distance),
'u_viewport_size': new Uniform2f(context, locations.u_viewport_size)
Expand Down Expand Up @@ -71,7 +71,7 @@ const collisionCircleUniformValues = (
): UniformValues<CollisionCircleUniformsType> => {
return {
'u_matrix': matrix,
'u_invMatrix': invMatrix,
'u_inv_matrix': invMatrix,
'u_quads': quads,
'u_camera_to_center_distance': transform.cameraToCenterDistance,
'u_viewport_size': [transform.width, transform.height]
Expand Down
6 changes: 3 additions & 3 deletions src/shaders/collision_circle.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
attribute vec2 a_idx;

uniform mat4 u_matrix;
uniform mat4 u_invMatrix;
uniform mat4 u_inv_matrix;
uniform vec2 u_viewport_size;
uniform float u_camera_to_center_distance;

Expand All @@ -37,8 +37,8 @@ varying float v_collision;

vec3 toTilePosition(vec2 screenPos) {
// Shoot a ray towards the ground to reconstruct the depth-value
vec4 rayStart = u_invMatrix * vec4(screenPos, -1.0, 1.0);
vec4 rayEnd = u_invMatrix * vec4(screenPos, 1.0, 1.0);
vec4 rayStart = u_inv_matrix * vec4(screenPos, -1.0, 1.0);
vec4 rayEnd = u_inv_matrix * vec4(screenPos, 1.0, 1.0);

rayStart.xyz /= rayStart.w;
rayEnd.xyz /= rayEnd.w;
Expand Down
9 changes: 7 additions & 2 deletions src/symbol/collision_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import PathInterpolator from './path_interpolator';
import * as intersectionTests from '../util/intersection_tests';
import Grid from './grid_index';
import {mat4} from 'gl-matrix';
import ONE_EM from '../symbol/one_em';

import * as projection from '../symbol/projection';

Expand Down Expand Up @@ -103,7 +104,7 @@ class CollisionIndex {

const perspectiveRatio = this.projectAnchor(posMatrix, symbol.anchorX, symbol.anchorY).perspectiveRatio;
const labelPlaneFontSize = pitchWithMap ? fontSize / perspectiveRatio : fontSize * perspectiveRatio;
const labelPlaneFontScale = labelPlaneFontSize / 24;
const labelPlaneFontScale = labelPlaneFontSize / ONE_EM;

const tileUnitAnchorPoint = new Point(symbol.anchorX, symbol.anchorY);
const labelPlaneAnchorPoint = projection.project(tileUnitAnchorPoint, labelPlaneMatrix).point;
Expand Down Expand Up @@ -139,7 +140,11 @@ class CollisionIndex {
const first = firstAndLastGlyph.first;
const last = firstAndLastGlyph.last;

let projectedPath = first.path.slice(1).reverse().concat(last.path.slice(1));
let projectedPath = [];
for (let i = first.path.length - 1; i >= 1; i--)
projectedPath.push(first.path[i]);
for (let i = 1; i < last.path.length; i++)
projectedPath.push(last.path[i]);

// Tolerate a slightly longer distance than one diameter between two adjacent circles
const circleDist = radius * 2.5;
Expand Down
4 changes: 2 additions & 2 deletions src/symbol/path_interpolator.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PathInterpolator {

t = clamp(t, 0, 1);

// Find the correct segment. Use a cached index value to start the search
// Find the correct segment [p0, p1] where p0 <= x < p1
let currentIndex = 1;
let distOfCurrentIdx = this._distances[currentIndex];
const distToTarget = t * this.paddedLength + this.padding;
Expand All @@ -48,7 +48,7 @@ class PathInterpolator {
distOfCurrentIdx = this._distances[++currentIndex];
}

// We've found a segment with two points p0 and p1 where p0 <= x < p1. Interpolate between these two points
// Interpolate between the two points of the segment
const idxOfPrevPoint = currentIndex - 1;
const distOfPrevIdx = this._distances[idxOfPrevPoint];
const segmentLength = distOfCurrentIdx - distOfPrevIdx;
Expand Down

0 comments on commit f4f59e7

Please sign in to comment.