Skip to content

Commit

Permalink
Add Undefined mercatorOrigin Check to computeMercatorFractionToDb (ba…
Browse files Browse the repository at this point in the history
…ckport #7269) [release/4.9.x] (#7328)

Co-authored-by: andremig-bentley <101671244+andremig-bentley@users.noreply.github.com>
  • Loading branch information
mergify[bot] and andremig-bentley authored Nov 6, 2024
1 parent 813a139 commit f54abdc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-frontend",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/core-frontend"
}
16 changes: 14 additions & 2 deletions core/frontend/src/test/BackgroundMapGeometry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { expect } from "chai";
import sinon from "sinon";
import { IModelApp } from "../IModelApp";
import { Cartographic, EmptyLocalization, GlobeMode } from "@itwin/core-common";
import { IModelConnection } from "../IModelConnection";
import { Range3d, XYAndZ } from "@itwin/core-geometry";
import { BlankConnection, IModelConnection } from "../IModelConnection";
import { Point3d, Range3d, XYAndZ } from "@itwin/core-geometry";
import { BackgroundMapGeometry } from "../BackgroundMapGeometry";
import { createBlankConnection } from "./createBlankConnection";
import { Guid } from "@itwin/core-bentley";

describe("BackgroundMapGeometry", () => {
const sandbox = sinon.createSandbox();
Expand Down Expand Up @@ -53,4 +54,15 @@ describe("BackgroundMapGeometry", () => {
expect(dataset[i].z).to.eq(result[i].height);
}
});

it("creates new background map geometry when the origin is (0, 0, 0)", async () => {
const name = "test-blank-connection";
const extents = new Range3d(-2500, -2500, -1000, 2500, 2500, 1000);
const globalOrigin = new Point3d(0, 0, 0);
const iTwinId = Guid.createValue();
const imodel = BlankConnection.create({ name, location: { origin: [0, 0, 0], orientation: { yaw: 0, pitch: 0, roll: 0 } }, extents, iTwinId, globalOrigin });

const geometry = new BackgroundMapGeometry(0, 0, imodel);
expect(geometry).to.not.be.undefined;
});
});
9 changes: 7 additions & 2 deletions core/frontend/src/tile/map/MapTilingScheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ export abstract class MapTilingScheme {
}

/** @alpha */
private ecefToPixelFraction(point: Point3d, applyTerrain: boolean): Point3d {
const cartoGraphic = Cartographic.fromEcef(point)!;
private ecefToPixelFraction(point: Point3d, applyTerrain: boolean): Point3d | undefined {
const cartoGraphic = Cartographic.fromEcef(point);
if (!cartoGraphic)
return undefined;
return Point3d.create(this.longitudeToXFraction(cartoGraphic.longitude), this.latitudeToYFraction(cartoGraphic.latitude), applyTerrain ? cartoGraphic.height : 0);
}

Expand All @@ -205,6 +207,9 @@ export abstract class MapTilingScheme {
const mercatorX = this.ecefToPixelFraction(dbToEcef.multiplyPoint3d(projectEast), applyTerrain);
const mercatorY = this.ecefToPixelFraction(dbToEcef.multiplyPoint3d(projectNorth), applyTerrain);

if (!mercatorOrigin || !mercatorX || !mercatorY)
return Transform.createIdentity();

const deltaX = Vector3d.createStartEnd(mercatorOrigin, mercatorX);
const deltaY = Vector3d.createStartEnd(mercatorOrigin, mercatorY);
const matrix = Matrix3d.createColumns(deltaX, deltaY, Vector3d.create(0, 0, 1));
Expand Down

0 comments on commit f54abdc

Please sign in to comment.