Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform specific projectPoint #5267

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/geo/projection/globe_transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@
return this.currentTransform.projectTileCoordinates(x, y, unwrappedTileID, getElevation);
}

public projectPoint(p: Point, pixelPosMatrix: mat4): Point {
return this.currentTransform.projectPoint(p, pixelPosMatrix);

Check warning on line 321 in src/geo/projection/globe_transform.ts

View check run for this annotation

Codecov / codecov/patch

src/geo/projection/globe_transform.ts#L321

Added line #L321 was not covered by tests
}

private _calcMatrices(): void {
if (!this._helper._width || !this._helper._height) {
return;
Expand Down
5 changes: 5 additions & 0 deletions src/geo/projection/mercator_transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,11 @@
};
}

projectPoint(p: Point, pixelPosMatrix: mat4) {
const point = vec4.transformMat4([] as any, [p.x, p.y, 0, 1], pixelPosMatrix);
return new Point(point[0] / point[3], point[1] / point[3]);

Check warning on line 784 in src/geo/projection/mercator_transform.ts

View check run for this annotation

Codecov / codecov/patch

src/geo/projection/mercator_transform.ts#L783-L784

Added lines #L783 - L784 were not covered by tests
}

populateCache(coords: Array<OverscaledTileID>): void {
for (const coord of coords) {
// Return value is thrown away, but this function will still
Expand Down
5 changes: 5 additions & 0 deletions src/geo/projection/vertical_perspective_transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
};
}

public projectPoint(p: Point) {
const point = vec4.transformMat4([] as any, [p.x, p.y, 0, 1], this._globeViewProjMatrix32f);
return new Point(point[0] / point[3], point[1] / point[3]);

Check warning on line 442 in src/geo/projection/vertical_perspective_transform.ts

View check run for this annotation

Codecov / codecov/patch

src/geo/projection/vertical_perspective_transform.ts#L441-L442

Added lines #L441 - L442 were not covered by tests
}

private _calcMatrices(): void {
if (!this._helper._width || !this._helper._height) {
return;
Expand Down
5 changes: 5 additions & 0 deletions src/geo/transform_interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ export interface IReadonlyTransform extends ITransformGetters {
*/
projectTileCoordinates(x: number, y: number, unwrappedTileID: UnwrappedTileID, getElevation: (x: number, y: number) => number): PointProjection;

/**
* Projects a point in screen coordinates to tile coordinates
*/
projectPoint(p: Point, pixelPosMatrix: mat4): Point;

/**
* Returns a matrix that will place, rotate and scale a model to display at the given location and altitude
* while also being projected by the custom layer matrix.
Expand Down
14 changes: 5 additions & 9 deletions src/style/style_layer/circle_style_layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@
// // A circle with fixed scaling relative to the viewport gets larger in tile space as it moves into the distance
// // A circle with fixed scaling relative to the map gets smaller in viewport space as it moves into the distance
const alignWithMap = this.paint.get('circle-pitch-alignment') === 'map';
const transformedPolygon = alignWithMap ? translatedPolygon : projectQueryGeometry(translatedPolygon, pixelPosMatrix);
const transformedPolygon = alignWithMap ? translatedPolygon : projectQueryGeometry(translatedPolygon, pixelPosMatrix, transform);

Check warning on line 67 in src/style/style_layer/circle_style_layer.ts

View check run for this annotation

Codecov / codecov/patch

src/style/style_layer/circle_style_layer.ts#L67

Added line #L67 was not covered by tests
const transformedSize = alignWithMap ? size * pixelsToTileUnits : size;

for (const ring of geometry) {
for (const point of ring) {

const transformedPoint = alignWithMap ? point : projectPoint(point, pixelPosMatrix);
const transformedPoint = alignWithMap ? point : transform.projectPoint(point, pixelPosMatrix);

Check warning on line 73 in src/style/style_layer/circle_style_layer.ts

View check run for this annotation

Codecov / codecov/patch

src/style/style_layer/circle_style_layer.ts#L73

Added line #L73 was not covered by tests

let adjustedSize = transformedSize;
const projectedCenter = vec4.transformMat4([] as any, [point.x, point.y, 0, 1], pixelPosMatrix);
Expand All @@ -88,13 +88,9 @@
}
}

function projectPoint(p: Point, pixelPosMatrix: mat4) {
const point = vec4.transformMat4([] as any, [p.x, p.y, 0, 1], pixelPosMatrix);
return new Point(point[0] / point[3], point[1] / point[3]);
}

function projectQueryGeometry(queryGeometry: Array<Point>, pixelPosMatrix: mat4) {
function projectQueryGeometry(queryGeometry: Array<Point>, pixelPosMatrix: mat4, transform: IReadonlyTransform) {

Check warning on line 91 in src/style/style_layer/circle_style_layer.ts

View check run for this annotation

Codecov / codecov/patch

src/style/style_layer/circle_style_layer.ts#L91

Added line #L91 was not covered by tests
return queryGeometry.map((p) => {
return projectPoint(p, pixelPosMatrix);
const projected = transform.projectPoint(p, pixelPosMatrix);
return new Point(projected.x, projected.y);

Check warning on line 94 in src/style/style_layer/circle_style_layer.ts

View check run for this annotation

Codecov / codecov/patch

src/style/style_layer/circle_style_layer.ts#L93-L94

Added lines #L93 - L94 were not covered by tests
});
}
Loading