Skip to content

Commit

Permalink
Bump typescript from 5.6.3 to 5.7.2 (#5109)
Browse files Browse the repository at this point in the history
* Bump typescript from 5.6.3 to 5.7.2

Bumps [typescript](https://github.com/microsoft/TypeScript) from 5.6.3 to 5.7.2.
- [Release notes](https://github.com/microsoft/TypeScript/releases)
- [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release.yml)
- [Commits](microsoft/TypeScript@v5.6.3...v5.7.2)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Fix unit test

* Refactor with tests

* Fix lint

* Use the correct array types for this to succeed.

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: HarelM <[email protected]>
  • Loading branch information
dependabot[bot] and HarelM authored Dec 5, 2024
1 parent bd4eb37 commit cf58061
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 47 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"typedoc": "^0.27.3",
"typedoc-plugin-markdown": "^4.3.1",
"typedoc-plugin-missing-exports": "^3.1.0",
"typescript": "^5.6.3",
"typescript": "^5.7.2",
"vitest": "2.2.0-beta.2",
"vitest-webgl-canvas-mock": "^1.1.0"
},
Expand Down
8 changes: 4 additions & 4 deletions src/source/vector_tile_worker_source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('vector tile worker source', () => {
});

test('VectorTileWorkerSource#loadTile reparses tile if the reloadTile has been called during parsing', async () => {
const rawTileData = new Uint8Array([]);
const rawTileData = new ArrayBuffer(0);
const loadVectorData: LoadVectorData = async (_params, _abortController) => {
return {
vectorTile: {
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('vector tile worker source', () => {
});

test('VectorTileWorkerSource#loadTile reparses tile if reloadTile is called during reparsing', async () => {
const rawTileData = new Uint8Array([]);
const rawTileData = new ArrayBuffer(0);
const loadVectorData: LoadVectorData = async (_params, _abortController) => {
return {
vectorTile: new vt.VectorTile(new Protobuf(rawTileData)),
Expand Down Expand Up @@ -290,7 +290,7 @@ describe('vector tile worker source', () => {
}));

test('VectorTileWorkerSource provides resource timing information', async () => {
const rawTileData = fs.readFileSync(path.join(__dirname, '/../../test/unit/assets/mbsv5-6-18-23.vector.pbf'));
const rawTileData = fs.readFileSync(path.join(__dirname, '/../../test/unit/assets/mbsv5-6-18-23.vector.pbf')).buffer.slice(0) as ArrayBuffer;

const loadVectorData: LoadVectorData = async (_params, _abortController) => {
return {
Expand Down Expand Up @@ -346,7 +346,7 @@ describe('vector tile worker source', () => {
});

test('VectorTileWorkerSource provides resource timing information (fallback method)', async () => {
const rawTileData = fs.readFileSync(path.join(__dirname, '/../../test/unit/assets/mbsv5-6-18-23.vector.pbf'));
const rawTileData = fs.readFileSync(path.join(__dirname, '/../../test/unit/assets/mbsv5-6-18-23.vector.pbf')).buffer.slice(0) as ArrayBuffer;

const loadVectorData: LoadVectorData = async (_params, _abortController) => {
return {
Expand Down
30 changes: 30 additions & 0 deletions src/util/create_tile_mesh.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {describe, expect, test, vi} from 'vitest';
import {createTileMesh, createTileMeshWithBuffers, type CreateTileMeshOptions} from './create_tile_mesh';

describe('create_tile_mesh', () => {
test('createTileMeshWithBuffers should create buffer in the right size', () => {
const createVertexBufferSpy = vi.fn();
const createIndexBufferSpy = vi.fn();
const contextMock: any = {
createVertexBuffer: createVertexBufferSpy,
createIndexBuffer: createIndexBufferSpy
};
const options: CreateTileMeshOptions = {};
createTileMeshWithBuffers(contextMock, options);

expect(createVertexBufferSpy.mock.calls[0][0].length).toBe(4);
expect(createIndexBufferSpy.mock.calls[0][0].length).toBe(2);
});

test('createTileMesh 32bit', () => {
const mesh = createTileMesh({}, '32bit');
expect(mesh.indices.byteLength).toBe(6 * 2 * 2); // 32bit
expect(mesh.vertices.byteLength).toBe(8 * 2); // 16bit
})

test('createTileMesh 16bit', () => {
const mesh = createTileMesh({}, '16bit');
expect(mesh.indices.byteLength).toBe(6 * 2); // 16bit
expect(mesh.vertices.byteLength).toBe(8 * 2); // 16bit
})
})
62 changes: 24 additions & 38 deletions src/util/create_tile_mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ export type CreateTileMeshOptions = {
/**
* Stores the prepared vertex and index buffer bytes for a mesh.
*/
export type TileMesh<T extends Uint16Array | Uint32Array> = {
export type TileMesh = {
/**
* The vertex data. Each vertex is two 16 bit signed integers, one for X, one for Y.
*/
vertices: Int16Array;
vertices: ArrayBuffer;
/**
* The index data. Each triangle is defined by three indices. The indices may either be 16 bit or 32 bit unsigned integers,
* depending on the mesh creation arguments and on whether the mesh can fit into 16 bit indices.
*/
indices: T;
indices: ArrayBuffer;
/**
* A helper boolean indicating whether the indices are 32 bit.
*/
uses32bitIndices: T extends Uint32Array ? true : false;
uses32bitIndices: boolean;
};

/**
Expand All @@ -80,11 +80,11 @@ export function createTileMeshWithBuffers(context: Context, options: CreateTileM
const tileMesh = createTileMesh(options, '16bit');
const vertices = PosArray.deserialize({
arrayBuffer: tileMesh.vertices,
length: tileMesh.vertices.length / 2, // Two values per vertex
length: tileMesh.vertices.byteLength / 2 / 2, // Two values per vertex, 16 bit
});
const indices = TriangleIndexArray.deserialize({
arrayBuffer: tileMesh.indices,
length: tileMesh.indices.length / 3, // Three values per triangle
length: tileMesh.indices.byteLength / 2 / 3, // Three values per triangle, 16 bit
});
const mesh = new Mesh(
context.createVertexBuffer(vertices, posAttributes.members),
Expand Down Expand Up @@ -114,7 +114,7 @@ export function createTileMeshWithBuffers(context: Context, options: CreateTileM
* @param forceIndicesSize - Specifies what indices type to use. The values '32bit' and '16bit' force their respective indices size. If undefined, the mesh may use either size, and will pick 16 bit indices if possible. If '16bit' is specified and the mesh exceeds 65536 vertices, an exception is thrown.
* @returns Typed arrays of the mesh vertices and indices.
*/
export function createTileMesh<T extends IndicesType>(options: CreateTileMeshOptions, forceIndicesSize?: T): T extends '32bit' ? TileMesh<Uint32Array> : (T extends '16bit' ? TileMesh<Uint16Array> : TileMesh<Uint16Array | Uint32Array>) {
export function createTileMesh(options: CreateTileMeshOptions, forceIndicesSize?: IndicesType): TileMesh {
// We only want to generate the north/south border if the tile
// does NOT border the north/south edge of the mercator range.
const granularity = options.granularity !== undefined ? Math.max(options.granularity, 1) : 1;
Expand All @@ -139,27 +139,7 @@ export function createTileMesh<T extends IndicesType>(options: CreateTileMeshOpt

const use32bitIndices = overflows16bitIndices || forceIndicesSize === '32bit';

const vertexArray = new Int16Array(vertexCount * 2);

let resultMesh;

if (use32bitIndices) {
const mesh: TileMesh<Uint32Array> = {
vertices: vertexArray,
indices: new Uint32Array(indexCount),
uses32bitIndices: true,
};
resultMesh = mesh;
} else {
const mesh: TileMesh<Uint16Array> = {
vertices: vertexArray,
indices: new Uint16Array(indexCount),
uses32bitIndices: false,
};
resultMesh = mesh;
}

const indexArray = resultMesh.indices;
const vertices = new Int16Array(vertexCount * 2);

let vertexId = 0;

Expand All @@ -180,11 +160,13 @@ export function createTileMesh<T extends IndicesType>(options: CreateTileMeshOpt
vy = options.extendToSouthPole ? SOUTH_POLE_Y : EXTENT + EXTENT_STENCIL_BORDER;
}

vertexArray[vertexId++] = vx;
vertexArray[vertexId++] = vy;
vertices[vertexId++] = vx;
vertices[vertexId++] = vy;
}
}

const indices = use32bitIndices ? new Uint32Array(indexCount) : new Uint16Array(indexCount);

let indexId = 0;

for (let y = 0; y < quadsPerAxisY; y++) {
Expand All @@ -198,15 +180,19 @@ export function createTileMesh<T extends IndicesType>(options: CreateTileMeshOpt
// | / |
// | / |
// v2----v3
indexArray[indexId++] = v0;
indexArray[indexId++] = v2;
indexArray[indexId++] = v1;
indices[indexId++] = v0;
indices[indexId++] = v2;
indices[indexId++] = v1;

indexArray[indexId++] = v1;
indexArray[indexId++] = v2;
indexArray[indexId++] = v3;
indices[indexId++] = v1;
indices[indexId++] = v2;
indices[indexId++] = v3;
}
}

return resultMesh;
}
return {
vertices: vertices.buffer.slice(0),
indices: indices.buffer.slice(0),
uses32bitIndices: use32bitIndices,
};
}

0 comments on commit cf58061

Please sign in to comment.