Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
HARP-14465: Store text/icon world coordinates in double precision.
Browse files Browse the repository at this point in the history
POI and text positions, which use world coordinates (in contrast to tile coordinates used
by meshes), were being decoded into a single precision buffer, hence losing precision.

Signed-off-by: Andres Mandado <andres.mandado-almajano@here.com>
  • Loading branch information
atomicsulfate committed Mar 18, 2021
1 parent 925263a commit 98354e4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 37 deletions.
7 changes: 1 addition & 6 deletions @here/harp-datasource-protocol/lib/DecodedTile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,11 @@ export interface TextGeometry {
* Structured clone compliant version of a `three.js` geometry object with points of interest (POIs)
* to be rendered. It is composed of buffers with metadata for POI objects.
*/
export interface PoiGeometry {
positions: BufferAttribute;
texts: number[];
export interface PoiGeometry extends TextGeometry {
/**
* Names of the image texture or the name of the POI as indices into the array `stringCatalog`.
*/
imageTextures?: number[];
technique?: number;
stringCatalog: Array<string | undefined>;
objInfos?: AttributeMap[];
// Angle in degrees from north clockwise specifying the directions the icons can be shifted.
offsetDirections?: number[];
}
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-mapview/lib/geometry/TileGeometryCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ export class TileGeometryCreator {
}

const positions = new THREE.BufferAttribute(
new Float32Array(text.positions.buffer),
new Float64Array(text.positions.buffer),
text.positions.itemCount
);

Expand Down
2 changes: 1 addition & 1 deletion @here/harp-mapview/lib/poi/PoiManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class PoiManager {
}

const positions = new THREE.BufferAttribute(
new Float32Array(poiGeometry.positions.buffer),
new Float64Array(poiGeometry.positions.buffer),
poiGeometry.positions.itemCount
);

Expand Down
41 changes: 16 additions & 25 deletions @here/harp-vectortile-datasource/lib/VectorTileDataEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ export class VectorTileDataEmitter {
positions: {
name: "position",
type: "float",
buffer: new Float32Array(aLine).buffer,
buffer: new Float64Array(aLine).buffer,
itemCount: 3
},
texts: [0],
Expand Down Expand Up @@ -1706,43 +1706,34 @@ export class VectorTileDataEmitter {
if (technique === undefined) {
return;
}

const positionElements = new Float32Array(meshBuffers.positions);

if (meshBuffers.texts.length > 0 && isTextTechnique(technique)) {
this.m_textGeometries.push({
if (meshBuffers.texts.length > 0) {
const geometry: TextGeometry = {
positions: {
name: "position",
type: "float",
buffer: positionElements.buffer as ArrayBuffer,
buffer: new Float64Array(meshBuffers.positions).buffer,
itemCount: 3
},
texts: meshBuffers.texts,
technique: techniqueIdx,
stringCatalog: meshBuffers.stringCatalog,
objInfos: meshBuffers.objInfos
});
return;
}
};

if (meshBuffers.texts.length > 0 && isPoiTechnique(technique)) {
this.m_poiGeometries.push({
positions: {
name: "position",
type: "float",
buffer: positionElements.buffer as ArrayBuffer,
itemCount: 3
},
texts: meshBuffers.texts,
technique: techniqueIdx,
stringCatalog: meshBuffers.stringCatalog,
imageTextures: meshBuffers.imageTextures,
objInfos: meshBuffers.objInfos,
offsetDirections: meshBuffers.offsetDirections
});
if (isTextTechnique(technique)) {
this.m_textGeometries.push(geometry);
} else {
assert(isPoiTechnique(technique));
const poiGeometry = geometry as PoiGeometry;
poiGeometry.imageTextures = meshBuffers.imageTextures;
poiGeometry.offsetDirections = meshBuffers.offsetDirections;
this.m_poiGeometries.push(poiGeometry);
}
return;
}

const positionElements = new Float32Array(meshBuffers.positions);

if (meshBuffers.groups.length === 0) {
// create a default group containing all the vertices in the position attribute.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,17 @@ describe("OmvDecodedTileEmitter", function () {
const tileKey = TileKey.fromRowColumnLevel(0, 0, level);
const decodeInfo = new DecodeInfo("test", mercatorProjection, tileKey);

function getExpectedHeight(geoAltitude: number, worldCoords: Vector3Like) {
function getExpectedHeight(
geoAltitude: number,
worldCoords: Vector3Like,
toSinglePrecision = true
) {
const scaleFactor = expectScaledHeight
? decodeInfo.targetProjection.getScaleFactor(worldCoords)
: 1.0;
const expectedHeight = geoAltitude * scaleFactor;
// Force conversion to single precision as in decoder so that results match.
return new Float32Array([geoAltitude * scaleFactor])[0];
return toSinglePrecision ? new Float32Array([expectedHeight])[0] : expectedHeight;
}

it(`Point Height at level ${level} with constantHeight ${
Expand Down Expand Up @@ -174,13 +179,13 @@ describe("OmvDecodedTileEmitter", function () {

assert.equal(textGeometries?.length, 1, "only one geometry created");

const buffer = new Float32Array(textGeometries![0].positions.buffer);
const buffer = new Float64Array(textGeometries![0].positions.buffer);
assert.equal(buffer.length, 3, "one position (3 coordinates)");

const actualHeight = buffer[2];
assert.approximately(
actualHeight,
getExpectedHeight(geoCoords.altitude, worldCoords),
getExpectedHeight(geoCoords.altitude, worldCoords, false),
1e-6
);
});
Expand Down

0 comments on commit 98354e4

Please sign in to comment.